IT 116: Introduction to Scripting
Quiz 10 Answers

  1. Write a Python expression that creates a slice containing the second through the fourth elements of the list l1.
    l1[1:4]
  2. Write a Python expression that evaluates to True if the list l1 contains the value 4.
    4 in l1
  3. Write a Python statement to add 6 to the list l1.
    l1.append(6)
  4. Write a Python statement that sorts the list l1.
    l1.sort()
  5. Write a Python expression that gives the largest value in the list l1.
    max(l1)
  6. Write a Python expression that gives the smallest value in the list l1.
    min(l1)
  7. If l1 is a list, what is l2 after the following statement is executed?
    l2 = l1
    a new list variable pointing to the same list as l1
  8. Write a Python statement that creates a new list, l2, that has all the elements of the list l1 in the same order.
    l2 = l1[:]
  9. Can a function that is given a list as a parameter and does not have a return statement change the list given as a parameter?
    yes
  10. If l1 and l2 are list variables, write a Python statement that creates the new list l3 that consists of all the elements in l1 followed by all the elements in l2.
    l3 = l1 + l2