Python operators are symbols that let you perform actions on values and variables. In this topic, you will practice using four major groups of operators: arithmetic, comparison, logical, and assignment. Mastering these will help you write clear conditions, perform calculations, and update values efficiently.
True or False).and, or, and not.Used for mathematical operations on numbers:
+ – addition- – subtraction* – multiplication/ – division (always returns a float)% – modulus (remainder of a division)** – exponentiation// – floor division (quotient without decimal part)Used to compare two values; the result is either True or False:
== – equal to!= – not equal to< – less than> – greater than<= – less than or equal to>= – greater than or equal toUsed to combine Boolean expressions:
and – True only if both conditions are True.or – True if at least one condition is True.not – inverts the Boolean value.Used to assign and update values stored in variables:
= – simple assignment+=, -=, *=, /= – update and assign in a single step%=, //=, **= – apply modulus, floor division, exponentiation and reassignBasic mathematical operations on integers:
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.3333...
print(a % b) # 1
print(a ** b) # 1000
print(a // b) # 3
Comparing two numbers using different comparison operators:
x = 5
y = 10
print(x == y) # False
print(x != y) # True
print(x < y) # True
print(x > y) # False
print(x <= y) # True
print(x >= y) # False
Combining Boolean values with logical operators:
a = True
b = False
print(a and b) # False
print(a or b) # True
print(not a) # False
Updating the same variable using different assignment operators:
num = 5
num += 3 # num = 8
num -= 2 # num = 6
num *= 2 # num = 12
num /= 4 # num = 3.0
num %= 2 # num = 1.0
num **= 3 # num = 1.0
num //= 1 # num = 1.0
a + b, a - b, a * b and a / b behave like normal math, but division gives a float. a // b drops the decimal part.True or False. For example, 5 < 10 is True and 5 > 10 is False.a and b is only True when both are True, a or b is True if at least one is True, and not a flips the value of a.num is changed step-by-step. Each operator both performs the operation and updates num in place.if-statements and loops using comparison operators.if-conditions instead of manually checking values using multiple statements.if-statements.+= for counters (e.g., i += 1 in loops).score = 0) and update it in multiple steps using different assignment operators.