Python id() function

(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!

The id() function returns a unique numeric identifier associated with the object.

In standard Python (i.e CPython) the identifier represents the memory address of the object. Although, this may vary in other implementation.

The unique identifier spring into existing when you define an object and will not change until the program is running. We can use this identifier to determine whether two objects are same or not.

The syntax() of id() function is as follows:

Here is an example:

Initially, variables  a and b references two distinct objects. As a result, id() call returns two unique identifiers. Next, we assign the object b to a. Now, a and b references the same object (5). Thus, the next id()  call returns the same identifier.

Other Tutorials (Sponsors)

This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

Leave a Reply

Your email address will not be published. Required fields are marked *