Talking about Objects in Python

“Object-oriented programming offers a sustainable way to write spaghetti code. It lets you accrete programs as a series of patches.” ― Paul Graham


What is an id and type?

str1 id is: 140503324721984
str1 id is: 140503324721984 and str3 id is: 140503324721984
str2 id is: 140503324552528
num1 id is: 10105088 and num3 id is: 10105088
num2 id is: 140503325106096 and num2 id is: 140503325106096
Type of str1: <class 'str'>
Type of num1: <class 'int'>

Mutable Objects

['cow', 'pig', 'chiken']
['bull', 'pig', 'rooster']

Immutable Objects

Traceback (most recent call last):
File "/home/vagrant/holberton_projects/holbertonschool-higher_level_programming/0x09-python-everything_is_object/", line 4, in <module>
tuple1[0] = 4
TypeError: 'tuple' object does not support item assignment

Storage management

The layout of a Python object in the heap. Each box is allocated in a different memory region, and arrows between boxes represent pointers.

How are arguments passed to functions and what does that imply for mutable and immutable objects?

[1, 2, 3, 4]

Preallocation in Python

Materials Engineer and Software Developer. First that a professional i am humanistic person. I accepts and overcomes every single challenge.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store