Operator Precedence
Now that comparisons and logical operators have joined the arithmetic ones, here is the whole ordering in one place.
The full precedence table
Now that comparisons and logical operators have joined the arithmetic ones, here is the whole ordering in one place.| Precedence | Operator | Operation |
|---|---|---|
| highest | ** | exponentiation |
- | negation | |
*, /, //, % | multiplication, division, floor division, modulus | |
+, - | addition, subtraction | |
==, !=, <, >, <=, >= | comparisons | |
not | logical not | |
and | logical and | |
or | logical or | |
| lowest | = | assignment |
Math operators have the highest precedence. Then comparison operators are followed by logical operators. The assignment operator is evaluated last.
Although the above expression is correct, often for the sake of readability and clarity it is often good practice to include parentheses.