Operators are the symbols Python uses to perform actions on values — adding numbers, comparing them, or combining logical conditions. Python groups its operators into a few categories: arithmetic, comparison, logical, and bitwise. Understanding each category is fundamental to writing almost any program.

Arithmetic Operators

Arithmetic operators perform mathematical calculations:

a, b = 10, 3

print(a + b)    # addition      -> 13
print(a - b)    # subtraction   -> 7
print(a * b)    # multiplication -> 30
print(a / b)    # division (always returns a float) -> 3.333...
print(a // b)   # floor division (rounds down) -> 3
print(a % b)    # modulus (remainder) -> 1
print(a ** b)   # exponentiation (a to the power of b) -> 1000

Output:

13
7
30
3.3333333333333335
3
1
1000

The two operators that most often trip up beginners coming from other languages are / and //: regular division always returns a float in Python, even when the result is a whole number, while floor division discards everything after the decimal point.

Comparison Operators

Comparison operators compare two values and always return a bool — True or False:

x, y = 5, 8

print(x == y)   # equal to       -> False
print(x != y)   # not equal to   -> True
print(x > y)    # greater than   -> False
print(x < y)    # less than      -> True
print(x >= 5)   # greater or equal -> True
print(x <= 4)   # less or equal    -> False

Output:

False
True
False
True
True
False

Comparison operators are what drive decision-making in your programs — they're the building blocks of if statements, covered in depth once you reach Python's control flow topics.

Logical Operators

Logical operators combine multiple boolean conditions into a single result: and, or, and not.

age = 25
has_id = True

print(age >= 18 and has_id)   # both must be True  -> True
print(age < 18 or has_id)     # at least one True    -> True
print(not has_id)             # flips the boolean     -> False

Output:

True
True
False

Bitwise Operators

Bitwise operators work directly on the binary representation of integers, bit by bit. They're used less often in everyday code but show up in low-level work, flags, and performance-sensitive code:

a, b = 6, 3   # binary: 110 and 011

print(a & b)    # AND  -> 2  (010)
print(a | b)    # OR   -> 7  (111)
print(a ^ b)    # XOR  -> 5  (101)
print(a << 1)   # left shift  -> 12 (1100)
print(a >> 1)   # right shift -> 3  (011)

Output:

2
7
5
12
3

You now have the full toolkit for calculating and comparing values. The next step is learning how to get data into your programs and display results back out, in Python input and output.