I “accidentally” came across this weird but valid syntax
i=3
print i+++i #outputs 6
print i+++++i #outputs 6
print i+-+i #outputs 0
print i+--+i #outputs 6
(for every even no: of minus symbol, it outputs 6 else 0, why?)
Does this do anything useful?
Update (Don’t take it the wrong way..I love python):
One of Python’s principle says
There should be one– and preferably only one –obvious way to do it. It seems there are infinite ways to do i+1
Since Python doesn’t have C-style ++ or — operators, one is left to assume that you’re negating or positivating(?) the value on the left.
E.g. what would you expect
i + +5to be?Notably, from the Python Grammar Specification, you’ll see the line:
Which means that a factor in an expression can be a factor preceded by
+,-, or~. I.e. it’s recursive, so if5is a factor (which it is because factor->power->NUMBER), then-5is a factor and so are--5and--------5.