Message292132
The behaviour is as documented and is not a bug. When you have a three-argument extended slice, the starting and stopping values depend on whether the stride (step) is positive or negative. Although that's buried in a footnote to the table.
https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
The current behaviour is necessary so that the common case of both start and stop being blank is supported correctly for negative stride:
py> "abcde"[::-1]
'edcba'
So with a positive stride, your first example lst[0:3:-1] starts at index 0, ends at index 3, with step -1. That is an empty slice.
But your second example lst[:3:-1] starts at the end of the list, index len(lst), ends at 3, with step -1. That is equivalent to lst[5:3:-1] which is not the same as your first example. |
|
Date |
User |
Action |
Args |
2017-04-22 18:16:43 | steven.daprano | set | recipients:
+ steven.daprano, Akshay Deogaonkar |
2017-04-22 18:16:43 | steven.daprano | set | messageid: <1492885003.06.0.227604956807.issue30137@psf.upfronthosting.co.za> |
2017-04-22 18:16:43 | steven.daprano | link | issue30137 messages |
2017-04-22 18:16:42 | steven.daprano | create | |
|