English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The id() function returns the identity of the object (unique integer).
The syntax of id() is:
id(object)
The id() function takes a single parameterobject.
The id() function returns the identity of an object. It is an integer, unique for the given object, and remains unchanged throughout its lifetime.
class Foo: b = 5 dummyFoo = Foo() print('dummyFoo's id =', id(dummyFoo))
When you run the program, the output will be similar to:
dummyFoo's id = 140343867415240
print('5The id =', id(5)) a = 5 print('a's id =', id(a)) b = a print('b's id =', id(b)) c = 5.0 print('c's id =', id(c))
When you run the program, the output will be similar to:
5The id = 1453124160 a's id = 1453124160 b's id = 1453124160 c's id = 42380816
It is important to note that all content in Python is an object, even numbers and classes.
Therefore, integer5Has a unique ID. Integer5The id remains unchanged during the lifetime of the float.5.5And it is the same with other objects.