SLIDE 1 Object Internals in Python
SLIDE 2 Who am I?
- Python Enthusiast
- Backend Developer by profession.
- I love speaking at various meetup groups and
conferences.
- Twitter handle - @Mridu__
SLIDE 3 Learning Objectives
- objects
- memory address
- type of objects (mutable
and immutable objects)
- difference between is vs ==
- perator
- optimizations
SLIDE 4
An object is an entity that has attribute and methods associated with it.
SLIDE 5
Example:
SLIDE 6
SLIDE 7
The location where the object gets stored in memory is referred to as memory address.
SLIDE 8
Pictorial Representation
SLIDE 9
id(object) - id is a built-in function. It is used to determine the memory address of the object.
SLIDE 10
SLIDE 11
Mutable objects and Immutable objects.
SLIDE 12
Objects of built-in type (list, dictionary, sets) are mutable.
SLIDE 13
SLIDE 14
Objects of built-in type (int, float, bool, str, tuple) are immutable.
SLIDE 15
SLIDE 16
Difference between is vs == operator
SLIDE 17
SLIDE 18
SLIDE 19 Different use cases to discuss memory
SLIDE 20
- 1. Sort and Sorted built-in methods
SLIDE 21
SLIDE 22
- 2. Concept of Integer Caching
SLIDE 23
SLIDE 24
- 3. Concept of String Interning
SLIDE 25 As the Python code compiles identifiers are interned.
- variable names
- function names
- class names
Rule: * start with _ or a letter. * may contain _, letter, numbers.
SLIDE 26
SLIDE 27
SLIDE 28
- 4. Copying List using Assignment
- perator
SLIDE 29
SLIDE 31
The outermost container is duplicated, but the copy is filled with references to the same items held by the original container.
SLIDE 32
SLIDE 34
Duplicates do not share references of embedded objects.
SLIDE 35
SLIDE 36 Why is it important to learn object internals?
SLIDE 37
* operator copies the memory references
SLIDE 38
SLIDE 39 Summary
- object internals
- memory address use cases
- type of objects (mutable,
immutable)
- difference between is vs ==
- perator
- optimizations
SLIDE 40