Thuta Learning
BasicProgrammingbeginner

Python Operators

Relax. We'll talk through this in plain words — no textbook voice.

🐍 Lesson 11: Python Operators

1. What is an operator?

In short → An operator is a symbol used to perform calculations on variables and values.

More formally → An operator is a symbol used to perform operations on variables and values.

2. Types of Python Operators

(a) Arithmetic Operators+ - * / // % **

(b) Comparison Operators== != > < >= <=

(c) Logical Operatorsand or not

(d) Assignment Operators= += -= *= /= %=

(e) Membership Operatorsin, not in

(f) Identity Operatorsis, is not

3. Summary

Arithmetic+ - * / // % **

Comparison== != > < >= <=

Logicaland or not

Membershipin, not in

python
# ===== 1. Arithmetic Operators =====
x = 10
y = 3

print("===== Arithmetic =====")
print(f"x + y = {x + y}")   # 13
print(f"x - y = {x - y}")   # 7
print(f"x * y = {x * y}")   # 30
print(f"x / y = {x / y}")   # 3.333...
print(f"x // y = {x // y}") # 3 (Floor Division)
print(f"x % y = {x % y}")   # 1 (Modulus)
print(f"x ** y = {x ** y}") # 1000 (Exponentiation)

# ===== 2. Comparison Operators =====
print(f"\n===== Comparison =====")
a = 5
b = 10

print(f"a == b: {a == b}")  # False
print(f"a != b: {a != b}")  # True
print(f"a > b: {a > b}")    # False
print(f"a < b: {a < b}")    # True

# ===== 3. Logical Operators =====
print(f"\n===== Logical =====")
print(f"True and False: {True and False}")
print(f"True or False: {True or False}")
print(f"not True: {not True}")

# ===== 4. Assignment Operators =====
print(f"\n===== Assignment =====")
c = 5
c += 3  # c = c + 3
print(f"c += 3: {c}")  # 8
c *= 2  # c = c * 2
print(f"c *= 2: {c}")  # 16

# ===== 5. Membership Operators =====
print(f"\n===== Membership =====")
fruits = ["apple", "banana"]
print(f"'apple' in fruits: {'apple' in fruits}")
print(f"'mango' not in fruits: {'mango' not in fruits}")
You should see
===== Arithmetic ===== x + y = 13 x - y = 7 x * y = 30 x / y = 3.333... x // y = 3 x % y = 1 x ** y = 1000 ===== Comparison ===== a == b: False a != b: True a > b: False a < b: True ===== Logical ===== True and False: False True or False: True not True: False ===== Assignment ===== c += 3: 8 c *= 2: 16 ===== Membership ===== 'apple' in fruits: True 'mango' not in fruits: True
Python Operators | Thuta Learning