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 Machine Learning - Sebastian Raschka
Python String isprintable()
Python setattr()
Python timestamp to datetime and vice-versa
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python *args and **kwargs
Python String join()
Python eval()
Python Set symmetric_difference_update()
Python Set issubset()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Set pop()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Display Powers of 2 Using Anonymous Function
Python pass statement
Python Program to Generate a Random Number
Python Program to Count the Number of Digits Present In a Number
Python String lstrip()
Python Dictionary keys()
Python isinstance()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Global, Local and Nonlocal variables
Python String casefold()
Python Program to Create a Countdown Timer
Deep Learning with Python - Francois Cholletf
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Sort a Dictionary by Value
Python next()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Iterate Through Two Lists in Parallel
Python Program to Check if a Number is Odd or Even
Python sorted()