CPSC120A
Fundamentals of Computer Science I

Activity 34

Review for Final Exam.

  1. What is the difference between mutable and immutable data types? What are some examples of each?

  2. What is aliasing? Why does it only affect mutable data types?

  3. How do dictionaries differ from lists?

  4. For each of the following snippets of Python code, give what would be printed to the command line if run. If the snippet will not print anything because of an error, just put error.

    1. spam = [1]
      for i in range(4):
          spam.append(spam[i] + spam[i])
      print(spam)
              
    2. spam = {1: 2, 2: 3}
      print(spam[spam[1]])
              
    3. spam = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
      eggs = []
      for i in range(3):
          eggs.append(spam[i][i])
      print(eggs)
              
    4. def spam(eggs):
          eggs.append(0)
      ham = [1, 2, 3]
      spam(ham)
      print(ham)
              
    5. def spam(eggs):
          eggs = eggs + "a"
      ham = "123"
      spam(ham)
      print(ham)