Object Model and Data Model
- Everything is an object. Numbers, functions, classes, modules: everything in Python is an object with a type and identity.
- id, is and ==. The is operator compares identity: same object: while == asks the objects whether they are equal in value.
- Attributes and __dict__. Most objects keep their attributes in a __dict__: attribute access is dictionary lookup wearing a dot.
Magic Methods and Descriptors
- Dunder methods. Syntax is negotiated through dunder methods: + calls __add__, len() calls __len__, printing calls __repr__.
- __repr__ honestly. A good __repr__ shows how to rebuild the object: debugging quality is set by this one method.
- Descriptors. A descriptor intercepts attribute access through __get__ and __set__: the machinery behind property and methods.
Interpreter and Garbage Collection
- Bytecode. CPython compiles source to bytecode and a stack machine executes it: dis.dis shows the instructions.
- Reference counting. CPython frees an object the instant its reference count hits zero: deterministic and immediate.
- The cycle collector. Objects that reference each other in a cycle need the garbage collector’s periodic sweep to be freed.
Before and after this level
- Before: Level 13: Networking & Services: HTTP and APIs, Sockets and Network Programming, Building Reliable Service Code.
- Next: Level 15: Performance: Profiling Python, Memory and CPU Optimisation, Native Extensions and Performance Boundaries.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Python Level 14: Python Internals cover?
Object Model and Data Model, Magic Methods and Descriptors, Interpreter and Garbage Collection: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 13: Networking & Services, which covers HTTP and APIs, Sockets and Network Programming, Building Reliable Service Code.