0

How does this work?

l = list((1,2,3,4,5)) print(l[1:3]+l[4:2]) Gives [2,3] But how?

29th Jul 2022, 8:08 AM
MrFantastic
MrFantastic - avatar
4 Antworten
+ 2
MrFantastic It won't be an error because it is not slicing outside the index value of the list
29th Jul 2022, 8:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
l[1:3] is [2,3]. l[4:2] is empty because there is no item whose order is greater equal than 4 and less than 2.
29th Jul 2022, 8:16 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Got it thanks 👍👍👍
29th Jul 2022, 8:46 AM
MrFantastic
MrFantastic - avatar
- 1
Wouldn't l[4:2] be an error?
29th Jul 2022, 8:38 AM
MrFantastic
MrFantastic - avatar