Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

In this tutorial, you will learn about the Python id() function with the help of examples.

The id() function returns a unique id for the given object. All objects in Python have their own unique id and which is an integer and constant for the object during its lifetime.

The id is assigned to the object when it is created.

Two objects with non-overlapping lifetimes may have the same id() value.

The id is the object’s memory address and will be different for each time you run the program. (except for some object that has a constant unique id, like integers from -5 to 256)

The syntax of the id() looks like this:


where argument may be Any object, String, Number, List, Class, etc.

Below are the examples.



# First run
# output: 139858837729584
# Second run
# output: 140519613063280

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.