Name
A label in a namespace, such as x. It does not store a value. It points at an object. See Session 01.
Short definitions for the words this course uses again and again. Search, then jump back into the session that shows the idea in memory.
No terms match that search.
A label in a namespace, such as x. It does not store a value. It points at an object. See Session 01.
Everything in Python is an object: numbers, strings, lists, functions, classes, instances. An object has identity, a type, and a value. Objects live on the heap.
The connection from a name (or a container slot) to an object. Assignment creates or changes a reference. It does not copy the object unless you ask for a copy.
Which object something is, not what it looks like. id(x) and x is y test identity. Two names with the same identity are aliases.
== asks whether two objects have the same value. They can be equal and still be different objects.
Two or more names (or slots) pointing at the same object. Mutations through any alias are visible to all of them.
x = something_else makes the name point at a different object. The old object is unchanged; it just loses one reference.
Changing an object in place without creating a new one. lst.append(1) mutates. The object's id() stays the same.
A mutable object can change its contents (list, dict, set, instances). An immutable object cannot (int, str, tuple). “Changing” an immutable name always rebinds.
How many names or containers currently point at an object. In CPython, when this hits zero the object is freed immediately. Cycles need a separate collector.
The region of memory where objects live. Every Python object — an int, a list, a function, a class — is allocated on the heap. Names live in namespaces and point into it.
The pile of frames for calls currently in progress. Each call pushes a frame; each return pops one. A traceback is a printout of this stack. See Session 02.
Freeing objects nothing refers to any more. CPython does this mainly by reference counting: the instant a count hits zero the object is freed. A separate cyclic collector handles objects that only refer to each other.
CPython builds the integers −5 to 256 once at start-up and hands out the same object every time, so a = 42; b = 42 gives two names for one object. Those objects are never freed. It is an implementation detail, not a language guarantee — never write code that depends on it.
CPython reuses some immutable objects, especially small integers (typically -5 to 256) and some strings. That is an optimization, not a language rule. Do not write code that depends on it.
def creates a function object and binds a name to it. The body does not run at definition time. See Session 02.
The temporary workspace for one function call: local names, the current line, and the path back to the caller. Frames stack; the top one is running.
Name lookup order: Local, Enclosing function scopes, Global, Built-ins. Assignment creates a local name unless you declare global or nonlocal.
A parameter is a local name bound to the object the caller passed. Python does not copy that object. Mutating it is visible to the caller; rebinding the parameter is not.
An inner function plus the outer names it still needs after the outer call returns. nonlocal updates a remembered outer name instead of creating a new local.
Default values are created once, when the function is defined, and stored on the function object. A mutable default is shared across calls — a classic surprise.
An object whose contents are references to other objects. Lists, dicts, tuples, and sets are containers. See Session 03.
A new outer container filled with the same inner references. list.copy() and dict.copy() are shallow. Nested objects stay shared.
A recursive copy of nested objects. Use it only when you need nested independence. Some objects should stay shared on purpose.
An object with a stable hash, required for dict keys and set elements. Built-in immutables are usually hashable. Lists and dicts are not.
class creates a class object. It holds methods and class attributes. Calling the class creates an instance. See Session 04.
An object created by calling a class. It has its own identity and usually its own __dict__ for instance attributes.
The conventional name for the instance a method is operating on. Python passes it automatically when you write obj.method().
The mapping that stores an object's writable attributes. Instance attributes live on the instance dict. Methods usually live on the class dict.
Python looks on the instance first, then the class, then base classes (the MRO). That is why a class attribute is visible on every instance until one instance shadows it.
Accessing a function on an instance creates a method object that already remembers self. g.hello is not the raw function; it is hello bound to g.
The initializer. After the instance exists, Python calls __init__(self, ...) to write attributes. It returns None. The caller receives the instance, not that return value. See Session 04.
The allocator. Calling a class first creates the instance, then initializes it. You almost never override __new__. The important picture: the object exists before __init__ runs.
A name stored on the class object. Every instance can read it until it assigns the same name on itself. A mutable class attribute (a list on the class) is one shared object.
A name stored in the instance __dict__. Assignment on an instance usually creates one of these. It shadows a class attribute of the same name for that instance only.
Method resolution order: the list of classes Python searches for an attribute. For class Dog(Animal) it is Dog → Animal → object. Subclasses do not copy methods; they walk this list.
The instance's link to its class. type(p) is Point and p.__class__ is Point are the same idea. Lookup follows this pointer after the instance dict misses.
An object you can loop over. It can produce an iterator via iter(obj). Lists, strings, dicts, and generators are iterable. See Session 05.
An object with state that yields one item at a time through next(). When it is exhausted it raises StopIteration. A for loop hides this protocol.
A function that uses yield. Calling it does not run the body; it returns a generator object. Each next() resumes a suspended frame until the next yield.
Work is done only when the next value is requested. A generator expression keeps one pending computation; a list comprehension builds every value immediately.
The signal that an iterator is exhausted. A for loop catches it and exits. The collection is unchanged; the iterator is spent. A new for on a list creates a new iterator. A generator does not rewind.
A callable that takes a function and returns a replacement. @deco above a def is shorthand for f = deco(f): your function is built, handed to deco, and the name is bound to whatever comes back. See Session 06.
The function a decorator returns. It usually calls the original and adds something around it. After decorating, your name points at the wrapper — not at the function you wrote.
The small box that keeps an outer name alive for an inner function. It is why a wrapper can still reach your original function after the decorator's frame is gone, and why that original is not garbage collected even though no name points at it. See Session 02.
A function you call to get a decorator, which is how a decorator takes arguments. In @repeat(2), repeat(2) runs first and returns the decorator that is then applied to your function.
functools.wrapsA decorator applied to a wrapper. It copies __name__, __qualname__, __doc__, __module__ and __annotations__ from the original function onto the wrapper, so tracebacks and help() keep telling the truth.
__wrapped__The attribute functools.wraps sets on a wrapper, pointing at the function underneath. It is how tools reach past a decorator to the real thing.