CBSE Class 12 Computer Science
Question 78 of 105
Python Revision Tour II — Question 5
Back to all questions[4, 3, 2]
The slicing notation a[start:stop:step] extracts a portion of the list from index start to stop-1 with a specified step. In the slicing part a[3:0:-1]:
startis 3, which corresponds to the element with value 4.stopis 0, but as element at stop index is excluded so slicing goes up to index 1.stepis -1, indicating that we want to step backward through the list.
Putting it together:
a[3:0:-1]This extracts elements from index 3 to (0+1) in reverse order with a step of -1.
The output of the code will be:
[4, 3, 2]