3 ms·
When you're unsure about how Python treats an expression, then the ast¹ module is your friend: >>> ast.dump(ast.parse('n != x &~ n'), False) Module([Ex
by JNRowe 7y ago
When you're unsure about how Python treats an expression, then the ast¹ module is your friend:
>>> ast.dump(ast.parse('n != x &~ n'), False)
Module([Expr(Compare(Name('n', Load()), [NotEq()], [BinOp(Name('x', Load()), BitAnd(), UnaryOp(Invert(), Name('n', Load())))]))])
It can make it easier to reason through the curiosities, such as the precedence in the given example.
Note: Suggesting `ast` as a solution surely proves continuational's point ;)
1. https://docs.python.org/3/library/ast.html https://docs.python.org/3/library/ast.html