Using the ast module, we can create an abstract representation of the syntax tree and see what happens:
import ast source = 'ADD SOURCE HERE' node = ast.parse(source, mode='eval') ast.dump(node, False, False)
In the case of 3 +++ 5 AST generates the following expression:
'Expression(BinOp(Num(1), Add(), UnaryOp(UAdd(), UnaryOp(UAdd(), Num(2)))))'
Or, for example, 3 ++ -- 5 produces:
'Expression(BinOp(Num(3), Add(), UnaryOp(UAdd(), UnaryOp(USub(), Num(-5)))))'
source share