Introduction
Operators are special symbols that perform operations on values and variables.
Arithmetic Operators
a, b = 10, 3
print(a + b) # Addition: 13
print(a - b) # Subtraction: 7
print(a * b) # Multiplication: 30
print(a / b) # Division: 3.333...
print(a // b) # Floor Division: 3
print(a % b) # Modulus: 1
print(a ** b) # Exponentiation: 1000
Comparison Operators
x, y = 5, 10
print(x == y) # Equal: False
print(x != y) # Not equal: True
print(x < y) # Less than: True
print(x > y) # Greater than: False
print(x <= y) # Less or equal: True
print(x >= y) # Greater or equal: False
Logical Operators
a, b = True, False
print(a and b) # False
print(a or b) # True
print(not a) # False
Practice Problems
- Calculate compound interest with operators
- Check if a number is divisible by both 3 and 5
- Use operator precedence to evaluate complex expressions
- Compare strings lexicographically
- Implement a simple calculator using operators