← Lesson
BitWithBite
Python · Quick Reference

Lesson 4 — Operators Cheat Sheet

Python
In one line: Arithmetic operators perform mathematical calculations. Python has 7 of them — you know most from school, but two are unique to programming.

Key Ideas

1Arithmetic Operators. Arithmetic operators perform mathematical calculations. Python has 7 of them — you know most from school, but two are unique to programming.
2Comparison Operators. Comparison operators compare two values and always return a boolean — either True or False. They are the backbone of every if statement and loop condition you'll ever ...
3Logical Operators. Logical operators combine multiple boolean expressions. Python uses English words (and, or, not) instead of symbols like && and || used in other languages — ma...
4Assignment Operators. You already know = for assigning values. Python also has augmented assignment operators that combine an arithmetic operation with assignment in one step.
5Identity & Membership Operators. Two more operator categories complete the picture. You've already seen in with strings — it works on all Python collections.

Code Examples

a, b = 17, 5 print(a + b) # 22 — addition print(a - b) # 12 — subtraction print(a * b) # 85 — multiplication print(a / b) # 3.4 — true division (always float!) print(a // b) # 3 — floor division (discard remainder) print(a % b) # 2 ...
age = 20 print(age >= 18) # True — is adult? print(age == 21) # False — exact match print(age != 21) # True — not equal # Chained comparisons — very Pythonic! score = 75 print(60 score 100) # True — is it between 60 and 100? # Comparing st...
age = 22 has_id = True is_member = False # and — both conditions required print(age >= 18 and has_id) # True (22≥18 AND has ID) print(age >= 18 and is_member) # False (22≥18 BUT not member) # or — at least one condition required print(ha...