Quick Reference
Python Basics & Operators Cheat Sheet
Fast syntax reminders for every chapter and all seven Python operator groups. Copy any snippet or open it in the Playground.
Variables
Store values under descriptive snake_case names using =.
Data Types & Casting
Inspect types with type() and convert safely between scalar types.
print() Output
Display values, customize separators with sep, and line endings with end.
print(..., sep, end)
Control separator text between arguments and trailing characters.
print("2026", "11", "12", sep="-")print("Hi", end="! ")print("Python")Strings
Create single or multiline strings, index characters, check length, and format.
Booleans
True and False (capitalized) plus truthiness checks via bool().
True / False & bool()
0, 0.0, '', and None are False; non-empty values are True.
print(10 > 3)print(bool(""), bool("Hi"))Arithmetic Operators
Perform numeric calculations.
Assignment Operators
Store and update variables in place.
Comparison Operators
Compare values and return True or False.
== != > < >= <=
Equal, not equal, greater, less, greater/equal, less/equal.
print(5 == 5, 5 != 3, 7 > 2, 4 <= 4)Logical Operators
Combine or invert boolean conditions.
and or not
Logical AND, logical OR, and logical negation.
a, b = True, Falseprint(a and b, a or b, not b)Identity Operators
Test whether two variables point to the exact same object in memory.
is is not
Compare identity (use == for value equality, is for None or object identity).
x = [1, 2]y = [1, 2]print(x == y, x is y, x is not y)Membership Operators
Check if a value or substring exists inside a sequence.
in not in
Returns True if found (or not found) in a string or list.
text = "Learn Python"print("Py" in text, "Ruby" not in text)Bitwise Operators
Operate on individual binary bits of integers.
& | ^ ~ << >>
Bitwise AND, OR, XOR, NOT, left shift, and right shift.
print(6 & 3, 6 | 3, 6 ^ 3, ~6, 6 << 1, 6 >> 1)