0

Why im not geting an index error when i run this code.. list = ['a', 'b', 'c', 'd', 'e'] print (list[10:]) ?

25th Nov 2016, 6:45 AM
Mazin
Mazin - avatar
3 Antworten
+ 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?
25th Nov 2016, 9:37 AM
donkeyhot
donkeyhot - avatar
0
im using python 3.5 and i get the same result an empty list.
25th Nov 2016, 9:39 AM
Mazin
Mazin - avatar
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.
25th Nov 2016, 1:26 PM
asdadasdsaczxc