What is the output of the following snippet?
my_list = [1, 2, 3, 4] print(my_list[-3:-2])
- []
- [2, 3, 4]
- [2]
- [2, 3]
Explanation: Let’s analyze this example:
- the list my_list is created with the integer elements 1, 2, 3, 4,
- using negative indices (-3:-2), the elements from the third-last position to before the second-last position are selected,
- the elements are printed on the console.
More Questions: Python Essentials 1 – Module 3 Test
Please login or Register to submit your answer