Table of Contents
The id() function returns identity (unique integer) of an object.
The syntax of id()
is:
id(object)
1. id() Parameters
id()
function takes a single parameter object.
2. Return Value from id()
id()
function returns the identity of the object. This is an integer that is unique for the given object and remains constant during its lifetime.
3. Example 1: How id() works?
class Foo: b = 5 dummyFoo = Foo() print('id of dummyFoo =',id(dummyFoo))
Output
id of dummyFoo = 140343867415240
4. More Examples on id()
print('id of 5 =',id(5)) a = 5 print('id of a =',id(a)) b = a print('id of b =',id(b)) c = 5.0 print('id of c =',id(c))
Output
id of 5 = 140472391630016 id of a = 140472391630016 id of b = 140472391630016 id of c = 140472372786520
It’s important to note that everything in Python is an object, even numbers, and Classes.
Hence, integer 5
has a unique id. The id of the integer 5
remains constant during the lifetime. Similar is the case for float 5.5
and other objects.
Related posts:
Python Program to Safely Create a Nested Directory
Python while Loop
Python String count()
Python Global Keyword
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Operator Overloading
Python complex()
Python Program to Access Index of a List Using for Loop
Python String islower()
Python float()
Python String lower()
Python Program to Find Numbers Divisible by Another Number
Python String strip()
Python Statement, Indentation and Comments
Python List remove()
Python datetime
Python vars()
Python dict()
Machine Learning with Python for everyone - Mark E.Fenner
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Find Hash of File
Python setattr()
Python String capitalize()
Node.js vs Python for Backend Development
Python Program to Get Line Count of a File
Python Program to Find HCF or GCD
Python Program to Extract Extension From the File Name
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Add Two Numbers
Python Program to Merge Two Dictionaries
Python String join()
Python Program to Convert Decimal to Binary Using Recursion