Python Tutorials · Python Operators

Operator Precedence

Learn all about Operator Precedence in this comprehensive tutorial.

5 min read beginner
  • Operator precedence describes the order in which operations are performed.
  • The precedence order is described in the table below, starting with the highest precedence at the top:
  • If two operators have the same precedence, the expression is evaluated from left to right.

Operator Precedence

Operator precedence describes the order in which operations are performed.

python
python

Precedence Order

The precedence order is described in the table below, starting with the highest precedence at the top:

OperatorDescriptionTry it
()ParenthesesTry it »
**ExponentiationTry it »
+x  -x  ~xUnary plus, unary minus, and bitwise NOTTry it »
*  /  //  %Multiplication, division, floor division, and modulusTry it »
+  -Addition and subtractionTry it »
<<  >>Bitwise left and right shiftsTry it »
&Bitwise ANDTry it »
^Bitwise XORTry it »
|Bitwise ORTry it »
==  !=  >  >=  <  <=  is  is not  in  not inComparisons, identity, and membership operatorsTry it »
notLogical NOTTry it »
andANDTry it »
orORTry it »

Left-to-Right Evaluation

If two operators have the same precedence, the expression is evaluated from left to right.

python

Module quiz

2 questions
1

Which of the following is true about Operator Precedence?

2

What is the most common pitfall when working with Operator Precedence?

Answer all questions to submit.