Why can I repeat the + in Python arbitrarily in a calculation?

  • A+

Today I have started to learn Python. The first things I learned were values, expressions and (arithmetic) operators. So far, everything makes sense, except one thing that I don not get:



evaluates to 4 (which makes sense),


results in a SyntaxError (which also makes sense). But what – from my point of view – does not make sense is the following line of code:


This results in 4 as well, and I wonder why. If I can compare this to JavaScript (which I use on a day-to-day basis), this results in an error in JavaScript.

So, two questions:

  1. Why does this not result in a syntax error?
  2. How does this expression get evaluated? What happens to the additional + signs?


Python has an unary + operator - +2 will evaluate to 2. So, that expression is actually evaluated as:


Which, of course, is 4.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: