Wednesday, July 16, 2014

How to count the number of items in a list

Code
mylist = ['apples','bananas', 'oranges']                               #1
len(mylist)                                                            #2

How this works - Line by Line

mylist = ['apples','bananas', 'oranges']                               #1
 
Defining mylist as a example list of items


len(mylist)                                                            #2

This line returns the count of items in the list.  In this case, the result would be 3.

No comments:

Post a Comment