MCQ - Python List Slicing

Mar 15, 2015 • Elizabeth Wickes

These questions are based off Analyzing Patient Data from here

Given this list:

my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Which element will be printed with the following command:

print my_list[-1]

  1. 0
  2. 1
  3. 9
  4. 8

Using this same list, what would be printed with the following command:

print my_list[2:9]
  1. [2, 3, 4, 5, 6, 7, 8, 9]
  2. [1, 2, 3, 4, 5, 6, 7, 8]
  3. [1, 2, 3, 4, 5, 6, 7, 8, 9]
  4. [2, 3, 4, 5, 6, 7, 8]

The misconceptions are:

  1. Using inclusive end.
  2. Started index at 1 instead of 2.
  3. Both bad index start and using inclusive end.
  4. Correct.