0

I just opened the python ide and entered the below code. I just want to know how it is working in background because I opened IDE freshely?Here, I am aware of id() function, but how come the "1" is given some id inside python because neither it is not a variable nor I used in my IDE anywhere since I opened the IDE freshly

>>> id(1)
20643664
>>> id(2)
20643652
>>> 
user3148499
  • 7
  • 1
  • 4

1 Answers1

1

It gives the address of the object in memory during which the object is alive.

Source: https://docs.python.org/2/library/functions.html#id

Gerges
  • 6,269
  • 2
  • 22
  • 44
  • Thanks for the reply. I am aware of id() concept but I want to know how come a numerical vaule that is being used directly first time is having an id assigned to@Gerges – user3148499 Jun 21 '17 at 05:31
  • Well I suppose it has to with python internals. Any value you use must be stored somewhere in memory, and I think python stores all its variables in a hash table. So basically if you try `id(1)` and then `foo = 1; id(foo)`, you will get the same address and vice versa. – Gerges Jun 21 '17 at 05:46