To find the size of a list in Python, the easiest way is to use the Python len() function. The len() function returns the length of the list and the number of elements in the list.
length_of_list = len(list_variable)
In Python, lists are a collection of objects which are unordered and mutable. When working with list, it can be useful to be able to easily calculate the length and size of a list.
To get the length of a list in Python, we can use the Python len() function.
Let’s say we have the following list in our Python code.
list_var = ["This","is","a","list"]
To get the length of our list variable, we can call the len() function.
list_var = ["This","is","a","list"] length_of_list = len(list_var) print(length_of_list) #Output: 4
Using the Python len() Function to Find the Length of Other Objects in Python
The Python len() function is one of the most used functions in the Python programming language.
For example, if I wanted to find the length of the following string variable, I’d just pass it to the len() function.
print(len("This is a string variable.")) #Output: 26
Hopefully this article has been useful for you to learn how to use the Python len() function to find the size of a list.