Skip to content

Precedence differs across languages: not a == b in Python

not a == b is not (a == b) in Python, because comparison binds tighter than not. In C, a & b == c is a & (b == c). The same characters group differently from one language to the next, and the parser here rejects the Python spelling rather than pick a reading.

The diagnostic recorded below is for not A == B: the parser stops at ==, which is not an operator in this language, and offers <->. Had it accepted the line, it would have had to decide whether not applies to A or to the whole comparison, and the two readings are different functions. Python's answer is the whole comparison; a logic textbook's answer is A alone, because NOT binds tightest; neither answer is wrong in its own language.

The engine's order is NOT, then AND, then XOR, then OR, then ->, then <->, and inside this language it never varies. The variation is at the borders: Python ranks not below comparisons; C and Java rank == above &, so a bitwise test needs brackets; SQL ranks NOT, AND, OR as here but places IS NULL and BETWEEN among the comparisons; spreadsheet functions have no precedence at all, because nesting is the grouping.

Translate by bracketing every mixed group before you cross a language border, and check the translation against the engine's truth table rather than against the other language's output. The language pages list each language's order and the fully bracketed form on every page shows what the engine read.

What the parser says

You typedCodeWhy it is rejectedRepair offered
not A == Bunsupported-operator`==` is not an expression operator. Use `<->` when both sides must have the same value, or the Compare workbench to compare two formulas.Replace with <->

The common slip

Translating not a == b from Python as NOT A <-> B, which is (NOT A) <-> B here, the opposite of what Python computes. The faithful translation is NOT (A <-> B), which is A XOR B.

Questions

Does the engine accept not in lower case?

Yes: operator words are case-insensitive, so not a and b parses, as (NOT a) AND b. The precedence is the engine's, not Python's.

Which language has the same order as the engine?

For NOT, AND and OR: C, Java, JavaScript, SQL and Python all rank them in that order. The differences are in how comparisons, bitwise operators and XOR fit between them.

Related

Tools

See also

Pitfalls

Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.