Skip to main content

📒 Python glossary

Python terms in plain English

Short, opinionated definitions. No jargon ladders, no "see also" loops. Each term links to a CodeMentor lesson that teaches it for real. Skim, search (Cmd+F), or read top to bottom.

Async & concurrency

async def

sr-21

Declares a coroutine. Can be awaited; runs cooperatively on an event loop.

asyncio.gather

sr-25

Run multiple coroutines concurrently and wait for all of them. The bread-and-butter of fan-out.

asyncio.TaskGroup

sr-22

Structured concurrency primitive (Python 3.11+). `async with TaskGroup()` ensures every spawned task is awaited and any exception cancels the whole group — safer than bare `gather`.

asyncio.wait_for

sr-22

Cap any awaitable with a timeout: `await asyncio.wait_for(coro, timeout=5)`. Raises `TimeoutError` on expiry and cancels the inner task. Essential for any external call.

await

sr-22

Pauses a coroutine until another coroutine/Future finishes. Only legal inside `async def`.

Event loop

sr-23

Scheduler that drives async code — runs ready coroutines, parks blocked ones. `asyncio.run(main())` starts one.

GIL

sr-30

Global Interpreter Lock — CPython's mutex that lets only one thread run Python bytecode at a time. Threads still help for I/O; for CPU, use processes.

Data structures

Dict comprehension

lesson-67

Same as list comp, but builds a dict: `{k: v for k, v in pairs}`.

Dictionary

lesson-45

Hash map from keys to values. Insertion order preserved since Python 3.7.

Generator

lesson-110

A function with `yield`. Produces values lazily, one at a time — uses constant memory for streams.

Iterable

lesson-49

Anything you can loop over with `for`. Lists, tuples, sets, dicts, strings, files, generators — all iterables.

List comprehension

lesson-66

Inline syntax for building a list from another iterable, with optional filter: `[f(x) for x in xs if cond(x)]`. Beats `map+filter+lambda`.

NamedTuple

lesson-105

Tuple with named fields — accessed by `t.x` instead of `t[0]`. `typing.NamedTuple` is the modern form; gives you type hints + immutability for free.

Set

lesson-50

Unordered collection of unique hashable values. O(1) membership check.

Tuple

lesson-44

Ordered immutable sequence. Use for fixed-size records and as dict keys.

Errors & control flow

Context manager

lesson-108

An object usable with `with`. Guarantees cleanup even on exception — `open()`, locks, DB sessions.

EAFP

lesson-103

“Easier to Ask Forgiveness than Permission”. Idiomatic Python: try the operation, catch the exception, rather than pre-checking.

Exception

lesson-100

An object that signals something went wrong. Raised with `raise`, caught with `try/except`.

try / except / finally

lesson-101

Handle exceptions. `finally` always runs (cleanup). Catching `Exception` is usually too broad — be specific.

Functions

*args, **kwargs

lesson-65

Capture variable positional and keyword arguments. Lets a function accept any signature.

Closure

lesson-118

An inner function that captures variables from its enclosing scope. The captured value is by reference, not by value.

Decorator

lesson-115

A higher-order function that wraps another to add behavior — logging, caching, auth. `@cache` is one.

Default argument

lesson-60

Parameter with a fallback value: `def f(x=10)`. Beware mutable defaults — `def f(xs=[])` is a classic trap.

Function

lesson-58

Named reusable block of code. Defined with `def`. First-class — you can pass functions like any other value.

functools.partial

sr-108

Pre-bind some arguments of a function — produces a new callable with fewer parameters. Cleaner than a wrapping lambda for currying-style use.

Lambda

lesson-69

An anonymous one-line function: `lambda x: x*2`. Use for short callbacks; prefer `def` when readable.

OOP

__init__

lesson-84

The constructor — runs when you call the class. Used to set instance attributes.

ABC (Abstract base class)

lesson-145

Inheriting `abc.ABC` + decorating with `@abstractmethod` prevents instantiation until subclasses override every abstract method. Documentation the language enforces.

Class

lesson-81

A blueprint for objects. Created with `class Foo:`. Defines attributes + methods.

classmethod / staticmethod

lesson-82

`@classmethod` receives the class as `cls` (alternative constructors, class-level state). `@staticmethod` gets neither `self` nor `cls` — a function namespaced inside the class.

Dataclass

lesson-105

Decorator (`@dataclass`) that auto-generates `__init__`, `__repr__`, and `__eq__` from typed attributes.

Dunder methods

lesson-90

Double-underscore methods that hook into Python syntax: `__add__`, `__len__`, `__repr__`. Make your objects feel native.

Inheritance

lesson-88

A class can inherit attributes and methods from a parent class: `class Dog(Animal):`.

Instance

lesson-82

A specific object built from a class. `dog = Dog()` makes one instance of `Dog`.

