Computer Science
What's a[1 : 1] if a is a string of at least two characters ? And what if string is shorter ?
Python String Manipulation
8 Likes
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.
Answered By
5 Likes
Related Questions
What do you understand by mutability ? What does "in place" task mean ?
Start with the list [8, 9, 10]. Do the following using list functions:
- Set the second entry (index 1) to 17
- Add 4, 5 and 6 to the end of the list
- Remove the first entry from the list
- Sort the list
- Double the list
- Insert 25 at index 3
What are the two ways to add something to a list ? How are they different ?
What are the two ways to remove something from a list? How are they different ?