Loading lesson path
Operator precedence describes the order in which operations are performed.
Parentheses has the highest precedence, meaning that expressions inside parentheses must be evaluated first:
print((6 + 3) - (6 + 3))print(100 + 5 * 3)The precedence order is described in the table below, starting with the highest precedence at the top:
()
Try it » **
Try it » +x -x ~x Unary plus, unary minus, and bitwise NOT Try it » * / // % Multiplication, division, floor division, and modulus Try it » +
Try it » << >>
Try it » &
Try it » ^
Try it » |
Try it » == != > >= < <= is is not in not in Comparisons, identity, and membership operators Try it » not
Try it » and
Try it » or OR Try it »
If two operators have the same precedence, the expression is evaluated from left to right.
+ and subtraction
has the same precedence, and therefore we evaluate the expression from left to right:
print(5 + 4 - 7 + 3)