agyanadda@gmail.com

Python Operators

Python Basics 1 min read Updated Dec 4, 2026 Topic 8 of 32

Arithmetic

+, -, *, / (always a float), // (floor division), % (remainder), ** (power).

Assignment

=, +=, -=, *=, /=, //=, %=, **=. Python has no ++ or --; use x += 1.

Comparison (result is True/False)

==, !=, >, <, >=, <=. You can chain them: 18 <= age < 60.

Logical

and, or, not. They short-circuit: in a and b, b is not checked if a is False.

Membership

in, not in — "a" in "cat", 3 in [1, 2, 3], "key" in my_dict.

Identity

is, is not — the same object (use for None). == checks equal values.

Bitwise

&, |, ^, ~, <<, >> — work on binary bits.

The walrus operator

:= assigns inside an expression: if (n := len(items)) > 5:

Precedence

** → * / // % → + - → comparisons → not → and → or. Use brackets to make intent clear.

Example

Example — Operators together Python
a, b = 17, 5
print(a + b, a - b, a * b, a / b, a // b, a % b, a ** 2)

age = 25
print(18 <= age < 60)          # chained comparison

has_ticket, is_vip = True, False
print(has_ticket and not is_vip)

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

x = [1, 2]
y = [1, 2]
print(x == y, x is y)          # equal values, different objects

count = 0
count += 5
print(count)

if (n := len(fruits)) >= 2:
    print(f"{n} fruits")

Output: 22 12 85 3.4 3 2 289, True, True, True True, True False, 5, 2 fruits

Test Yourself With Exercises

Exercise 1 Multiple Choice

What is 17 // 5?

Exercise 2 True / False

Python supports the ++ operator.

Exercise 3 Fill in the Blank

Check if a value is in a list with the ___ operator.

Frequently Asked Questions

Use is only to check identity, mainly with None (if x is None). For comparing values such as numbers, strings and lists, always use ==.