Operators are symbols that tell Python what action to perform. Think of them as the tools you use to calculate, compare, and combine values.
Arithmetic Operators
Arithmetic operators let you do maths in Python. They work with numbers, both integers and floats.
+adds numbers (3 + 2 = 5)-subtracts (5 - 2 = 3)*multiplies (4 * 3 = 12)/divides and gives a float (7 / 2 = 3.5)//divides but rounds down (7 // 2 = 3)%gives the remainder (7 % 2 = 1)**raises to a power (2 ** 3 = 8)
print(10 + 5)
print(10 / 3)
print(2 ** 4)
Try this
- Work out
15 % 4. - Predict then run
3 + 2 * 4.
Comparison Operators
Comparison operators check whether values are equal, greater, or smaller. They always return a Boolean: True or False.
==equal to!=not equal to<less than<=less than or equal to>greater than>=greater than or equal to
print(5 == 5) # True
print(7 < 3) # False
print(10 != 8) # True
These are often used in if statements to control decisions.
Try this
- Print whether
12is greater than7. - Print whether
"apple" == "Apple".
Logical Operators
Logical operators combine Booleans. They help you create conditions that are more complex.
andisTrueif both conditions are true.orisTrueif at least one condition is true.notflips a Boolean value.
x = 10
print(x > 5 and x < 20) # True
print(x < 5 or x == 10) # True
print(not (x == 10)) # False
Try this
- Check if
age = 16is greater than 13 and less than 19. - Use
orto check iffruitis"apple"or"orange".
Assignment Operators
Assignment operators are used to set or update the value of a variable. The basic one is =. Others combine arithmetic with assignment.
=assigns (x = 5)+=adds and assigns (x += 3is the same asx = x + 3)-=subtracts and assigns*=multiplies and assigns/=divides and assigns
x = 10
x += 5 # now 15
x *= 2 # now 30
print(x)
This helps keep your code shorter and clearer.
Try this
- Start with
score = 0. Add 10, then subtract 2, then double it.
Membership Operators
Membership operators check whether a value is inside a sequence such as a string or a list.
inchecks if a value exists.not inchecks if it does not.
fruits = ["apple", "banana", "cherry"]
print("apple" in fruits) # True
print("grape" not in fruits) # True
word = "Python"
print("P" in word) # True
print("z" in word) # False
Try this
- Make a list of three favourite foods. Check if
"pizza"is in the list. - Check if
"x"is in"example".
Identity Operators
Identity operators check whether two variables refer to the same object in memory.
isreturnsTrueif two variables point to the same object.is notreturnsTrueif they don’t.
x = [1, 2, 3]
y = x
z = [1, 2, 3]
print(x is y) # True (same object)
print(x is z) # False (different objects with same content)
print(x == z) # True (contents are equal)
Beginners often confuse is with ==. == checks value equality, while is checks object identity.
Try this
- Create two variables with the same number. Compare them with both
==andis. - Try the same with two lists.
✅ With these operators, you now have the core tools to calculate, compare, and control your Python programs.










