Blog 2: Diving Deep into Python Fundamentals


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.
Category | Examples |
Text | str |
Numeric | int , float , complex |
Sequence | list , tuple , range |
Mapping | dict |
Set | set , frozenset |
Boolean | bool |
Binary | bytes , bytearray , memoryview |
None Type | NoneType |
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
Operator | Description | Example | Result |
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 2 | 3 |
* | Multiplication | 4 * 3 | 12 |
/ | Division (float) | 10 / 4 | 2.5 |
// | Floor Division | 10 // 4 | 2 |
% | Modulus (remainder) | 10 % 3 | 1 |
** | Exponentiation | 2 ** 3 | 8 |
🔹 Assignment Operators
Operator | Usage | Equivalent To |
= | a = 5 | Assign 5 to a |
+= | a += 3 | a = a + 3 |
-= | a -= 2 | a = a - 2 |
*= | a *= 4 | a = a * 4 |
/= | a /= 2 | a = a / 2 |
//= | a //= 2 | Floor divide |
%= | a %= 2 | Modulus assignment |
**= | a **= 3 | Raise to power |
🔹 Comparison Operators
Operator | Description | Example | Result |
== | Equal to | 3 == 3 | True |
!= | Not equal to | 3 != 4 | True |
> | Greater than | 5 > 2 | True |
< | Less than | 2 < 5 | True |
>= | Greater or equal | 4 >= 4 | True |
<= | Less or equal | 3 <= 2 | False |
🔹 Logical Operators
Operator | Description | Example | Result |
and | Both conditions | True and False | False |
or | At least one | True or False | True |
not | Negates boolean | not True | False |
🔹 Bitwise Operators
Operator | Description | Example | Result |
& | AND | 5 & 3 (0101 & 0011) → 0001 = 1 | |
` | ` | OR | `5 |
^ | XOR | 5 ^ 3 → 6 | |
~ | NOT | ~5 → -6 | |
<< | Left Shift | 2 << 2 → 8 | |
>> | Right Shift | 8 >> 2 → 2 |
🔹 Membership Operators
Operator | Description | Example |
in | Checks presence | 'a' in 'apple' → True |
not in | Checks absence | 'z' not in 'apple' → True |
🔹 Identity Operators
Operator | Description | Example |
is | True if same object in memory | a is b |
is not | True if not same object | a 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!
Subscribe to my newsletter
Read articles from Alisha Malhotra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
