Python Diaries đ: The Hidden Powers Begin
Episode 1 â Operators Unleashedđ

Hey youđ Yes, youđ«”
Ever felt like Python tutorials are either too boring or too basic?
You follow along, write a few lines of code, but deep down youâre still wonderingâŠ
âWait. Why does this actually work?â
âWhatâs going on behind the scenes đ§?â
Well, welcome to the series that answers all of that and more.
Weâre not here to just write PythonâŠ
Weâre here to actually understand it. Deeply, Clearly and One âaha!â moment at a time.
This isnât your usual tutorial playlist.
This is a story-driven, real-talk Python web series packed with concepts, mind-bending insights, fun vibes and the kind of smooth explanations that make your brain go:
âWait⊠ohhh, now I get it!đ„łâ
We're not rushing. We're not skipping.
Weâre decoding Python from the inside out like peeling back the curtain and finally seeing whatâs going on backstage.
So whether youâre just starting out or youâve written Python for a while and still feel like somethingâs missing you're in the right place.
Weâve got:
đ Deep dives
đŻ Real-world clarity
đ§ Tricky edge cases
And weâre starting this journey with Episode 1: Operators Unleashed
Because trust me once you get how operators work under the hood, the rest of Python starts making a whole lot more sense.
Episode 1 â Operators Unleashedđ
Hey Python Famđ,
Welcome to the very first episode of this Python-packed series â
Where each part feels less like a tutorial⊠and more like your favorite Netflix binge đđż
If you're here, I already know one thing about you. You're someone whoâs not just writing Python codeâŠ
You actually wanna understand whatâs happening behind the scenes, right?
Alright, get ready because... Today weâre cracking open a topic that most Python learners either skip⊠or totally misunderstand. but itâs actually the core of how Python thinks, behaves, and makes decisions.
And trust me once you get this, your whole Python perspective is gonna level up.
Weâre talking about the hidden superpowers of:
â Arithmetic
đ€ Comparison
đ§ Logical
đ Assignment
âïž Bitwise
đ Membership
đȘ Identity
All those tiny symbols like ==, is, &, or not in that seem innocent⊠but can change everything when used right!
print(2 + 3) # 5
print("2" + "3") # "23"
print([2] + [3]) # [2, 3]
Same operator, different results. Why?
Is â+â secretly changing its job depending on the data?
This is called operator overloading. where the same symbol pulls off completely different stunts depending on who itâs hanging out with.
One minute it's doing math, next minute it's gluing strings together, and the next it's stitching lists like a Python tailor. Pretty unexpected, right?
But donât worry! weâll break them down with real examples, tricky edge cases, and even memory-level clarity â
so by the end of this episode, you wonât just use operatorsâŠâŠ
Youâll understand their vibe.
So, grab your chai, coffee, or energy drink and letâs dive into the world of operators.
Letâs Talk About Operators:

