QuestionQ55

VerifiedData Collections – Tuples, Dictionaries, Lists, and Strings

Assume that the following assignment has executed successfully:

my_list = [5, 4, 3, 2]  

Select the expressions that will not raise an exception.

Choose two
Explanation

A four-element Python list permits indexes from 0 to 3 and from -4 to -1. my_list[-1] is 2, making my_list[my_list[-1]] equivalent to my_list[2], which is valid. The slice my_list[1:1] is also valid and returns an empty list.

Community Discussion

No comments yet. Be the first to start the discussion!