Part 1 · Section 03
Variables and Memory
In many languages a variable is a named box that holds a value. Python works differently: a variable is a name that refers to an object living somewhere in memory. That one idea explains a lot of behavior that otherwise looks surprising, like why changing one list can change “another”, why is and == can disagree, and why a is b is sometimes True for numbers you never linked together.
In this section you’ll learn:
- how names reference objects, and how to look at memory addresses with
id() - how CPython decides when to free memory (reference counting and the garbage collector)
- dynamic typing and what really happens when you re-assign a variable
- mutable vs immutable objects, and why that matters for function arguments and shared references
- identity (
is) vs equality (==), and the specialNoneobject - why “everything is an object” in Python, including functions
- the optimizations CPython applies: integer and string interning, and peephole/constant folding
Lectures
- 01Variables are Memory References✓
- 02Reference Counting✓
- 03Garbage Collection✓
- 04Dynamic vs Static Typing✓
- 05Variable Re-Assignment✓
- 06Object Mutability✓
- 07Function Arguments and Mutability✓
- 08Shared References and Mutability✓
- 09Variable Equality✓
- 10Everything is an Object✓
- 11Python Optimizations - Interning✓
- 12Python Optimizations - String Interning✓
- 13Python Optimizations - Peephole✓