- 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.
Arithmetic, comparison, logical, identity and membership.
✍️ 3 exercises + code challenge in this lesson+ - * / // % **= += -= *= /=== != > < >= <=and, or, notis, is not (same object in memory)in, not inPython also allows chained comparisons: 18 <= age < 60.
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.
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)
Check what you learned in “Python Operators”.
Check whether "mango" is in the list.
print("mango" fruits)
What does "is" compare?
Print whether age is between 18 and 60 (inclusive) using a chained comparison.
Free sign-in required · Google login available
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