On Thu, Nov 26, 2020 at 12:07:56PM +1300, Greg Ewing wrote:
> On 26/11/20 2:30 am, [email protected] wrote:
> >At times I heavily rely on index out of bound exceptions to reduce the
> >number of lines necessary for error checking.
>
> This is a downside to the negative indexing scheme -- you
> can't tell the difference between a backwards index and an
> error due to out-of-bounds indexing.
Sorry, perhaps I am being a bit dim-witted this morning, but I don't
understand this. Surely the difference is obvious?
a = "abcdef"
a[-2] # returns a result
a[999] # raises an exception
Obviously you can tell the two apart, so I'm confused by your comment.
Valid indices are the half-open interval `-n <= index < n` where n is
the length of the sequence. Outside of that interval, you get an
exception.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QQ5EFB6525XZRMVCNAEX3RDNM62MMY3U/
Code of Conduct: http://python.org/psf/codeofconduct/