Python: everything is object

Monty python. Source
Method: split string
Object’s types
Mutable object (list)
Inmmutable object (integer)
  • We can see in this example, the object’s reference has not been tranfered but a copy of it. This happens with immutable objects.
  • On the other hand, in the next image, we can see how the reference has been transfered, therefor, an element has been added to the object.
>>> list_1 = [1, 2, 3]
>>> list_2 = [1, 2, 3]
>>> list_1 == list_2
True # list_1 and list_2 have the same value
>>> L1 is L2
False # list_1 and list_2 do not refer to the same object!
>>> list_1 = [1, 2, 3]
>>> list_2 = list_1 # list_2 now refers to the same object as list_2
>>> list_1 == list_2
>>> list_1 is list_2
>>> list_1.append(4)
>>> print(list_2)
[1, 2, 3, 4]

Exceptions with Immutable Objects

  1. some strings
  2. Integers between -5 and 256 (inclusive)
  3. empty immutable containers (e.g., tuples)
  1. Since programmers use these objects frequently, interning existing objects saves memory.
  2. Since immutable objects like tuples and strings cannot be modified, there is no risk interning the same object. But tupples are something in between because eventhough they are immutable can contain mutable objects like lists, so at the end they can be modified.
#define NSMALLPOSINTS           257




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introducing the Stater Lydian Update — Mainnet Scheduled for 16.04.2021

Vim: delete sentences and paragraphs via Text Objects

WeMeta Launches The World’s First Metaverse Analytics Engine


Event-driven architecture benefits & models | Apiumhub

CS371p Fall 2019: Xiang Gu

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
Atenea Castillo

Atenea Castillo

More from Medium

Fetching Data From API’s

Owasp Top Ten API Security

My experience with CKAD(certified Kubernetes Application Developer) exam