2 ms·
Why is x == not x rejected by the parser? In many other languages this is perfectly valid and, depending on the semantics, may allow the compiler that into fals
by kccqzy 7y ago
Why is x == not x rejected by the parser? In many other languages this is perfectly valid and, depending on the semantics, may allow the compiler that into false. (Of course this can't generally be the case where operators are user-overloadable.)
- js2 7y agoBecause that's how the grammar is defined: https://docs.python.org/3.8/reference/grammar.html https://docs.python.org/3.8/reference/grammar.html The RHS of the == (comp_op) has to be an expr. You can force "not x" to be an expr by parenthesizing it: x == (not x)
- kccqzy 7y agoThat interesting. On the other hand, not x == x is totally valid.
- lidHanteyk 7y agoI don't know man, I didn't do it.