Python lists

Mar 12, 2015 • Kim Moir

The multiple choice questions are based on material from the Python lists lesson

q1. Given the following list definition:

l = [2, 4, -3, 11, -1, 12]

What is the value of l[-1]?

a. 4 
b. 2 
c. 12 
d. not defined 

q2. Given the following code:

l = [2, 4, -3, 11, -1, 12]
l.reverse()
l.append(13)

What is the value of l[-3]?

a. -3 
b. 3 
c. 11
d. 4
  • a thinks append adds element the beginning of the list, not the end
  • b thinks searching for -3 returns the position of the value -3 in the list
  • c thinks -3 starts from the beginining of the list, not the end
  • d is the correct answer