How to use id() In Python
We can get an address using the id() function. id() function gives the address of the particular object.
Syntax:
id(object)
where the object is the data variables.
Example: Python program to get the address of different objects
Python3
# get id of list a = [ 1 , 2 , 3 , 4 , 5 ] print ( id (a)) # get id of a variable a = 12 print ( id (a)) # get id of tuple a = ( 1 , 2 , 3 , 4 , 5 ) print ( id (a)) # get id of a dictionary a = { 'a' : 1 , 'b' : 2 } print ( id (a)) |
Output:
140234866534752
94264748411744
140234904267376
140234866093264
How to get the memory address of an object in Python
In Python, everything is an object, from variables to lists and dictionaries everything is treated as objects. In this article, we are going to get the memory address of an object in Python.
Contact Us