0

Why this code output is []

lst=list(range(0,10)) Print(lst[-1:2])

5/27/2019 6:54:45 PM

Geek

2 Answers

New Answer

+4

lst[-1:2] is the same as lst[-1:2:1]. Go from the last element back to the third element in steps of +1. That's not possible, so the result is an empty list. If you change it to lst[-1:2:-1]), the result will be [9, 8, 7, 6, 5, 4, 3]

0

Thankyou!!