Menu Close

Python id() Function

In this tutorial, you will all about the Python id() function to find the unique id for the specified objects.
id function in Python is the best built-in function to get the id of a specified object( string, list, number, set, etc).
In the previous tutorial, we have seen the Python hex function to convert number to hexadecimal.

Python id() function

Python id() function in python is a built-in function that is used to find the unique object of any specified object.
All the objects it owns unique objects. In id is assigned when the object is created. The id of the object will be different each time you run the program.

Syntax

The syntax of python id() function is:-

id(object)

Parameter

The python id() function take one parameter, that is python object.

Return Value

Return value of id function in python is id of the object.

Python id() Example

Here we will take some examples to understand id function.

Example:

#id of the number
num = 120
print(id(num))

#id of the string
mystring = 'Programming Funda'
print(id(mystring))


#id of the set
my_set = {1, 2, 3, 4}
print(id(my_set))

#id of the tuple
my_tuple = ('Python', 'Java', 'JavaScript')
print(id(my_tuple))

#id of the list
my_list = [1, 2, 3, 4, 5, 6]
print(id(my_list))

Output

140706168055168
2254935321136
2254936994528
2254936646464
2254936963328

Conclusion

In this tutorial, you have learned the python id() function to find the id of the object along with an example.
If this article helps you, please share and keep visiting for further python built-in functions tutorials.

Python built-in functions

For more information:- Click Here

Python hex() Function
Python input() Function

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *