2 Apr
2019
2 Apr
'19
6:42 p.m.
On Wed, Apr 3, 2019 at 5:34 AM MRAB <python@mrabarnett.plus.com> 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