Python Cheat Sheet 2026

Updated for Python 3.13 / 3.14 – Quick reference, examples, new features & best practices

1. Basics & Syntax


# Hello World
print("Hello, Python 2026!")

# Variables (no type declaration needed)
name = "Alice"
age = 30
is_dev = True
height = 1.75

# Multiple assignment
x, y, z = 1, 2.5, "text"
                        

# Constants (by convention)
PI = 3.14159
MAX_USERS = 100

# Type hints (optional but recommended)
def greet(name: str, age: int = 25) -> str:
    return f"Hello {name}, age {age}"
                        

2. Data Structures


# List (mutable, ordered)
fruits = ["apple", "banana", "cherry"]
fruits.append("date")
fruits[1] = "blueberry"

# List comprehension
squares = [x**2 for x in range(10)]
evens = [x for x in range(20) if x % 2 == 0]
                        

# Dictionary (mutable, ordered in 3.7+)
person = {"name": "Bob", "age": 28, "city": "Dubai"}
person["job"] = "Developer"

# Dict comprehension
squares_dict = {x: x**2 for x in range(10)}
                        

3. Control Flow


# If / Elif / Else
if age < 18:
    print("Minor")
elif age < 65:
    print("Adult")
else:
    print("Senior")

# Ternary operator
status = "Adult" if age >= 18 else "Minor"

# Match-case (Python 3.10+)
match command:
    case "start":
        print("Starting...")
    case "stop":
        print("Stopping...")
    case _:
        print("Unknown command")
                

4. Functions & Lambdas


# Basic function
def add(a: int, b: int = 0) -> int:
    return a + b

# Lambda (anonymous)
multiply = lambda x, y: x * y

# Decorators (2026 style)
def timer(func):
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        print(f"{func.__name__} took {time.time() - start:.2f}s")
        return result
    return wrapper

@timer
def slow_function():
    time.sleep(1)
                

5. New in Python 3.13 / 3.14 (2026)

  • Improved error messages (colorized, more helpful)
  • Better REPL with multi-line editing & syntax highlighting
  • Experimental JIT compiler (faster execution)
  • New typing features (e.g. `TypeIs`, `TypeGuard` improvements)
  • Faster `pathlib`, `tomllib`, `sqlite3`

6. Common Built-ins


print(), len(), type(), id(), dir()
range(), enumerate(), zip(), map(), filter()
sorted(), max(), min(), sum(), all(), any()
str(), int(), float(), list(), dict(), set()
open(), input(), repr(), eval(), exec()
                    

# New in recent versions
breakpoint()           # debugging
__import__()           # dynamic import
locals(), globals()
vars(), dir(), help()
                    

Last updated: January 2026 • Python 3.13 / 3.14 compatible
Bookmark or print this page for quick reference!