The id() method in Python returns the identity of the object, which is the unique ID of the specified object. Now, you might be wondering, what is this id() .
The id here is the memory address of the object, an integer, which ensures that the object is unique and constant during its life cycle. Two objects with non-overlapping lifetimes may have the same id() value.
id(object)
This object can be object, String, Number, List, etc.
In this example, we will use id() to get the unique id of the list object -
myList = ["john", "tom", "henry", "mark"] res = id(myList) print(res)
140571958913920
When we run it again, the id will be different:
140597372271552
In this example, we will use the id() method to get the unique id of the Tuple object -
myTuple = ("david", "steve", "alexa", "dwyer") res = id(myTuple) print(res)
140389997162960
When we run it again, the id will be different -
140674820137424
In this example, we will get the unique ID of the integer -
print(id(50)) print(id(100))
140184574995904 140184574997504
The above is the detailed content of Why does the result of id() not seem to be unique in Python?. For more information, please follow other related articles on the PHP Chinese website!