The function id () in Python
The built-in function id () in Python returns a single integer value that identifies an object.
- All objects in Python have their own unique id .
- Id is assigned to the object when it is created.
Id () function syntax
id(object)
Parameters of the id function ()
Id () has a unique parameter:
object
: is an object, number, string, list, class . that must return id.
Value returned from id ()
The id () function returns the identity of the object. This is a unique integer for the injected object and remains constant throughout its life cycle.
For example
1. The way id () works in Python
class Demo: b = 5 qtmDemo = Demo() print('id của qtmDemo =',id(qtmDemo))
Run the program, the result will be in the form:
id của qtmDemo = 139870602688104
2. Some other examples:
print('id của 5 =',id(5)) a = 5 print('id của a =',id(a)) b = a print('id của b =',id(b)) c = 5.0 print('id của c =',id(c))
Result:
id của 5 = 10914496 id của a = 10914496 id của b = 10914496 id của c = 139870675422424
See also: Built-in Python functions
5 ★ | 1 Vote
You should read it
May be interested
- The ord () function in Pythonthe built-in ord () function in python returns an integer representing the unicode code of the specified character.
- The input () function in Pythonpython's built-in input () function allows users to enter data, convert it into a string, and return the entered content.
- Type () function in Pythonthe built-in function type () in python returns the type of object passed as parameter.
- Print () function in Pythonthe print () function in python works to display the screen magic when the program executes.
- Sum () function in Pythonthe built-in function sum () in python returns the sum of all numbers in iterable.
- __Import __ () function in Python__import __ () is an advanced function called by the import statement in python