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

What is the difference between the address value from instance and the address value from id(instance) in python?

class T:
    pass


t = T()

print(t) # <__main__.T object at 0x100651460>
print(id(t)) # 4301591648

What is the difference between 0x100651460 and 4301591648 in the code above? id(t) is to print the address value of the object as everyone knows. However, <main.T object at 0x100651460> also implies that 0x100651460 is the address value of the object. Which one is the real address value?

>Solution :

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

They are the same number. There is no difference in value, the only difference is that the first one is represented in hexadecimal, and the second one is represented in decimal.

>>> hex(4301591648)
'0x100651460'
>>> 0x100651460 == 4301591648
True

The prefix 0x is commonly used to indicate a hexadecimal representation.

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