Python id() function
Python id() function
The id() function in Python returns an id for the specified object where all the objects in has its own unique id.
Syntax
id(object)
Parameter
object: This parameter represents any object, String, Number, List, Class etc.
Return
This function returns the “identity” of an object.
Example 1
# Python program explaining # the id() function str1 = ('Monday', 'Tuesday', 'Wednesday') val = id(str1) print(val)
Output
140493944320648
Example 2
# Python program explaining # the id() function str1 = "obj" print(id(str1)) str2 = "obj" print(id(str2)) # It will return True print("Both strings are equal ? ",id(str1) == id(str2)) # Use in Lists val = ["Reema", "Rahul", "Varun","Sita"] print(id(val[1])) print(id(val[2])) # It returns false print(id(val[1])==id(val[2]))
Output
140004107852744 140004107852744 Both strings are equal ? True 140004088008976 140004088010320 False