đź§© Memory Basics¶
Python programs manipulate objects. Variables don’t “contain” the object — they refer to it.
This topic focuses on:
- object identity:
id() - mutability vs immutability
- avoiding unnecessary copies using
memoryview
âś… Object Identity & References¶
a and b are two names pointing to the same list.
âś… Mutability¶
- Mutable objects can change “in place” (list, dict, set).
- Immutable objects can’t (int, float, str, tuple). “Changing” them creates a new object.
âś… Views with memoryview¶
If you slice bytes, you often create a copy.
With memoryview(), you can create a view into the same underlying buffer.
🔍 Key Takeaways¶
- Variables hold references to objects.
- Mutability decides whether changes affect the same object.
memoryviewhelps avoid copies for binary data.