Message270157
This is documented behavior for the built-in sequence types [1], and it's also mentioned in the tutorial [2].
The indices() method of a slice object shows the resolved bounds for given sequence length:
>>> slice(-1000, 1000, 1).indices(4)
(0, 4, 1)
>>> slice(None, None, 1).indices(4)
(0, 4, 1)
>>> slice(1000, -1000, -1).indices(4)
(3, -1, -1)
>>> slice(None, None, -1).indices(4)
(3, -1, -1)
The rules apply the same to list, tuple, and range sequences:
>>> [1, 2, 3, 4][-1000:1000]
[1, 2, 3, 4]
>>> (1, 2, 3, 4)[-1000:1]
(1,)
>>> range(0)[-100:100]
range(0, 0)
[1]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[2]: https://docs.python.org/3/tutorial/introduction.html#strings |
|
Date |
User |
Action |
Args |
2016-07-11 04:24:42 | eryksun | set | recipients:
+ eryksun, Elizacat |
2016-07-11 04:24:42 | eryksun | set | messageid: <1468211082.7.0.314580047061.issue27479@psf.upfronthosting.co.za> |
2016-07-11 04:24:42 | eryksun | link | issue27479 messages |
2016-07-11 04:24:42 | eryksun | create | |
|