Test Yourself

  1. What is []?
  1. 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'].

  1. What does spam[int(int('3' * 2) // 11)] evaluate to?
  1. What does spam[-1] evaluate to?
  1. What does spam[:2] evaluate to?

For the following three questions, let’s say bacon contains the list [3.14, 'cat', 11, 'cat', True].

  1. What does bacon.index('cat') evaluate to?
  1. What does bacon.append(99) make the list value in bacon look like?
  1. What does bacon.remove('cat') make the list value in bacon look like?
  1. What are the operators for list concatenation and list replication?
  1. What is the difference between the append() and insert() list methods?
  1. What are two ways to remove values from a list?
  1. Name a few ways that list values are similar to string values.
  1. What is the difference between lists and tuples?
  1. How do you type the tuple value that has just the integer value 42 in it?
  1. How can you get the tuple form of a list value? How can you get the list form of a tuple value?
  1. Variables that “contain” list values don’t actually contain lists directly. What do they contain instead?
  1. What is the difference between copy.copy() and copy.deepcopy()?

results matching ""

    No results matching ""