How Can We Help?
While working with lists in Python, it’s a common task often requested during our development of an application to get the list size or length.
How to find the length of a list in Python? To find the size of a tuple in Python, We use the len() function in Python. The in-built length function is used to find the length of a list. It’s calculating the size of a list; It takes one parameter, which is the list in our case, and returns a total length of a list by counting the list’s number of elements.
Python List Length Syntax:
len(list_variable_name)
Input Parameters:
- list_variable_name: the list name which needs to get the length of the element inside.
Python List Length Example
alphabet=['a','b','c','d','e']
# length of list or size of a list
print('length of list:',len(alphabet))
Output:
length of list: 5
In the above example, the list variable ‘alphabet’ has five values, i.e., its length is 5, which we got by len(alphabet), so the output is “5”.
In Python, the len() function is also used to get the size of a tuple like a list. Check this article for how to find the length of a tuple in Python; to see how by example.
In this tutorial, you have learned how to get the length or size of a list in Python.
Hopefully, it was clear and concise.
If you have a inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback as well.
Similar Python list length Function:
- min(list): It returns a minimum value of a list.
- max(list): It returns a maximum value of a list.
- type(list): It returns the list type if a passed variable is a list.
- list(seq): It converts a sequence/string into a list.
- del(list): It deletes the whole list, individual list elements, or all elements of a list.
Related Articles
Python List – Mastering By Practical Examples (Comprehensive Guide)