[Python-ideas] New explicit methods to trim strings
Terry Reedy
tjreedy at udel.edu
Mon Mar 25 13:35:55 EDT 2019
On 3/25/2019 6:22 AM, Jonathan Fine wrote:
> Instead of naming these operations, we could use '+' and '-', with
> semantics:
>
> # Set the values of the variables.
> >>> a = 'hello '
> >>> b = 'world'
> >>> c = 'hello world'
>
> # Some values between the variables.
> >>> a + b == c
> True
> >>> a == c - b
> True
> >>> b = -a + c
> True
Summary: using '-' for trimming works well for postfixes, badly for
prefixes, and not at all for infixes. Clever but not too practical
since trimming prefixes seems to be more common than trimming postfixes.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list