Skip to main content

Operators in Python

Operators perform operations on values and variables.

Arithmetic operators​

OperatorMeaningExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Division (float)7 / 23.5
//Floor division7 // 23
%Modulus7 % 31
**Exponent2 ** 38

Comparison operators​

==, !=, >, <, >=, <= return a bool.

print(5 > 3) # True
print(5 == 5.0) # True

Logical operators​

age = 20
print(age > 18 and age < 60) # True
print(not age > 18) # False

Assignment operators​

x = 10
x += 5 # 15
x *= 2 # 30

Membership and identity​

print("a" in "banana") # True
print(3 not in [1, 2, 3]) # False
a = [1]; b = a
print(a is b) # True (same object)