0
Why im not geting an index error when i run this code.. list = ['a', 'b', 'c', 'd', 'e'] print (list[10:]) ?
3 ответов
+ 1
Perhaps, because your list only contains 5 elements. And you are trying to slice it, starting from the 10th element. So, index 10 is out of range.
However, code playground and both my IDLE's (2.7 and 3.4) return an empty list, no error. That's weird you are getting one. What python version are you using?
0
im using python 3.5 and i get the same result an empty list.
0
there will be no error, because slices are not indices, and do not require them to be within the range of the list. it will return an empty list because the slice starting point exceeds the length of the list, thus the slice reads no values and returns an empty list.