In this tutorial, we will learn about python id() method and its uses with examples.
What is python id() method?
The id() method in python returns the unique identity number of an object. All the objects in python have a unique integer number.
These identity numbers are assigned to the object when created and remain constant for this object until the program’s execution is ended.
The syntax of id() is:
Python id() method Parameters
id() method only takes only one parameter as an argument.
- object – object name whose id to be returned.
Let’s check some examples of python id() methods.
Example 1: How to use the id() method in python?
An id will automatically assign to a variable whenever it’s declared.
Example 2: How to use id() method with python variable?
The output will be as follows:
In python, even classes and methods have their unique identity number.
Example 3: How to use id() method with python classes and methods?
Rules of id() method
- id() method will always return a unique integer number of given objects.
- Unique numbers will remain constant during its lifetime, once assing.