Python Operators Explained: Types, Examples & Uses (Beginner Guide)

Python Operators
🐍 For Beginners

Python
Operators
Explained

All 7 types · Simple words · Real examples

Arithmetic Comparison Logical Assignment Bitwise Membership Identity
πŸ”§
01 · Definition
What is an Operator?

An operator is a symbol that tells Python to do something with values. For example, + tells Python to add two numbers. The values it works on are called operands.

πŸ’‘ Think of a calculator button. Pressing + tells the calculator to add. In Python, + does the same thing.
Example
a = 10        # a is an operand

b = 3         # b is an operand

print(a + b)  # + is the operator → 13
Operand = the value (like 10 or 3). Operator = the action symbol (like +).
πŸ“‹
02 · Overview
7 Types of Operators

Python has 7 types of operators. Each type has a different job. We will learn all of them one by one.

Arithmetic
Math operations
⚖️
Comparison
Compare values
πŸ”—
Logical
and / or / not
πŸ“¦
Assignment
Store values
πŸ”’
Bitwise
Binary (0s & 1s)
πŸ”
Membership
in / not in
πŸͺͺ
Identity
is / is not — same object in memory?
03 · Arithmetic
Arithmetic Operators

These are used for basic math — add, subtract, multiply, and divide. Python also has three special ones: Floor division // gives only the whole number. Modulus % gives the leftover (remainder). Exponent ** raises a number to a power.

πŸ›’ 3 pens × ₹10 → 3 * 10 = 30. Share 10 chocolates among 3 friends → each gets 10 // 3 = 3, and 10 % 3 = 1 is left over.
SymbolNameExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiply10 * 330
/Division10 / 33.33…
//Floor Div10 // 33
%Modulus10 % 31
**Exponent2 ** 38
Try it yourself
a = 10

b = 3

print(a + b)   # 13

print(a - b)   # 7

print(a * b)   # 30

print(a / b)   # 3.3333...

print(a // b)  # 3  (no decimal)

print(a % b)   # 1  (remainder)

print(2 ** 3)  # 8  (2×2×2)
⚠️ Watch out! Dividing by 0 gives a ZeroDivisionError. Always make sure the bottom number is not zero.
⚖️
04 · Comparison
Comparison Operators

These compare two values and always return either True or False. They are mostly used inside if statements to make decisions in your program — like "Is the user old enough?" or "Did the score pass?"

πŸ§‘‍⚖️ Like a judge — you ask "Is 10 bigger than 5?" Judge says True. You ask "Is 3 equal to 7?" Judge says False.
SymbolMeaningExampleResult
==Equal to5 == 5True
!=Not equal5 != 3True
>Greater than7 > 3True
<Less than2 < 9True
>=Greater or equal5 >= 5True
<=Less or equal4 <= 6True
Try it yourself
age = 18

print(age == 18)  # True  — age is 18

print(age != 20)  # True  — 18 is not 20

print(age >  15)  # True  — 18 > 15

print(age <  10)  # False — 18 is not < 10

print(age >= 18)  # True  — 18 >= 18
⚠️ Common mistake! = stores a value. == compares values. Inside if, always use ==, never =.
πŸ”—
05 · Logical
Logical Operators

Logical operators combine two conditions. Use and when both conditions must be true. Use or when at least one must be true. Use not to reverse a condition — turns True into False.

🚦 You can enter a club if you are 18+ AND have an ID. Both must be true. That is and at work!
OperatorTrue whenExampleResult
andBoth are TrueTrue and TrueTrue
andOne is FalseTrue and FalseFalse
orAt least one TrueFalse or TrueTrue
orBoth are FalseFalse or FalseFalse
notFlips the valuenot TrueFalse
Try it yourself
age    = 20

has_id = True

print(age >= 18 and has_id)  # True

print(age <  18 or  has_id)  # True

print(not has_id)              # False
Short-circuit: With and, if the first condition is False, Python skips the second — it already knows the result is False.
πŸ“¦
06 · Assignment
Assignment Operators

Use = to store a value in a variable. Shortcut operators like += do math and store in one step. For example, x += 5 means "add 5 to x, then save it back to x". These are used a lot inside loops.

πŸͺ£ x = 10 fills a bucket with 10. x += 5 adds 5 more to the bucket. The bucket now holds 15.
OperatorSame asx=10 → Result
=Store valuex = 10
+=x = x + 5x = 15
-=x = x - 3x = 7
*=x = x * 2x = 20
/=x = x / 4x = 2.5
//=x = x // 3x = 3
%=x = x % 3x = 1
**=x = x ** 2x = 100
Try it yourself
x = 10

print(x)   # 10

x += 5     # same as x = x + 5

print(x)   # 15

x *= 2     # same as x = x * 2

print(x)   # 30
⚠️ Always define x first before using x += 1. If x does not exist yet, Python will give an error.
πŸ”’
07 · Bitwise
Bitwise Operators

Computers store numbers as binary — a series of 0s and 1s called bits. Bitwise operators work directly on those bits. For example, 5 in binary is 0101 and 3 is 0011. These are used in advanced topics like games, security, and hardware.

πŸ’‘ Quick trick: x << 1 doubles the number. x >> 1 halves it. So 5 << 1 = 10 and 5 >> 1 = 2.
SymbolNameExampleResult
&AND5 & 31
|OR5 | 37
^XOR5 ^ 36
~NOT~5-6
<<Left Shift5 << 110
>>Right Shift5 >> 12
Try it yourself
a = 5   # binary: 0101

b = 3   # binary: 0011

print(a & b)   # 1  (AND)

print(a | b)   # 7  (OR)

print(a << 1)  # 10 (doubled)

print(a >> 1)  # 2  (halved)
If bitwise feels hard right now — that is totally normal! Come back to it after you learn binary numbers. For now just know it exists.
πŸ”
08 · Membership
Membership Operators

These check if a value exists inside a collection — like a list, string, or set. in returns True if the value is found. not in returns True if the value is NOT found. Very readable — almost like plain English!

πŸ›’ You have a shopping list. "Is milk on the list?" → 'milk' in shopping_list. Yes → True. No → False.
OperatorChecksExampleResult
inValue IS inside'a' in 'cat'True
not inValue NOT inside5 not in [1,2]True
Try it yourself
fruits = ['apple', 'mango']

print('apple' in     fruits) # True

print('grape' in     fruits) # False

print('grape' not in fruits) # True

# Works on strings too!

print('Py' in 'Python')      # True
On dictionaries, in checks keys only. Example: 'name' in {'name': 'Ali'}True.
πŸͺͺ
09 · Identity
Identity Operators

These check if two variables are pointing to the exact same object in memory. This is different from ==, which only checks if the values are the same. is → same object. is not → different objects.

πŸ‘― Two twins look the same (== is True) but they are two different people (is is False). Identity checks if it is literally the same person.
OperatorChecksExampleResult
isSame object in memorya is bTrue/False
is notDifferent objectsa is not cTrue/False
Try it yourself
a = [1, 2, 3]

b = a            # b points to same list

c = [1, 2, 3]   # c is a brand new list

print(a is b)      # True  — same object

print(a is c)      # False — different objects

print(a == c)      # True  — same values

x = None

print(x is None)   # True ✓ correct way
⚠️ Always write x is None — never x == None. This is the correct Python style (PEP 8 rule).
🐍 Python Operators · Beginner's Guide · Python 3.x

Comments