Python Operators

Arithmetic, comparison, logical, identity and membership.

✍️ 3 exercises + code challenge in this lesson
  • Arithmetic: + - * / // % **
  • Assignment: = += -= *= /=
  • Comparison: == != > < >= <=
  • Logical: and, or, not
  • Identity: is, is not (same object in memory)
  • Membership: in, not in

Python also allows chained comparisons: 18 <= age < 60.

Key Takeaways: Python Operators

Mastering Python Operators helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Python Operators Code Example

Python
print(17 / 5, 17 // 5, 17 % 5, 2 ** 10)

x = 10
x += 5
print("x =", x)

age = 25
print(18 <= age < 60)
print(age > 18 and age < 30, not age > 18)

fruits = ["mango", "apple"]
print("mango" in fruits, "kiwi" not in fruits)

a = [1, 2]
b = a
c = [1, 2]
print(a is b, a is c, a == c)
Free sign-in required · Google login available

Python Operators Practice Exercises

Check what you learned in “Python Operators”.

/ 3 solved
Fill in the blank

Check whether "mango" is in the list.

print("mango"  fruits)
✓ Correct! Not quite. Try again.
Multiple choice

What does "is" compare?

✓ Correct! Not quite. Try again.
Code challenge

Print whether age is between 18 and 60 (inclusive) using a chained comparison.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services