0

I am unable to understand how the statement below gets this answer? Question:

>>>a=[1,2,3,4,5]

>>>a[3:1]
>>>[]

>>>a[3:1:-1]
>>>[4, 3]

Please explain to me why did I get this output?

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
  • 6
    Does this answer your question? [Understanding slice notation](https://stackoverflow.com/questions/509211/understanding-slice-notation) – Buckeye14Guy Feb 27 '20 at 20:37
  • 1
    `[start:stop:step]` - similar to `range`... With your second example, the default `step` is 1, so you can't have any items - 1 (your stop) is lower than 3... – Ed Ward Feb 27 '20 at 20:40

0 Answers0