Find the size of a list - Python Last Updated : 10 Oct, 2022 Comments Improve Suggest changes Like Article Like Report 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. 1.Using getsizeof() function: The getsizeof() function belongs to the python's sys module. It has been implemented in the below example. Example 1: Python3 import sys # sample lists list1 = [1, 2, 3, 5] list2 = ["GeeksForGeeks", "Data Structure", "Algorithms"] list3 = [1, "Geeks", 2, "For", 3, "Geeks"] # print the sizes of sample lists print("Size of list1: " + str(sys.getsizeof(list1)) + "bytes") print("Size of list2: " + str(sys.getsizeof(list2)) + "bytes") print("Size of list3: " + str(sys.getsizeof(list3)) + "bytes") OutputSize of list1: 104bytes Size of list2: 96bytes Size of list3: 120bytes Note:The 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. 1.Using inbuilt __sizeof__() method: 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. Example 2: Python3 # sample lists list1 = [1, 2, 3, 5] list2 = ["GeeksForGeeks", "Data Structure", "Algorithms"] list3 = [1, "Geeks", 2, "For", 3, "Geeks"] # print the sizes of the sample lists print("Size of list1: " + str(list1.__sizeof__()) + "bytes") print("Size of list2: " + str(list2.__sizeof__()) + "bytes") print("Size of list3: " + str(list3.__sizeof__()) + "bytes") OutputSize of list1: 72bytes Size of list2: 64bytes Size of list3: 88bytes Comment More infoAdvertise with us Next Article Find the size of a list - Python R RajuKumar19 Follow Improve Article Tags : Python Python Programs Python list-programs Practice Tags : python Similar Reads Find the size of a Set in Python A Set is an unordered collection data type that is iterable, mutable, and has no duplicate elements. Pythonâs set class represents the mathematical notion of a set. The size of a set means the amount of memory (in bytes) occupied by a set object. In this article, we will learn various ways to get th 2 min read Find the Size of a Tuple in Python There are several ways to find the "size" of a tuple, depending on whether we are interested in the number of elements or the memory size it occupies. For Example: if we have a tuple like tup = (10, 20, 30, 40, 50), calling len(tup) will return 5, since there are five elements in the tuple.Using len 3 min read Find the length of a set in Python We are given a set and our task is to find its length. For example, if we have a = {1, 2, 3, 4, 5}, the length of the set should be 5.Using len()len() function in Python returns the number of elements in a set. It provides total count of unique items present in set.Pythona = {1, 2, 3, 4, 5} # Return 2 min read Python - Create List of Size n Creating a list of size n in Python can be done in several ways. The easiest and most efficient way to create a list of size n is by multiplying a list. This method works well if we want to fill the list with a default value, like 0 or None.Python# Size of the list n = 5 # Creating a list of size n 2 min read Python | Find number of lists in a tuple Given a tuple of lists, the task is to find number of lists in a tuple. This is a very basic problem but can be useful while making some utility application. Method #1: Using len Python3 # Python code to find number of list in a tuple # Initial list Input1 = ([1, 2, 3, 4], [5, 6, 7, 8]) Input2 = ([1 4 min read Like