Skip to main content
Python Learning

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 =.

Lesson →

Assign a variable

Create a variable without declaring a type keyword.

Try
name = "Maya"age = 15

Multiple assignment

Assign multiple variables in a single statement.

Try
x, y = 10, 20a = b = 0

Data Types & Casting

Inspect types with type() and convert safely between scalar types.

Lesson →

str, int, float, bool

Core beginner data types in Python.

Try
text = "Python"whole = 9decimal = 3.14ready = True

type() & casting

Check a value's type or convert between int, float, str, and bool.

Try
print(type(42))num = int("12") + 3label = "Score: " + str(num)

print() Output

Display values, customize separators with sep, and line endings with end.

Lesson →

print(..., sep, end)

Control separator text between arguments and trailing characters.

Try
print("2026", "11", "12", sep="-")print("Hi", end="! ")print("Python")

Strings

Create single or multiline strings, index characters, check length, and format.

Lesson →

Indexing & len()

First character is at [0], last is at [-1].

Try
word = "Python"print(len(word), word[0], word[-1])

f-strings

Embed variables and expressions inside f"...".

Try
name = "Sam"print(f"Hello, {name}!")

Booleans

True and False (capitalized) plus truthiness checks via bool().

Lesson →

True / False & bool()

0, 0.0, '', and None are False; non-empty values are True.

Try
print(10 > 3)print(bool(""), bool("Hi"))

Arithmetic Operators

Perform numeric calculations.

Lesson →

+ - * /

Addition, subtraction, multiplication, and float division.

Try
print(10 + 3, 10 - 3, 10 * 3, 10 / 4)

% ** //

Modulus remainder, exponentiation (power), and floor division.

Try
print(17 % 5, 2 ** 4, 17 // 5)

Assignment Operators

Store and update variables in place.

Lesson →

= += -= *= /=

Assign or modify a variable using arithmetic shortcuts.

Try
x = 10x += 5x -= 2x *= 2x /= 2print(x)

%= //= **=

Compound modulus, floor division, and exponent updates.

Try
n = 17n //= 5n **= 2print(n)

Comparison Operators

Compare values and return True or False.

Lesson →

== != > < >= <=

Equal, not equal, greater, less, greater/equal, less/equal.

Try
print(5 == 5, 5 != 3, 7 > 2, 4 <= 4)

Logical Operators

Combine or invert boolean conditions.

Lesson →

and or not

Logical AND, logical OR, and logical negation.

Try
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.

Lesson →

is is not

Compare identity (use == for value equality, is for None or object identity).

Try
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.

Lesson →

in not in

Returns True if found (or not found) in a string or list.

Try
text = "Learn Python"print("Py" in text, "Ruby" not in text)

Bitwise Operators

Operate on individual binary bits of integers.

Lesson →

& | ^ ~ << >>

Bitwise AND, OR, XOR, NOT, left shift, and right shift.

Try
print(6 & 3, 6 | 3, 6 ^ 3, ~6, 6 << 1, 6 >> 1)