Howdoesthefollowingexpressionworkinpython?
How does the following expression work in python?
>>> 1 ++++++++++++++++++++ 1
2
>>> 1 ++++++++++++++++++++-+ 1
0
I thought this would raise SyntaxError but that was not the case.
回答
You have to use the logic of brackets and arithmetic operations for this kind of calculation.
1--2 becomes,
1-(-(2)) = 1-(-2)
= 1+2
= 3
1+++1 becomes,
1+(+(+1)) = 2
1++-1 becomes,
1+(+(-1)) = 0
THE END
二维码