Operators
Operators
Arithmetic Operators
# Addition
result = 10 + 5 # 15Subtraction
result = 10 - 5 # 5Multiplication
result = 10 * 5 # 50Division
result = 10 / 5 # 2.0Floor Division
result = 10 // 3 # 3Modulus (remainder)
result = 10 % 3 # 1Exponentiation
result = 2 3 # 8
Comparison Operators
x = 10
y = 5print(x == y) # False (equal)
print(x != y) # True (not equal)
print(x > y) # True (greater than)
print(x < y) # False (less than)
print(x >= y) # True (greater or equal)
print(x <= y) # False (less or equal)
Logical Operators
a = True
b = Falseprint(a and b) # False
print(a or b) # True
print(not a) # False
Assignment Operators
x = 10
x += 5 # x = x + 5 → x = 15
x -= 3 # x = x - 3 → x = 12
x = 2 # x = x 2 → x = 24
Operator Precedence
1. (exponentiation) 2. *, /, //, % (multiplication/division) 3. +, - (addition/subtraction) 4. Comparison operators 5. not, and, or (logical)
Summary
- Arithmetic: +, -, , /, //, %, *
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -=, *=, /=
Next Lesson
In the next lesson, you'll learn about strings and formatting.
Quiz - Quiz - Operators
1. What is the result of 10 // 3?
2. What does == operator do?
3. What is the result of True and False?