Checkpoint 9.4.1.
- 910
- That entry is at index 4.
- 3.14
- Yes, 3.14 is at index 5 since we start counting at 0.
- False
- False is at index 6.
What is printed by the following statements?
a_list = [3, 67, "cat", "dog", 910, 3.14, False]
print(a_list[5])
[]
— not to be confused with an empty list). The expression inside the brackets specifies the index. Remember that the indices start at 0. Any integer expression can be used as an index, and as with strings, negative index values will locate items from the right instead of from the left.a_list = [3, 67, "cat", "dog", 910, 3.14, False]
print(a_list[5])
a_list = [3, 67, "cat", "dog", 910, 3.14, False]
print(a_list[2].upper())
upper
to a_list[2]
, not the whole list. a_list[2]
is the string "cat"
so the upper method is legal"cat"
is upper cased to become "CAT"
.