On 2021-10-12 13:49, Steven D'Aprano wrote:
On Tue, Oct 12, 2021 at 11:36:42PM +1100, Chris Angelico wrote:
You haven't given any reason why unary plus should imply ord().
I think the question Chris is really asking is why should unary plus return ord() rather than any other function or method.
We could make unary plus of a string equal to the upper() method:
+"Hello world" # returns "HELLO WORLD"
You could then strengthen that suggestion by saying the unary minus would be equivalent to the lower() method.
or the strip() method:
+" Hello world " # returns "Hello world"
+"Hello world" # returns 11
or any other function or method we want. What is so special about ord(), and what is the connection between ord() and `+` that makes it obvious that +"a" should return 97 rather than "A" or 1 or 10 or something else?
It's not enough to just say that unary plus is unused for strings, you have to justify why the average programmer will look at unary plus and immediately think "ord".