Possible Duplicate:
Behaviour of increment and decrement operators in Python
Completely new to python I wrote ++x thinking it would increment x. So I was wrong about that, no problem. But no syntax error either. Hence my question: what does ++x actually mean in python?
The
+operator is the unary plus operator; it returns its numeric argument unchanged. So++xis parsed as+(+(x)), and givesxunchanged (as long asxcontains a number):If
+is called on an object of a user-defined class, the__pos__special method will be called if it exists; otherwise,TypeErrorwill be raised as above.To confirm this we can use the ast module to show how Python parses the expression: