Test Yourself
- What is []?
- How would you assign the value 'hello' as the third value in a list stored in a variable named spam? (Assume spam contains [2, 4, 6, 8, 10].)
For the following three questions, let’s say spam contains the list ['a', 'b', 'c', 'd'].
- What does spam[int(int('3' * 2) // 11)] evaluate to?
- What does spam[-1] evaluate to?
- What does spam[:2] evaluate to?
For the following three questions, let’s say bacon contains the list [3.14, 'cat', 11, 'cat', True].
- What does bacon.index('cat') evaluate to?
- What does bacon.append(99) make the list value in bacon look like?
- What does bacon.remove('cat') make the list value in bacon look like?
- What are the operators for list concatenation and list replication?
- What is the difference between the append() and insert() list methods?
- What are two ways to remove values from a list?
- Name a few ways that list values are similar to string values.
- What is the difference between lists and tuples?
- How do you type the tuple value that has just the integer value 42 in it?
- How can you get the tuple form of a list value? How can you get the list form of a tuple value?
- Variables that “contain” list values don’t actually contain lists directly. What do they contain instead?
- What is the difference between copy.copy() and copy.deepcopy()?