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


以上是Howdoesthefollowingexpressionworkinpython?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>