2

I presumed id() of immutable data types in python should be the same if the same value be used

But this fails if i store decimal and hex version of same integer :

In [1]: a = 0x1234                                                                                                                                                                                         

In [2]: b = 4660                                                                                                                                                                                           

In [3]: a == b                                                                                                                                                                                             
Out[3]: True

In [4]: id(a) == id(b)                                                                                                                                                                                     
Out[4]: False

In [5]: id(a)                                                                                                                                                                                              
Out[5]: 140579138155600

In [6]: id(b)                                                                                                                                                                                              
Out[6]: 140579138154736

Why?

Ariyan
  • 14,760
  • 31
  • 112
  • 175

1 Answers1

4

It's not about conversion, Python interpreter creates object every time you assign a big integer so those have different objects. numbers between -1 to 255 are created when interpreter starts and they have same id in all program.

Aliakbar Saleh
  • 649
  • 3
  • 10