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'
Flame
  • 6,663
  • 3
  • 33
  • 53

2 Answers2

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

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.

bb1950328
  • 1,403
  • 11
  • 18