Operators

Operators

Arithmetic Operators

# Addition
result = 10 + 5    # 15

Subtraction

result = 10 - 5 # 5

Multiplication

result = 10 * 5 # 50

Division

result = 10 / 5 # 2.0

Floor Division

result = 10 // 3 # 3

Modulus (remainder)

result = 10 % 3 # 1

Exponentiation

result = 2 3 # 8

Comparison Operators

x = 10
y = 5

print(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 = False

print(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?

Variables and Data Types