Thursday, March 19, 2015

id() - Python Tutorial


The id() built-in function returns a unique integer which is the identifier of an object in the memory. We can use id() to check if two variables are using the same object.


Examples Of The Built-In Python Function Id()


>>> a = 2
>>> a
2
>>> id(a)
4297366528
>>> b = 3
>>> b
3
>>> id(b)
4297366560
>>> id(a)==id(b)
False
>>> c = 2
>>> c
2
>>> id(c)
4297366528
>>> id(a)==id(c)
True
>>> d = "string"
>>> d
'string'
>>> id(d)
4328793624
>>> e = "String"
>>> e
'String'
>>> id(d)==id(e)
False

 


 



No comments:

Post a Comment