List slices PRO exercise problem | Sololearn: Learn to code for FREE!

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

4/27/2021 2:04:27 PM

PotassiumBanana

3 Answers

New Answer

+2

some tutorial https://code.sololearn.com/cAQBZ3dHmbKW/?ref=app

+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).

0

Thank you! :D