PythonGlossary

Glossary

A quick-reference glossary of jargon you will run into throughout the Python docs on this site — from everyday terms like module to implementation details like the GIL. Definitions are kept short on purpose; follow the related tutorial pages for the full story.

Term

Definition

Bytecode

The low-level instructions the Python interpreter actually executes. Source code is compiled to bytecode (stored in .pyc files) before it runs.

Closure

A function that remembers values from the scope it was defined in, even after that scope has finished executing. Common in decorators and factory functions.

Comprehension

A compact expression for building a list, dict, set, or generator from an iterable in a single line, optionally with a filter.

Context manager

An object that defines __enter__ and __exit__, used with the with statement to guarantee setup and cleanup (e.g. closing a file) even if an exception occurs.

Decorator

A function that wraps another function (or class) to add behaviour without changing its source code, applied with the @decorator syntax.

Docstring

A string literal placed as the first statement in a module, function, class, or method, used as that object's documentation and accessible via __doc__.

Duck typing

A style of typing where an object's suitability is determined by the methods and attributes it has, not its actual class — "if it walks like a duck...".

Exception

An event raised when an error occurs during execution, which interrupts the normal flow of a program unless it is caught with try/except.

First-class function

A function that can be assigned to a variable, passed as an argument, or returned from another function, just like any other value.

f-string

A string literal prefixed with f that lets you embed expressions directly inside {} placeholders, e.g. f"{name} is {age}".

Garbage collection

Python's automatic memory management, which reclaims objects that are no longer reachable — primarily via reference counting, with a cyclic collector for reference cycles.

Generator

A function containing yield that produces a sequence of values lazily, one at a time, instead of building the whole sequence in memory up front.

GIL

The Global Interpreter Lock — a mutex in CPython that allows only one thread to execute Python bytecode at a time, which limits true parallelism for CPU-bound threads.

Higher-order function

A function that takes another function as an argument, returns a function, or both — for example map(), filter(), and decorators.

Immutable

An object whose state cannot be changed after it is created. Numbers, strings, and tuples are immutable — any "change" actually creates a new object.

Interpreter

The program that reads and executes Python source code (compiling it to bytecode first), as opposed to a compiler that produces a standalone binary ahead of time.

Iterable

Any object you can loop over with for, because it implements __iter__ (or __getitem__) — lists, strings, dicts, and files are all iterables.

Iterator

An object that produces values one at a time via __next__, and raises StopIteration when exhausted. Calling iter() on an iterable gives you an iterator.

Magic method / dunder method

A method with double underscores on each side (like __init__ or __len__) that lets an object customise how it behaves with built-in operators and functions.

Metaclass

The "class of a class" — by default type — which controls how classes themselves are created. Used to customise class creation, though rarely needed in everyday code.

Module

A single Python file containing definitions and statements that can be imported and reused in other files.

Monkey patching

Modifying or extending a class or module at runtime, after it has already been defined — for example, replacing a method on a third-party class for testing.

Mutable

An object whose contents can be changed in place after creation, without creating a new object. Lists, dicts, and sets are mutable.

Namespace

A mapping from names to objects (roughly a dictionary) that determines which variables and functions are visible at a given point in code.

Package

A directory of Python modules that contains an __init__.py file (or is an implicit namespace package), letting related modules be grouped and imported together.

PEP

A Python Enhancement Proposal — a design document that describes a new feature or process for the language. PEP 8, the style guide, is the most widely referenced.

REPL

The Read-Eval-Print Loop — the interactive Python shell you get by running python with no arguments, useful for quick experiments.

Scope

The region of code where a name is visible and accessible — Python resolves names using the LEGB rule: Local, Enclosing, Global, Built-in.

Slice

A way to extract a subsequence from a sequence using start:stop:step syntax inside square brackets, e.g. my_list[1:5:2].

Truthy/Falsy

Whether a value evaluates as True or False in a boolean context. Empty collections, 0, "", and None are falsy; most everything else is truthy.

Type hint

Optional annotation that documents the expected type of a variable, parameter, or return value (e.g. def add(a: int, b: int) -> int), checked by external tools like mypy rather than enforced at runtime.

Virtual environment

An isolated Python environment with its own installed packages, created with venv or similar tools, so that different projects can use different (and conflicting) dependency versions.