On 2021-10-13 16:26, Marc-Andre Lemburg wrote:
On 13.10.2021 17:11, Guido van Rossum wrote:
Maybe we should only accept operators as aliases for existing methods.
x-y could mean x.removesuffix(y)
That was the idea, yes, in particular to make it similar to "+", which adds to the end of the string, so that:
s = x - oldend + newend
works as expected.
I don't think x~y is intuitive enough to use.
True.
I tried to find an operator that looked similar to "-", but "~" would only work as unary operator, a Chris correctly pointed out, and even if it were a binary one, it would look too similar to "-" and also doesn't play well when used on a single line.
s = newstart + (x ~ oldstart)
So I withdraw that proposal.
From a mathematical point of view, x-y is equivalent to x+(-y). That leads me to me "negative" strings that, when added to a string, remove characters instead of adding them. For example: "abcdef" - "ef" == "abcdef" + (-"ef") == "abcd" and also: (-"ab") + "abcdef" == "cdef" Voilà! An alternative to .removeprefix. :-)
On Wed, Oct 13, 2021 at 8:03 AM Stephen J. Turnbull <stephenjturnbull@gmail.com <mailto:stephenjturnbull@gmail.com>> wrote:
Chris Angelico writes:
> +1, although it's debatable whether it should be remove suffix or > remove all. I'd be happy with either.
If by "remove all" you mean "efefef" - "ef" == "", I think that's a footgun. Similarly for "efabcd" - "ef" == "abcdef" - "ef".
Steve