Getting a List’s Length with len()

Mr #1738 - Aug 4 '23 - - Dev Community

The len() function will return the number of values that are in a list value passed to it, just like it can count the number of characters in a string value.
Enter the following into the interactive shell to see the output:

>>> spam = ['cat', 'dog', 'moose']
>>> len(spam)
3
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .