Checkpoint 10.3.1.
- 4
- len returns the actual number of items in the list, not the maximum index value.
- 5
- Yes, there are 5 items in this list.
What is printed by the following statements?
alist = [3, 67, "cat", 3.14, False]
print(len(alist))
len
returns the length of a list (the number of items in the list). However, since lists can have items which are themselves lists, it important to note that len
only returns the top-most length. In other words, sublists are considered to be a single item when counting the length of the list.alist = [3, 67, "cat", 3.14, False]
print(len(alist))
alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False]
print(len(alist))