Find and Print Address of Variable using id()

We can get an address using id() function, id() function gives the address of the particular object.

Syntax: id(object)

where, object is the data variables.

Here we are going to find the address of the list, variable, tuple and dictionary.

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

Python Program to Find and Print Address of Variable

In this article, we are going to see how to find and print the address of the Python variable. 

It can be done in these ways:

  • Using id() function
  • Using addressof() function
  • Using hex() function

Similar Reads

Method 1: Find and Print Address of Variable using id()

We can get an address using id() function, id() function gives the address of the particular object....

Method 2: Find and Print Address of Variable using addressof()

...

Method 3: Find and Print Address of Variable using hex()

we can also get memory addresses using these functions, ctypes is a foreign function library for Python. It provides C-compatible data types and allows calling functions in DLLs or shared libraries....