2. Object Lifecycle
Python objects have a lifecycle: creation, usage, and destruction.
Creation
Objects are created when assigned:
x = [1, 2, 3]
Usage
Objects are referenced and manipulated by variables.
Destruction
When no references remain, the object is garbage collected.
Example
def foo():
x = [1, 2, 3]
return x
y = foo() # x continues to live because it is returned
Wrap-Up
Objects live as long as references to them exist.