4 ms·
Is this legal python?
by csunbird 7y ago
Is this legal python?
- ainar-g 7y agoYes. At least in Python 2. "<>" was an alternative spelling of "!=".
- tyingq 7y ago<> is gone in python 3
- JNRowe 7y agoWhen 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