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 Find Armstrong Number in an Interval
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python String find()
Python Data Types
Python Program to Make a Flattened List from Nested List
Python Program to Create Pyramid Patterns
Python Program to Swap Two Variables
Python Program to Check If Two Strings are Anagram
Python Program to Get the Last Element of the List
Python any()
Python setattr()
Python Program to Count the Number of Digits Present In a Number
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Intelligent Projects Using Python - Santanu Pattanayak
Python locals()
Python input()
Python complex()
Python zip()
Python Program to Display Fibonacci Sequence Using Recursion
Python enumerate()
Python bool()
Python Shallow Copy and Deep Copy
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Machine Learning Eqution Reference - Sebastian Raschka
Python memoryview()
Python Program to Check Armstrong Number
Python Set remove()
Python Program to Differentiate Between del, remove, and pop on a List
Python String upper()
Python Program to Convert Kilometers to Miles
Python Program to Find ASCII Value of Character
Python Program to Print Output Without a Newline