Python id() function

Published February 16, 2022

The Python id() method returns the unique identifiers of Python objects stored in memory. In Python, each object in memory can be referred to by a unique numeric value. These distinct numerical values distinguish these objects from the others.
When an object is passed as the Python id() function parameter, the object's identity is determined. The identity is an integer that remains constant in the sense that it cannot be altered or changed.

Syntax
The simple syntax of the id() function includes:

Id(object)

This function is assigned with only a single parameter to return the object's unique identity. The identity should be unique and should not change.

Example

integer = 5
float = 25.7
text = 'Hello'
print('ID of an Integer:', id(integer))
print('ID of float :', id(float))
print('ID of text :', id(text))

 

Output:

ID of an Integer: 9789120
ID of float : 140331424368912
ID of text : 140331423926640

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

267 Views