On Fri, Nov 13, 2015 at 10:40 PM, Steven D'Aprano <st...@pearwood.info> wrote: > Python has operator overloading, so it can be anything you want it to be. > E.g. you might have a DSL where +feature turns something on and -feature > turns it off.
By that argument we should also have operators ~, !, $, \, ? because some hypothetical DSL might someday want to use them for something. > Decimal uses it to force the current precision and rounding, regardless of > what the number was initiated to: > > Counter uses it to strip zero and negative counts: > > I would expect that symbolic maths software like Sympy probably has use of a > unary plus operator, but I'm not sure. Unary plus as normalization does not strike me as being very intuitive. I never would have known about any of these if I hadn't read the Counter case in the docs, and then I only remembered it because it because it seemed janky. Unary minus on Counters is even weirder, by the way: it first negates the signs of all the values, and *then* normalizes by removing non-positive values. Who has ever needed that? For somebody reading one of these uses of unary plus in real code, I imagine it would be a bit of a WTF moment if it's the first time they've encountered it. I don't recall ever seeing any code that actually used this, though. > I might consider stealing an idea from Perl and Javascript, and have unary > plus convert strings to a number: > > +"123" > => returns int 123 > +"1.23" > => returns float 1.23 Eww. -- https://mail.python.org/mailman/listinfo/python-list