The + operator is the unary plus operator; it returns its numeric argument unchanged. So ++x is parsed as +(+(x)), and gives x unchanged (as long as x contains a number):
>>> ++5 5 >>> ++"hello" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: bad operand type for unary +: 'str'
If + is called on an object of a user-defined class, the __pos__ special method will be called if it exists; otherwise, TypeError will be raised as above.
To confirm this we can use the ast module to show how Python parses the expression:
import ast print(ast.dump(ast.parse('++x', mode='eval'))) Expression(body=UnaryOp(op=UAdd(), operand=UnaryOp(op=UAdd(), operand=Name(id='x', ctx=Load()))))