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 Compute all the Permutation of the String
Python Type Conversion and Type Casting
Python Dictionary values()
Python String expandtabs()
Python Program to Create Pyramid Patterns
Python delattr()
Python Program to Convert Kilometers to Miles
Python sleep()
Python Namespace and Scope
Python Function Arguments
Python bool()
Python Program to Remove Duplicate Element From a List
Python String maketrans()
Python List extend()
Python bin()
Python Program to Convert Two Lists Into a Dictionary
Python Anonymous / Lambda Function
Python Object Oriented Programming
Python Program to Get the Last Element of the List
Python Program to Generate a Random Number
Python String rsplit()
Python String isprintable()
Python Program to Concatenate Two Lists
Python Program to Iterate Over Dictionaries Using for Loop
Python List copy()
Python Strings
Python enumerate()
Python Package
Python Program to Capitalize the First Character of a String
Python map()
Python Data Structures and Algorithms - Benjamin Baka
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...