Concept Flow - Object lifecycle overview
Create Object
→Initialize __init__
Use Object
Delete Object
→Call __del__
This flow shows how an object is created, initialized, used, and then deleted in Python.
class MyObject: def __init__(self): print('Object created') def __del__(self): print('Object deleted') obj = MyObject() del obj
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Create object obj | Calls __init__ | Prints 'Object created' |
| 2 | Object obj ready | Object exists in memory | No output |
| 3 | Delete object obj | Calls __del__ | Prints 'Object deleted' |
| 4 | Object obj removed | No longer accessible | No output |
| Variable | Start | After Creation | After Deletion |
|---|---|---|---|
| obj | None | Reference to MyObject instance | No reference (deleted) |
Object lifecycle in Python: 1. Creation calls __init__ to initialize. 2. Object is ready to use. 3. Deletion calls __del__ to clean up. 4. Object memory is freed after deletion. Use del to delete objects explicitly.