This table shows the precedence and associativity of the arithmetic, relational, and logical operators from highest to lowest precedence.
Operation | Description | Associativity |
---|---|---|
() | parentheses for grouping | left to right |
** | exponentiation | right to left |
+, - | unary + (positive sign), | left to right |
unary - (negative sign) | ||
*, /, % | multiplication, division, remainder | left to right |
+, - | addition and subtraction | left to right |
in, not in, is, is not, | membership and comparisons | left to right |
<, <=, >, >=, !=, ==! | ||
not | boolean not | left to right |
and | boolean and | left to right |
or | boolean or | left to right |
In Python 3, // (integer division) has the same precedence as *, /, and %.
|
Last modified: January 9, 2018 at 10:58PM Winter Quarter 2018 You can get a PDF version of this |