Blog 2: Diving Deep into Python Fundamentals

Alisha MalhotraAlisha Malhotra
6 min read

Introduction

Welcome back to the “10 Blogs. One Language” series!
In this second post, we’ll dive into the core fundamentals of Python — the building blocks every coder must master. Whether you’re new to programming or brushing up on your basics, this blog will guide you through:

  • Character Sets

  • Tokens

  • Literals

  • Data Types

  • Operators (in detail!)

  • Statements & Expressions

  • Input & Output

Let’s begin your journey into the real structure of Python programs.


1. Character Sets: ASCII, Unicode, and UTF-8

Python understands and uses a variety of characters:

  • Letters: A-Z, a-z

  • Digits: 0–9

  • Special symbols: +, -, *, /, (), {}, [], =, !=, etc.

  • Whitespace: spaces, tabs, newlines

ASCII covers basic English (0–127).
Unicode includes characters from all languages and even emojis.
UTF-8 is the encoding format used to store Unicode data — it’s flexible and widely supported.

Note: If your Python program displays weird characters or throws text-related errors, it’s likely an encoding issue — just make sure your files use UTF-8.


2. Tokens in Python

Tokens are the smallest elements of a Python program. They include:

  • Keywords: Predefined, reserved words (e.g., if, else, def, class, return)

  • Identifiers: Names for variables, functions, classes (e.g., my_var, Person)

  • Literals: Constants like numbers, strings, True, None, etc.

  • Operators: Symbols like +, *, ==, etc.

  • Punctuators: Brackets, colons, commas — e.g., (), {}, :, ,


3. Literals in Python

Literals are fixed values assigned to variables. Python supports:

🔹 Numeric Literals

x = 10        # Integer
y = 3.14      # Float
z = 2 + 3j    # Complex

🔹 String Literals

s = "Hello"  # Single-line
msg = '''Hello
World'''     # Multi-line

🔹 Boolean & Special Literals

flag = True
empty = None

🔹 Collection Literals

list_ex = [1, 2, 3]
tuple_ex = (1, 2, 3)
dict_ex = {'a': 1, 'b': 2}
set_ex = {1, 2, 3}

4. Data Types in Python

Python has dynamic typing, meaning you don’t declare variable types — Python detects them.

CategoryExamples
Textstr
Numericint, float, complex
Sequencelist, tuple, range
Mappingdict
Setset, frozenset
Booleanbool
Binarybytes, bytearray, memoryview
None TypeNoneType

You can also define your own types:

class Person:
    pass

5. Operators in Python

Python offers various types of operators for arithmetic, logic, comparison, and more.


🔹 Arithmetic Operators

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction5 - 23
*Multiplication4 * 312
/Division (float)10 / 42.5
//Floor Division10 // 42
%Modulus (remainder)10 % 31
**Exponentiation2 ** 38

🔹 Assignment Operators

OperatorUsageEquivalent To
=a = 5Assign 5 to a
+=a += 3a = a + 3
-=a -= 2a = a - 2
*=a *= 4a = a * 4
/=a /= 2a = a / 2
//=a //= 2Floor divide
%=a %= 2Modulus assignment
**=a **= 3Raise to power

🔹 Comparison Operators

OperatorDescriptionExampleResult
==Equal to3 == 3True
!=Not equal to3 != 4True
>Greater than5 > 2True
<Less than2 < 5True
>=Greater or equal4 >= 4True
<=Less or equal3 <= 2False

🔹 Logical Operators

OperatorDescriptionExampleResult
andBoth conditionsTrue and FalseFalse
orAt least oneTrue or FalseTrue
notNegates booleannot TrueFalse

🔹 Bitwise Operators

OperatorDescriptionExampleResult
&AND5 & 3 (0101 & 0011) → 0001 = 1
``OR`5
^XOR5 ^ 3 → 6
~NOT~5 → -6
<<Left Shift2 << 2 → 8
>>Right Shift8 >> 2 → 2

🔹 Membership Operators

OperatorDescriptionExample
inChecks presence'a' in 'apple' → True
not inChecks absence'z' not in 'apple' → True

🔹 Identity Operators

OperatorDescriptionExample
isTrue if same object in memorya is b
is notTrue if not same objecta is not b

🧠 Example with Precedence:

result = 3 + 4 * 2 ** 2 // 2
# Evaluates as: 3 + ((4 * (2 ** 2)) // 2)
# = 3 + ((4 * 4) // 2) = 3 + (16 // 2) = 3 + 8 = 11
print(result)  # Output: 11

6. 🧾 Statements in Python

🔹 Simple Statement

A single line instruction:

x = 10
print(x)

🔹 Compound Statement

Includes a header and an indented block:

if x > 0:
    print("Positive")
else:
    print("Not positive")

7. 🔣 Expressions in Python

An expression is a combination of values, variables, and operators that evaluates to a result.

a = 5
b = 10
c = a + b * 2  # Expression evaluates to 25

8. ⌨️ Input and Output in Python

🔹 Taking Input

name = input("Enter your name: ")

🔹 Displaying Output

print("Hello,", name)

My Experience

When I first began learning Python, character encodings confused me the most.
Remember this:

  • ASCII = Basic English characters (0–127)

  • Unicode = All characters in all languages

  • UTF-8 = A smart way of storing Unicode efficiently

So if you ever get garbled output or weird errors — check if your file encoding is UTF-8.


What’s Next?

In the next blog, we’ll explore control structures — how to make decisions and perform loops.

Here’s a small teaser:

for i in range(5):
    if i % 2 == 0:
        print(i, "is even")
    else:
        print(i, "is odd")

Stay tuned, and let’s keep compiling your Python skills!

0
Subscribe to my newsletter

Read articles from Alisha Malhotra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Alisha Malhotra
Alisha Malhotra