On Wed, Apr 3, 2019 at 5:34 AM MRAB <[email protected]> wrote:
>
> The code above contains a subtle bug.
> If suffix == '', then word.endswith(suffix) == True, and
> word[:-len(suffix)] == word[:-0] == ''.
>
> Each time I see someone do that, I see more evidence in support of
> adding the method.

Either that, or it's evidence that negative indexing is only part of
the story, and we need a real way to express "zero from the end" other
than negative zero. For instance, word[:<0] might mean "zero from the
end", and word[:<1] would be "one from the end". As a syntactic
element rather than an arithmetic one, it would be safe against
accidentally slicing from the front instead of the back.

But that's an idea for another day.

ChrisA
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to