CBSE Class 11 Computer Science Question 52 of 104

List Manipulation — Question 5

Back to all questions
5
Question

Question 5

What's a[1 : 1] if a is a list of at least two elements? And what if the list is shorter?

Answer

a[x:y] returns a slice of the sequence from index x to y - 1. So, a[1 : 1] will return an empty list irrespective of whether the list has two elements or less as a slice from index 1 to index 0 is an invalid range.

Answer