0

List slices PRO exercise problem

Why is the output 2 and not 42? Can someone please explain this to me? ------------------- x = input() elements = x.split() print(x[:-2:-1]) ------------------- input: [42] output: 2

27th Apr 2021, 2:04 PM
PotassiumBanana
3 Answers
27th Apr 2021, 2:33 PM
Rohit
Rohit - avatar
+ 3
in indexing Im sure you know you have your [start:stop:step] if x is a list of two items, then print(x[:-2:-1]) means: print a list of all the values in the list reversed (-1), up to but not including the second to last value in the original list (-2).
27th Apr 2021, 2:19 PM
Slick
Slick - avatar
0
Thank you! :D
29th Apr 2021, 3:52 PM
PotassiumBanana