chevron_left
Cookbooks
Accessing an item in a listAdding items to a listChecking if a list is emptyChecking whether a value is in a listConcatenating two listsCopying a list in PythonDifference between append and extend methodsDifference between sort and sortedFinding the index of an element in a listFinding the length of a listIterating from index oneLooping through listsModifying listsPrinting a list in reverse orderRemoving items from a listSorting a listUsing enumerate and zip at the same time
0
0
0
new
Finding the length of a list in Python
Programming
chevron_rightPython
chevron_rightOperations
chevron_rightList Operations
chevron_rightCookbooks
schedule Jul 1, 2022
Last updated Python
Tags tocTable of Contents
expand_more We can find the length of a list (i.e. number of elements) by using the len()
method.
To find the length of list cars
:
cars = ['mercedes', 'range rover', 'toyota', 'renault']len(cars)
4
An embedded list will only count as one item:
dessert = ['cake', 'cookie', 'cupcake', ['pudding','tea']]len(dessert)
4
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
0
0
0
Enjoy our search