id() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

id()

In Python 3, what is this id() function returning?

25th Sep 2018, 4:35 AM
Gordon
Gordon - avatar
4 Answers
+ 3
id() gives you memory address of the variable.in python when you create something variable , function,object or whatever everything stores in memory block.each of variable,function has different memory block which can acess using using it's memory address. x=5 print(id(x)) gives you memory address of the x variable.
25th Sep 2018, 4:40 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
it gives an specific id to an object for identification.
25th Sep 2018, 9:41 AM
Kenny Wong
Kenny Wong - avatar
0
After experimenting, my observation is that id(n+1) - id(n) = 16 https://code.sololearn.com/c0hIItv4yn4H/?ref=app
25th Sep 2018, 4:38 AM
Gordon
Gordon - avatar
0
When I redefine A from 3 to 4 its id increases by 16 So I'm not so sure about "specific id" or "memory address" Looks like it's more about the value itself. https://code.sololearn.com/c0hIItv4yn4H/?ref=app
25th Sep 2018, 5:55 PM
Gordon
Gordon - avatar