Hello, On Thu, 26 Nov 2020 13:27:46 +1300 Greg Ewing <[email protected]> wrote:
> On 26/11/20 12:41 pm, Steven D'Aprano wrote: > > a = "abcdef" > > a[-2] # returns a result > > Yes, but did you *intend* that result, or did the -2 > result from a calculation that should have returned a > positive index but went wrong? Python has no way to > tell. Certainly it does: idx = index_calc() assert idx >= 0 Compare that with the case where index of 5 is invalid (just can't happen per algorithm invariants). Python (or any other language) "has no way to tell" that just from looks of your algorithm, and yet it's easy to tell that: idx = index_calc() assert idx != 5 -- Best regards, Paul mailto:[email protected] _______________________________________________ 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/OLRBQRDWFB3QRVCW2Z2HAG66UOPTI5WS/ Code of Conduct: http://python.org/psf/codeofconduct/
