Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does ID function create a new object?

I have 2 variables (links) a and b that are pointing to the same object, and, of course

a is b #true

But when im asking about memory addr for the same object that this links pointing to

id(a) is id(b) #false

Does that mean that id is creating a new object ? How long will this object last ? What type will it be? What’s going on?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

>>> a is b
True 

They are the same object…

>>> id(a) == id(b)
True 

They have the same id…

>>> id(a) is id(b)
False 

…but the integers representing their ids are not the same object.

That’s because in Python ints are objects too.


I would suggest you to read this, this and this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading