How to find size of an object in Python? Last Updated : 17 Jul, 2023 Comments Improve Suggest changes Like Article Like Report 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 to the object is accounted for, not the memory consumption of objects it refers to. Examples: Input: # Any Integer Valuesys.getsizeof(4) Expected Output: 4 bytes (Size of integer is 4bytes)Actual Output: 28 bytesHere's how we can interpret the actual output. Have a look at the table below: Type of Object Actual Size Notes int 28 NA str 49 +1 per additional character (49+total length of characters) tuple 40 (Empty Tuple) +8 per additional item in a tuple ( 40 + 8*total length of items ) list 56 (Empty List) +8 per additional item in a list ( 56 + 8*total length of items ) set 216 0-4 take the size of 216. 5-19 take size 728. 20th will take 2264 and so on... dict 232 0-5 takes a size of 232. 6-10 size will be 360. 11th will take 640 and so on... func def 136 No attributes and default arguments Example: Python3 import sys # Getting size using getsizeof() method and lately # printing the same. a = sys.getsizeof(12) print(a) b = sys.getsizeof('geeks') print(b) c = sys.getsizeof(('g', 'e', 'e', 'k', 's')) print(c) d = sys.getsizeof(['g', 'e', 'e', 'k', 's']) print(d) e = sys.getsizeof({1, 2, 3, 4}) print(e) f = sys.getsizeof({1: 'a', 2: 'b', 3: 'c', 4: 'd'}) print(f) Output: Comment More infoAdvertise with us Next Article How to find size of an object in Python? K kunalkumbhar19 Follow Improve Article Tags : Python Write From Home 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 Length of a list in Python The length of a list means the number of elements it contains. In-Built len() function can be used to find the length of an object by passing the object within the parentheses. Here is the Python example to find the length of a list using len().Pythona1 = [10, 50, 30, 40] n = len(a1) print("Size of 2 min read How to get file size in Python? We can follow different approaches to get the file size in Python. It's important to get the file size in Python to monitor file size or in case of ordering files in the directory according to file size. Method 1: Using getsize function of os.path module This function takes a file path as an argume 3 min read How to check file size in Python? Prerequisites: os pathlib Given a file, the task here is to generate a Python Script to print its size. This article explains 2 methods to do so. ApproachImport moduleGet file sizeFile in use Name: Data.csv Size: 226 bytes Method1: Using pathlib Path().stat().st_size() function of pathlib module get 1 min read 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. Method 1: Using id() We can get an address using the id() function. id() function gives the address of the pa 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 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 How to find the current capacity of a list - Python List in Python is mainly implementation of dynamic sized arrays (like ArrayList in Java or vector in C++). Capacity of a list means number of elements a list can store at a specific time. When we append an element to a list it will store the element if its size is less than capacity and if current c 3 min read How to find width and height of an image using Python? Finding the width and height of an image in Python means reading the image and determining its dimensions in pixels. For example an image might have a height of 135 pixels and a width of 600 pixels. Letâs explore some common methods to find an imageâs width and height.1. Using OpenCV (cv2)OpenCV is 2 min read Measure Size of an Object Using Python OpenCV In this article, we will learn about how to measure the size of an object using OpenCV which is implemented in Python. It is implemented by finding the contours around it. This can be done by first loading an image of an object, converting it to grayscale, and applying a threshold to separate the ob 3 min read Like