CBSE Class 12 Computer Science Question 57 of 105

Python Revision Tour II — Question 6

Back to all questions
6
Question

Question 6

What's a[1 : 1] if a is a string of at least two characters ? And what if string 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.