Object Identifier(id of variables)


Python provides the guaranteed that no two objects will have the same identifier. The built-in id() function, is used to identify the object identifier

=====================================================================
#example 1

print("#example 1")
print("=================")

a = 50
print("a value is:",a)
b = a
print("b value is:",b)
print("=================")

print(id(a))
print("id of a value is:",id(a))
print(id(b))
print("id of b value is:",id(b))
print("=================")

print("# Reassigned variable a") 
a = 500
print("a value is:",a)
print("id of a value is:",id(a))


OUTPUT:

#example 1
=================
a value is: 50
b value is: 50
=================
3080095729424
id of a value is: 3080095729424
3080095729424
id of b value is: 3080095729424
=================
# Reassigned variable a
a value is: 500
id of a value is: 3080131783408


Note:
We assigned the b = a, a and b both point to the same object. When we checked by the id() function it returned the same number. We reassign a to 500; then it referred to the new object identifier.

=====================================================================
#example 2

print("#example 2")
print("=================")
a=[10,20,30]
b=[10,20,30]
print(id(a))
print(id(b))



OUTPUT:

#example 2
=================
3080096548224
3080133278912


Note:
variables values are same,
but id's of variables are not same