Python Tutorial Python Advanced Python References Python Libraries

Python id() Function



The Python id() function returns a unique id of the specified object. The id is the memory address of the object and it changes every time the program is executed. The id of an object is unique and constant during it's lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

Syntax

id(object)

Parameters

object Required. Specify object like string, number, list and class etc.

Example:

In the example below, the id() function returns the unique id of list called MyList and it's elements. These ids gets changed every time the program is executed.

MyList = [10, 'Python']

print(id(MyList))

print(id(MyList[0]))
print(id(MyList[1]))

The output of the above code will be:

140238883095872
140238884571728
140238883968112

❮ Python Built-in Functions

5