But no my dear friend! you were about to realize they were much more than that.
Operators are like action heroes in your code. They're like action verbs for your variables. They tell python what to do with your variables.
Operators perform actions on your data. From adding numbers to comparing values, from checking conditions to manipulating strings.
There are many types of operators, but donât stress. Letâs take them one by one with real-life example.
1. Arithmetic Operators:
These are your basic math buddies. Weâve all used these before, right? From the time you were figuring out how much pizza to order for a party to calculating your grades.
In python we have basic arithmetic operators like:
| Operator(Symbol) | Meaning | Example | Output |
| + | Addition | 5 + 5 | 10 |
| - | Subtraction | 5 - 2 | 3 |
| * | Multiplication | 5 * 3 | 15 |
| / | Division | 10 / 2 | 5.0 |
| // | Floor Division | 10 // 3 | 3 |
| % | Modulus | 10 % 3 | 1 |
| ** | Power | 2 ** 3 | 8 |
Example:
a = 10
b = 3
print(a + b) # 13
print(a // b) # 3
print(a % b) # 1
Itâs like ordering food. If you order 10 pizzas and share with 3 friends, the // operator tells how many full pizzas each gets. The % operator says how many are left over.
2. Comparison Operators:
They check what's True and what's False. These are the judges of your code. They compare two values and return True or False. Perfect for when you want to know if one value is bigger than another or if two values are equal.
Example:
x = 20
y = 15
print("Is x equal to y?", x == y) # False
print("Is x not equal to y?", x != y) # True
print("Is x greater than y?", x > y) # True
print("Is x less than y?", x < y) # False
These are the decision-makers. Theyâll help you figure out if things are equal, bigger, or smaller. Think of them like comparing the prices of two phones. Which oneâs the better deal?
3. Logical Operators:
When you have multiple conditions and you want to check if both are true or either is true, you use logical operators.
| Operator | Meaning | Example | Output |
| and | Both true | (5 > 2 and 3 < 4) | True |
| or | Any one true | (5 < 2 or 3 < 4) | True |
| not | Opposite | not(5 > 2) | False |
Example:
x = 5
y = 10
print(x < 10 and y > 5) # True, because both conditions are true
print(x < 5 or y > 5) # True, because at least one condition is true
print(not (x < 10)) # False, because x < 10 is true, and not reverses it
this think like that,
"If I have money and the cafe is open then Iâm going out for coffee."
âIf you have enough time or the task is easy, youâll finish it today.â
4. Assignment Operators:
These are like putting values into variables with a twist.
| Operator | Meaning | Example | Output |
| \= | Assign value | x = 5 | 5 |
| += | Add and assign | x = 5, x += 3 | 8 |
| -= | Subtract and assign | x = 10, x -= 4 | 6 |
| *= | Multiply and assign | x = 6, x *= 2 | 12 |
| /= | Divide and assign | x = 9, x /= 3 | 3.0 |
| //= | Floor divide and assign | x = 9, x //= 2 | 4 |
| %= | Modulus and assign | x = 10, x %= 3 | 1 |
| **= | Power and assign | x = 2, x **= 3 | 8 |
Example:
x = 5
x -= 3 # same as x = x - 3
print(x) # 2
Assignment operators help make your code shorter and cleaner. Instead of writing x = x + 1, you can simply write x += 1. Small things, big difference!
5. Bitwise Operators:
These are a bit more advanced and work on the binary level (0s and 1s).They compare or modify numbers bit by bit, which means they perform operations on the individual 0s and 1s that make up the number in binary form.
Super useful for performance-based stuff.


Bitwise operators might seem tricky at first, but donât worry flocks. weâll go through each one step by step with simple examples and see how they work behind the scenes in binary.
Bitwise AND (&):
Returns
1only if both bits are1, otherwise returns0.Example:
a = 5 # binary: 0101 b = 3 # binary: 0011 result = a & b print(result) # Output: 1Binary Breakdown:
0101 (5) & 0011 (3) = 0001 â 1Only the last bit is
1in both numbers, so the result is1.Bitwise OR (|):
Returns
1if at least one bit is1, otherwise returns0.Example:
a = 5 # binary: 0101 b = 3 # binary: 0011 result = a | b print(result) # Output: 7Binary Breakdown:
0101 (5) | 0011 (3) = 0111 â 7Any bit that is
1in either number becomes1in the result.
Bitwise XOR (^):
Returns
1if the bits are different, otherwise returns0Example:
a = 5 # binary: 0101 b = 3 # binary: 0011 result = a ^ b print(result) # Output: 6Binary Breakdown:
0101 (5) ^ 0011 (3) = 0110 â 6
Only the bits that are different become 1.
Bitwise NOT (~):
Bitwise NOT flips every bit in the binary representation of a number. But because Python uses signed integers with two's complement, flipping bits also changes the sign of the number.
How ~a Works Internally
Letâs take a = 5 and evaluate ~5.
a = 5
print(~a) # Output: -6
Looks confusing at first, right?
Letâs first explore with formula,
~a = - (a + 1)
~5 = - (5 + 1) = -6
Simple, right? But letâs go deeper to understand why it works this way in binary.
Step 1: Convert 5 to Binary (8 bits):
We assume 8-bit representation for easy understanding:
5 â 00000101
Step 2: Apply Bitwise NOT (~) â Flip All Bits
We flip every 0 to 1 and every 1 to 0:
~00000101 â 11111010
So, after flipping, we get:
11111010
In Python, integers are stored using twoâs complement when dealing with negatives. That means:
If the leftmost bit is 1, the number is negative, and we need to decode it using twoâs complement method.
So let's do that now.
Step 3: Decode 11111010 using Twoâs Complement
1. Flip all bits (1âs complement):
11111010 â 00000101
2. Add 1:
00000101 + 1 = 00000110
3. Add minus sign:
Result = -6
So, the result of ~5 is -6.
Bitwise NOT (~) on Negative Numbers:
Letâs say:
a = -5
print(~a) # Output: 4
~(-5) gives 4? Letâs see how!Letâs first explore with formula,
~a = - (a + 1)
~(-5) = - (-5 + 1) = -(-4) = 4
Simple, right? But letâs go deeper to understand why it works this way in binary.
Step 1 : Represent -5 in Binary (8 bits)
To understand bitwise operations on negative numbers, we use twoâs complement.
First, write positive 5 in binary:
5 â 00000101
Now:
To get -5, we use twoâs complement:
- Flip all bits (1âs complement):
00000101 â 11111010
- Add 1:
11111010 + 1 = 11111011
So, -5 in binary (8-bit) = 11111011
Step 2 : Apply Bitwise NOT (~)
Now flip all bits of 11111011:
~11111011 â 00000100
That equals 4 in decimal.
~(-5) = 4
Bitwise Left Shift (
<<):
Letâs take a simple example first:
a = 5
print(a << 1) # Output: 10
Letâs explore step-by-step.
The left shift operator
a << bshifts the binary bits ofato the left bybpositions, and empty spots get filled with zeros on the right
Example: 5 << 1
Step 1: Convert 5 to Binary (8-bit)
5 â 00000101
Step 2: Left Shift by 1
We shift every bit 1 place to the left, and add a 0 at the end
00000101 << 1 â 00001010
So 00001010 is the result after shifting.
Step 3: Convert Back to Decimal
00001010 â 10
Final Answer:
5 << 1 = 10
hereâs each left shift multiplies the number by 2
| Expression | Result | Meaning |
| 5 << 1 | 10 | 5 * 2 |
| 5 << 2 | 20 | 5 * 2 * 2 |
| 5 << 3 | 40 | 5 * 2 * 2 * 2 |
So in general:
a << bis equal toa * (2^b)
Bitwise Right Shift (>>):

Letâs take a basic example:
a = 10
print(a >> 1) # Output: 5
Letâs walk through it.
The right shift operator
a >> bshifts the bits ofato the right bybpositions, and discards the rightmost bits, filling in with zeros from the left.
Example: 10 >> 1
Step 1: Convert 10 to Binary (8-bit)
10 â 00001010
Step 2: Right Shift by 1
Shift all bits 1 position to the right, and add 0 from the left:
00001010 >> 1 â 00000101
We just lost the last bit (the rightmost 0), and a 0 came in from the left.
Step 3: Convert Back to Decimal
00000101 â 5
Final Answer:
10 >> 1 = 5
Each right shift divides the number by 2 (ignoring the remainder):
| Expression | Result | Meaning |
| 10 >> 1 | 5 | 10 // 2 |
| 10 >> 2 | 5 | 20 // 4 |
| 10 >> 3 | 5 | 30 // 8 |
So in general:
a >> bis equal toa // (2^b)
Membership Operators:
Python provides two membership operators:
| Operator | Description | | --- | --- | | in | Returns
Trueif a value exists in the given object | | not in | ReturnsTrueif a value does not exist |These are used to check presence, especially in collections like
list,tuple,set,dict,string, etc.Letâs Begin with a Simple Example
fruits = ['apple', 'banana', 'mango']
print('apple' in fruits) # True
print('grape' not in fruits) # True
Letâs explore how it works internally, and how behavior differs based on data types.
These are iterable containers. Python checks each element one by one*.*
colors = ['red', 'green', 'blue']
print('green' in colors) # True
Internally, Python runs a loop and checks each element with
==to match the value.
Set is Faster
s = {'a', 'b', 'c'}
print('b' in s) # True
Why faster?
Because
setuses hashing. constant time lookup instead of looping. Prefersetwhen you need fast membership checks in large data!
Membership in Dictionaries
Now this part often confuses beginners.
person = {'Name': 'Neha', 'Gender': 'Female'}
print('Name' in person) # True
print('Neha' in person) # False
Why is 'Neha' not in the dictionary?
Because
inonly checks keys, not values.
If you want to check in values:
print('Neha' in person.values()) # True
Similarly, for keys:
print('Name' in person.keys()) # True
Tricky Cases: Nested Structures
Sometimes things get tricky with nested lists or dicts.
nested = [1, [2, 3], 4]
print(2 in nested) # False
print([2, 3] in nested) # True
Why?
Because
2is inside a nested list, not directly in the outer list.
Final Recap: Membership Operator Behaviors
| Data Type | in checks | Fast? |
list, tuple | Linear search (==) | Slow for big data |
set, dict | Hash-based lookup | Fast |
dict | Checks keys by default | Fast |
string | Checks substring | Moderate |
Identity Operators
Python provides two identity operators:
| Operator | Description |
| is | Returns True if two variables point to the same object in memory |
| is not | Returns True if two variables point to different objects in memory |
These are not the same as == and !=, which check for value equality.
Letâs Begin Simple
a = 5
b = 5
print(a is b) # True, both point to the same object (small int interning)
You might think:
is?âBecause is checks if both variables are literally pointing to the same memory address, not just if their values are the same.
is Sometimes Returns True, Sometimes False?Here comes the twist.
It depends on mutability and Pythonâs internal optimizations.
Immutable Data Types
Immutable means canât be changed after creation. These include:
intfloatstrbooltuple(but with a condition â weâll explain)
Example: Integers
a = 100
b = 100
print(a is b) # True
But watch this:
a = 257
b = 257
print(a is b) # False
Why this difference?
Because Python caches integers from -5 to 256. Any number in this range points to the same object in memory for efficiency.
Strings
a = "hello"
b = "hello"
print(a is b) # True (due to interning)
But:
a = "hello world!"
b = "hello world!"
print(a is b) # Might be False in some environments
Python automatically interns some strings (especially short ones or ones that look like identifiers). But itâs not guaranteed for all strings.
Mutable Data Types
Mutable means can be changed in-place. These include:
listdictset
Even if two variables hold the same data, they are different objects.
a = [1, 2, 3]
b = [1, 2, 3]
print(a is b) # False
print(a == b) # True
Why?
Because Python creates a new object each time you create a list, dictionary, or set â even if values are the same.
Letâs explore more...
Tuples â The Sneaky Immutable
Tuples are immutable, yes. But reuse depends on what they contain.
Case 1: Tuples with only immutables
a = (1, 2, 3)
b = (1, 2, 3)
print(a is b)# Could be True or False depending on the Python implementation
In this Python may reuse memory depending on the Python implementation in some small tuple cases that might be true
Case 2: Tuples with mutables inside
a = ([1, 2], 3)
b = ([1, 2], 3)
print(a is b) # Always False
Python does not reuse this tuple because it contains mutable objects inside.
Identity with Functions and Objects
def func(): pass
print(func is func) # True
x = func
print(x is func) # True
Even classes or functions are objects in Python â and is checks if they are the same reference.
Practical Use Case of is
x = None
if x is None:
print("x is not set yet")
Pythonic way to check for None.
Avoid doing x == None.
Recap : Which Types Are Reused / New?
| Data Type | Immutable? | Reused with is? |
int (-5 to 256) | Yes | Yes |
int (others) | Yes | No (new object) |
str (short/simple) | Yes | Yes (often) |
str (complex) | Yes | No (usually) |
list | No | No |
tuple (all immutables) | Yes | Maybe |
tuple (with mutables) | Yes | No |
dict, set | No | No |
None, True, False | Yes | Always same object |
Alright fam, if youâve made it this far give yourself a virtual high-five đ.
That was quite a ride through the land of Python Operators. From the straightforward to the totally âwait, what?â moments, we cracked open every corner of what Python operators really do. not just how to use them, but why they work the way they do.
And if youâve made it this far. you're not just coding Python anymore... you're starting to think in Pythonđ§ .
Pretty cool, right?
But hey â donât close the tab just yet!
Weâve only scratched the surface of what Python hides in plain sight. weâre diving into a topic that looks simple on the outside⊠but hides tons of power and gotchas inside: Strings.
Yeah, that thing you thought was just text inside quotes?
Turns out, itâs got its own rules⊠quirks⊠and even memory tricks that can surprise you!
So grab a cup of chai or coffee â, stretch a bit, and when youâre ready
CHECK OUT NEXT BLOG: Episode 2: Strings in Python â Not Just Text, But Pure Magic is waiting for you.
Trust me, you donât wanna miss it.
Letâs keep leveling up one line of code at a time.
See you there, Python fam! đđ



