curious asymmetry in range limiting

Robin Becker robin at reportlab.com
Tue Mar 20 10:36:46 EDT 2018


So eventually I tried this
> C:\code\hg-repos\reportlab>\python36\python -c"s='0123456789';print(repr(s[-5:15]))"
> '56789'
>> C:\code\hg-repos\reportlab>\python36\python -c"s='0123456789';print(repr(s[-6:15]))"
> '456789'

and the light dawned :) seems the negative indexes rules apply to both
On 20/03/2018 14:21, Robin Becker wrote:
> I don't know how I never came across this before, but there's a curious asymmetry in the way ranges are limited
>> Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> s = '0123456789'
> >>> print(repr(s[-5:5]))
> ''
> >>> print(repr(s[5:15]))
> '56789'
> >>>
>> why is the underflow start index treated so differently from the limit index overflow? I suppose there must be some reason, but it 
> eludes me.

-- 
Robin Becker


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /