How to get the memory address of an object in Python Last Updated : 23 Aug, 2021 Comments Improve Suggest changes Like Article Like Report 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. Method 1: Using id() 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 Method 2: Using c_int, addressof modules ctypes is a foreign function library for Python. It provides C compatible data types and allows calling functions in DLLs or shared libraries. Syntax: addressof(c_int(object)) where object is the data variables Example: Python program to get the memory address of a variable Python3 # import addressof and c_int modules # from ctypes module from ctypes import c_int, addressof # get memory address of variable a = 44 print(addressof(c_int(a))) Output: 140234866278064 It is also possible to get memory addresses in hexadecimal format. Here we will call the hex(address) function, to convert the memory address to hexadecimal representation. Syntax: hex(id(object)) where, hex() is the memory hexadecimal representation to the addressid is used to get the memory of the objectobject is the data Example: Python program to get the memory address in hexadecimal representation. Python3 # get id of list in hexadecimal representation a = [1, 2, 3, 4, 5] print(hex(id(a))) # get id of a variable in hexadecimal # representation a = 12 print(hex(id(a))) # get id of tuple in hexadecimal # representation a = (1, 2, 3, 4, 5) print(hex(id(a))) # get id of a dictionary in hexadecimal # representation a = {'a': 1, 'b': 2} print(hex(id(a))) Output: 0x7fba9b0ae8c0 0x5572da858b60 0x7fba9f3c4a10 0x7fba9b05b8c0 Comment More infoAdvertise with us Next Article How to get the memory address of an object in Python sravankumar_171fa07058 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads How to Check the Type of an Object in Python In this article, we will explore the essential skill of determining the type of an object in Python. Before engaging in any operations on an object within the Python programming language, it is imperative to possess the knowledge of how to check its type. This fundamental task is encountered regular 4 min read How to find size of an object in Python? In python, the usage of sys.getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes. It takes at most two arguments i.e Object itself. Note: Only the memory consumption directly attributed t 2 min read How to get the address for an element in Python array? In this article we are going to discuss about getting the address of an particular element in the Python array. In python we can create the array using numpy. Numpy stands for numeric python used to create and process arrays. We have to import numpy module import numpy as np Syntax to create array: 3 min read Printing the Address of an Object of Class in C++ Prerequisite: Classes and Objects in C++ The location of an object in the memory is called its address. Addressing is a necessary part of C++, it enables us to use any element as a reference and maintains the uniqueness of all the elements whether it is any variable, object, or container. In this ar 3 min read How to Get a List of Class Attributes in Python? Getting a list of class attributes in Python means identifying all variables defined at the class level, excluding instance attributes and methods. For example, a class might have attributes like name, age and location. The output will be a list or dictionary showing these attribute names and their 3 min read How to get value from address in Python ? In this article, we will discuss how to get the value from the address in Python. First, we have to calculate the memory address of the variable or python object which can be done by using the id() function. Syntax: id(python_object) where, python_object is any python variable or data structure like 4 min read Find out how much memory is being used by an object in Python In this article, we are going to see how to find out how much memory is being used by an object in Python. For this, we will use sys.getsizeof() function can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object i 2 min read Unexpected Size of Python Objects in Memory In this article, we will discuss unexpected size of python objects in Memory. Python Objects include List, tuple, Dictionary, etc have different memory sizes and also each object will have a different memory address. Unexpected size means the memory size which we can not expect. But we can get the s 2 min read How to get the list of all initialized objects and function definitions alive in Python? In this article, we are going to get the list of all initialized objects and function definitions that are alive in Python, so we are getting all those initialized objects details by using gc module we can get the details. GC stands for garbage collector which is issued to manage the objects in the 2 min read How to Print Object Attributes in Python In Python, objects are the cornerstone of its object-oriented programming paradigm. An object is an instance of a class, and it encapsulates both data (attributes) and behaviors (methods). Understanding how to access and print the attributes of an object is fundamental for debugging, inspecting, and 2 min read Like