[Python-ideas] New explicit methods to trim strings
Jonathan Fine
jfine2358 at gmail.com
Mon Mar 25 08:01:21 EDT 2019
Chris Angelico asked: what does a negative string look like?
This is a very good question. It looks a bit like a negative number.
>>> 2 + 2
4
>>> len('aa' + 'bb')
4
>>> len(-'bb')
-2 # Odd, I must confess.
>>> 5 + (-1)
4
>>> len('hello')
5
>>> len(-'o')
-1
>>> 'hello' + (-'o')
'hell'
>>> len('hello' + (-'o'))
4
Grade school: How can I possible have -3 apples in my bag.
University: How can I possibly be overdrawn in my bank account.
Negative strings are similar to negative numbers except:
For numbers a + b == b + a
For strings a + b != b + a
It is the non-commuting that make negative strings difficult. This is a bit
like computer programming. It's not enough to have the correct lines of
code (or notes). They also have to be put in the right order.
I hope this helps. I do this sort of math all the time, and enjoy it. Your
experience may be different.
--
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190325/98ffd5f1/attachment.html>
More information about the Python-ideas
mailing list