Python is a widely-used, high-level programming language that is known for its readability and ease of use. As a Python developer, it is important to understand how Python's operator precedence rules affect the way expressions are evaluated. This tutorial will cover the basics of operator precedence in Python. By the end of this tutorial, you will have a solid understanding of operator precedence in Python, which will make it easier for you to write clean, efficient code that gets the job done.

Table of Contents :

  • What is Operators Precedence?
  • Precedence of operators in Python

What is Operators Precedence?

  • An expression can be a combination of several operators and sub-expressions.
  • To evaluate such an expression correctly, the interpreter should know which operator should be evaluated first.
  • This order of evaluation is determined by operator precedence.

Precedence of operators in Python

  • The following tables shows python operator precedence from highest to lowest.
Operator Meaning 
()Parenthesis  (Highest Precedence)
** Exponent
+x, -x ,~xUnary plus, Unary Minus, Bitwise negation
*, /, //, %Multiplication, Division, Floor division, Modulus
 +, -Addition, Subtraction
<<, >>Bitwise shift operator
&Bitwise AND
^Bitwise XOR
|Bitwise OR
 ==, !=, >, >=, <, <=Comparison
is, is not, in, not inIdentity, Membership
notLogical NOT
andLogical AND
orLogical OR  (Lowest Precedence)

Prev. Tutorial : Bitwise Operators

Next Tutorial : Operator special functions