Property

lesson-86

`@property` turns a method into a read-only attribute. Accessed without parentheses; computed on demand. Common when the value derives from other state.

self

lesson-83

The current instance, passed implicitly as the first argument to methods. By convention named `self`, but the name isn't magic.

Standard library

collections.Counter

lesson-128

Dict subclass that counts hashable items: `Counter("hello")` → `{'l': 2, ...}`.

collections.defaultdict

iv-43

Dict that auto-creates missing keys with a factory: `defaultdict(list)` returns `[]` for any new key. Replaces `if k not in d: d[k] = []`-style code in counters and grouping.

dataclasses.field

lesson-106

Configure a dataclass attribute — mutable defaults, init/repr behavior. Use `field(default_factory=list)` to avoid the mutable-default trap.

functools.cache

lesson-131

Memoize a pure function with `@functools.cache`. Replaces hand-rolled dict caching.

itertools

lesson-130

Iterator building blocks — `chain`, `groupby`, `combinations`, `accumulate`. Lazy, memory-friendly.

pathlib.Path

lesson-126

Object-oriented filesystem paths. `Path(".").rglob("*.py")` beats `os.walk + os.path.join`.

Syntax

f-string

lesson-08

An f-prefixed string literal that lets you inline expressions: `f"x={x}"`. Introduced in Python 3.6, now the default formatter.

Match statement

iv-94

Structural pattern matching (PEP 634, Python 3.10+). `match val: case Point(x, y): ...`. Matches on shape, not just value — closer to Rust/Scala match than C switch.

Slicing

lesson-31

Substring/sublist via `s[start:stop:step]`. Negative indices count from the end.

Truthy / falsy

lesson-21

Values that act as True / False in `if` statements. Empty containers, `0`, `None`, `""` are falsy; everything else is truthy.

Type hints

lesson-101

Annotations that describe expected types: `def f(x: int) -> str:`. Not enforced at runtime — used by tools like mypy.

Walrus operator

lesson-92

`:=` assigns inside an expression. Useful when you'd otherwise compute the same value twice.

Testing

Coverage

lesson-143

Measures which lines your tests execute. 100% is rarely the goal — 'every important path covered once' is.

Fixture

lesson-141

Reusable test setup. Declared with `@pytest.fixture`, injected by parameter name.

Parametrize

lesson-142

Run the same test against multiple inputs: `@pytest.mark.parametrize("x,y", [(1,2), (3,4)])`. Replaces copy-paste tests.

pytest

lesson-140

De facto Python test framework. `def test_x():` and `assert` — that's the whole API.

Tooling

Black

lesson-154

Opinionated Python formatter. Stops bike-shedding about style — one command, one canonical form.

mypy

lesson-156

Static type checker for Python. Catches type errors before runtime. Works best when you adopt incrementally.

pip

lesson-151

Python's package manager. `pip install requests` fetches from PyPI.

pyproject.toml

lesson-153

Modern Python project config. Replaces setup.py + setup.cfg + (eventually) requirements.txt.

requirements.txt

lesson-152

Plain text list of dependencies, optionally pinned: `requests==2.31.0`. `pip install -r requirements.txt` recreates the env.

ruff

lesson-155

Fast Rust-based Python linter. Replaces flake8 + isort + several plugins, ~100× faster.

uv

lesson-157

Fast Rust-based Python package + project manager. Drop-in replacement for pip + venv with much faster installs.

virtualenv / venv

lesson-150

Per-project Python environment. Isolates dependencies so two projects can use different package versions.

Web & APIs

CORS

fastapi-30

Cross-Origin Resource Sharing — browser security check on which origins may call your API. Set with response headers, not in the client.

FastAPI

fastapi-01

Modern Python web framework. Type-driven, async-first, autogenerates OpenAPI docs.

httpx ASGITransport

fastapi-18

Test transport that calls your FastAPI/Starlette app in-process — no real TCP, no port conflict, deterministic, 10-100× faster than spinning up a real server.

JWT

fastapi-25

JSON Web Token — a signed, base64-encoded payload used for stateless auth. Verify, don't trust.

OpenAPI

fastapi-12

Spec for describing REST APIs as JSON/YAML. FastAPI emits one automatically; tools generate clients + docs from it.

Pydantic

fastapi-05

Data validation library. Define a model, get parsing + validation + JSON serialization for free.

REST

fastapi-08

Architectural style for HTTP APIs — resources at URLs, verbs in the HTTP method, stateless requests.

WSGI / ASGI

fastapi-01

Server-application interfaces. WSGI (PEP 3333) is sync — Flask, Django until 3.0. ASGI extends it for async + WebSockets — FastAPI, Starlette, modern Django. uvicorn / hypercorn speak ASGI; gunicorn speaks WSGI.

Missing a term? Tell us what to add.