In Python, a list is a collection data type that can store elements in an ordered manner and can also have duplicate elements. The size of a list means the amount of memory (in bytes) occupied by a list object. In this article, we will learn various ways to get the size of a python list.
getsizeof() function belongs to the python’s sys module. It has been implemented in the below example.
Size of list1: 96bytes Size of list1: 88bytes Size of list1: 112bytes
sys.getsizeof() function includes the marginal space usage, which includes the garbage collection overhead for the object. Meaning it returns the total space occupied by the object in addition to the garbage collection overhead for the spaces being used.
Python also has an inbuilt __sizeof__() method to determine the space allocation of an object without any additional garbage value. It has been implemented in the below example.
Size of list1: 72bytes Size of list1: 64bytes Size of list1: 88bytes
- Find size of a list in Python
- Python | Subgroups of i'th index size in list
- Python | Size and element exponentiation of list
- Break a list into chunks of size N in Python
- Python | Size Range Combinations in list
- Python - List of N size increasing lists
- Python | Categorize the given list by string size
- Python - Fill Strings for size K in Tuple List
- Python | Combinations of elements till size N in list
- Python | Sort list of lists by the size of sublists
- Python | Increase list size by padding each element by N
- Find the size of a Set in Python
- Python | Find maximum length sub-list in a nested list
- Find the size of a Tuple in Python
- How to find size of an object in Python?
- Find the size of a Dictionary in Python
- Python Counter to find the size of largest subset of anagram words
- Python | Find all triplets in a list with given sum
- Python | Find Min/Max in heterogeneous list
- Find Median of List in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.