Returns unique identity ( integer or long integer ) of the python object.
identity is assigned when object is created.
It is the address of the object's memory
id changes each time the program is run except some objects for which id is fixed.

Using integer

print(id(my_int)) # 10969856 
Using list
print(id(my_list)) #139787163392648

Fixed id

These ids will remain same even after re-run of the program.
print(id(my_int)) # 10968608
print(id(my_int)) # 10976960

Mutable and immutable object and id()

We can see for mutable objects by changing the element the ID will not change , whereas for immutable objects id will change.

More on Mutable & Immutable objects

List is a mutable object but tuple is a immutable object. Check how the identities are changing after adding elements.

Using tuple
print(id(my_tuple)) # 139787173397704
my_tuple +=(9,8)
print(id(my_tuple)) # 139787174601112
print(my_tuple)     #(5, 7, 5, 4, 3, 5, 9, 8)
Using List
print(id(my_list))  # 139787163608584
my_list +=[9,8]
print(id(my_list))  # 139787163608584
print(my_list)      # [5, 7, 5, 4, 3, 5, 9, 8]
Two non-overlapping lifetime objects may have the same identity or id() vlaue.

variables Iterator any() is() & not is()

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 All rights reserved worldwide Privacy Policy Disclaimer