Arithmetic Operators
Python provides all the standard arithmetic operators you'd expect from a calculator, plus a few extras like floor division and exponentiation.
x = 15
y = 4
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x // y)
print(x % y)
print(x ** y)
Try it Yourself →
Comparison Operators
Comparison operators compare values and return True or False. They're the building blocks of decision-making in code.
a = 10
b = 20
print(a == b)
print(a != b)
print(a < b)
print(a > b)
print(a <= b)
print(a >= b)
Try it Yourself →
Logical Operators
and, or, and not let you combine multiple conditions into more complex checks.
x = 5
print(x > 0 and x < 10)
print(x > 0 or x > 10)
print(not x > 0)
Try it Yourself →
Identity Operators
is and is not check if two variables refer to the same object in memory, not just if they have the same value.
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a is c)
print(a is b)
print(a is not b)
Try it Yourself →