Code Reference

Glossary

Python · Reference cheat sheet

Glossary

Python · Reference cheat sheet


📋 Overview

Alphabetical glossary of core Python terms covering types, syntax, OOP, packaging, and runtime concepts you meet daily.

🔧 Core concepts

TermDefinition
AnnotationOptional type hint attached to a variable, parameter, or return value.
ArgumentA value passed into a function when it is called.
BytecodeIntermediate instructions CPython compiles source into before the interpreter runs it.
ClassA blueprint that defines attributes and methods for creating objects.
ClosureA nested function that remembers variables from its enclosing scope.
ComprehensionCompact syntax that builds a list, set, or dict from an iterable expression.
Context managerAn object usable with with that sets up and tears down a resource.
CoroutineAn async def function that can pause and resume with await.
DecoratorA callable that wraps another function or class to modify behavior.
DescriptorAn object defining __get__/__set__/__delete__ that customizes attribute access.
DictA mutable mapping of unique hashable keys to values.
DunderA “double underscore” special method or attribute such as __init__.
ExceptionAn error object raised to interrupt normal control flow.
GeneratorA function using yield that produces values lazily as an iterator.
GILGlobal Interpreter Lock that allows only one CPython bytecode thread at a time.
ImmutableA value that cannot change after creation, such as str, tuple, or frozenset.
ImportThe mechanism that loads a module or package into the current namespace.
IteratorAn object with __next__ that yields items until StopIteration.
LambdaA small anonymous function expressed as lambda args: expression.
ListAn ordered, mutable sequence of elements.
MethodA function defined on a class and bound to an instance when accessed.
ModuleA single .py file that can be imported as a namespace.
MutableAn object whose contents can change in place, such as list or dict.
NamespaceA mapping from names to objects, such as locals, globals, or a module dict.
PackageA directory of modules, typically with __init__.py, importable as a unit.
ParameterA named slot in a function definition that receives an argument.
PropertyA managed attribute exposed via getter/setter methods using @property.
SetAn unordered collection of unique hashable elements.
SliceA range of indices written as start:stop:step used to extract subsequences.
StatementA complete instruction that performs an action, such as assignment or return.
TupleAn ordered, immutable sequence often used for fixed groupings.
Virtual environmentAn isolated Python install directory for project-specific packages.
Walrus operatorThe := operator that assigns a value inside an expression.

💡 Examples

Comprehension and slice:

nums = [1, 2, 3, 4, 5]
evens = [n for n in nums if n % 2 == 0]
print(nums[1:4])  # [2, 3, 4]

Decorator and context manager:

from functools import wraps
from pathlib import Path

def once(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        return fn(*args, **kwargs)
    return wrapper

with Path("notes.txt").open() as f:
    text = f.read()

Walrus operator:

while (line := input(">> ")) != "quit":
    print(line.upper())

⚠️ Pitfalls

  • Confusing parameter (definition) with argument (call-site value).
  • Mixing list (mutable) with tuple (immutable) when APIs expect one or the other.
  • Treating iterator and iterable as the same — an iterable can be re-looped; many iterators cannot.
  • Assuming annotation enforces types at runtime — they are hints unless a checker or validator runs.
  • Equating module and package — a package is a collection of modules.

On this page