0

Why are these the same address? Is it because the integer 4 is actually an Object in Python and therefore a variable which points to this same integer will have the memory address of this particular integer Object?

hex(id(4)) #will return '0x10b684900' 

x = 4

hex(id(x)) #will return '0x10b684900'

2 Answers 2

1

In python everything is an object! Maybe this answer will help you understand!

Python 3.6: Memory address of a value vs Memory address of a variable

Sign up to request clarification or add additional context in comments.

Comments

1

Please read the answer here: https://stackoverflow.com/a/15172182/8733066

The python interpreter doesn't need tho save the value 4 multiple times because int is immutable. So all variables with the value four point to the same memory location.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.