[Python-ideas] New explicit methods to trim strings
jfine2358 at gmail.com
Mon Mar 25 06:22:53 EDT 2019
Instead of naming these operations, we could use '+' and '-', with
# Set the values of the variables.
>>> a = 'hello '
>>> b = 'world'
>>> c = 'hello world'
# Some values between the variables.
>>> a + b == c
>>> a == c - b
>>> b = -a + c
# Just like numbers except.
>>> a + b == b + a
This approach has both attractions and problems. And also decisions. The
main issue, I think come to this. Suppose we have
a, A = ('a', -'a')
b, B = ('b', -'b')
a + A == A + a == ''
b + B == B + b == ''
A + '' == '' + A == A
B + '' == '' + B == B
together with unrestricted addition of a, A, b, B then we have what
mathematicians call the free group on 2 letters, which is an enormous
object. If you want the math, look at,
We've made a big mistake, I think, if we allow Python programmers to
accidentally encounter this free group. One way to look at this, is that we
want to cut the free group down to a useful size. One way is
>>> 'hello ' - 'world' == 'hello' # I like to call this truncation.
Another way is
>>> 'hello' - 'world' # I like to call this subtraction.
ValueError: string s1 does not end with s2, so can't be subtracted
I hope this little discussion helps with naming things. I think this is
enough for now.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas