Sunday 7 November 2021

Python: id(): return identity of the object

‘id()’ method return an unique identifier to the object.

 

id_function_demo_1.py

class Employee:  
    def __init__(self, id, name):  
        self.id = id  
        self.name = name  

emp1 = Employee(1,"Ram")
emp2 = Employee(1,"Ram")
emp3 = Employee(1,"Ram")      

print('id(emp1) -> ' + str(id(emp1)))
print('id(emp2) -> ' + str(id(emp2)))
print('id(emp3) -> ' + str(id(emp3)))

 

Output

id(emp1) -> 4309679840
id(emp2) -> 4309679648
id(emp3) -> 4309679504

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment