Skip to Content
Learn
Advanced Topics in Python
Omitting Indices

If you don’t pass a particular index to the list slice, Python will pick a default.

to_five = ['A', 'B', 'C', 'D', 'E'] print to_five[3:] # prints ['D', 'E'] print to_five[:2] # prints ['A', 'B'] print to_five[::2] # print ['A', 'C', 'E']
  1. The default starting index is 0.
  2. The default ending index is the end of the list.
  3. The default stride is 1.

Instructions

1.

Use list slicing to print out every odd element of my_list from start to finish.

Omit the start and end index. You only need to specify a stride.

Check the Hint if you need help.

Folder Icon

Take this course for free

Already have an account?