Eryk Sun added the comment:

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

----------
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27479>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to