🔹 Operator Precedence

Last Updated: 17th August 2025


It is the order in which the operators are evaluated in an expression.

👉 Higher precedence → evaluated first.
👉 Same precedence → evaluated left to right (except exponentiation ** which is right to left).

Hinglish Tip 🗣:Operator precedence means kis operator ka calculation pehle hoga agar ek hi expression me multiple operators use ho rahe ho.


📊 Precedence Table (Highest → Lowest)

PrecedenceOperator(s)Description
1()Parentheses (grouping)
2**Exponentiation
3+x, -x, ~xUnary plus, minus, bitwise NOT
4*, /, //, %Multiplication, Division, Floor division, Modulo
5+, -Addition, Subtraction
6<, <, >, >Bitwise shift left, right
7&Bitwise AND
8^, |Bitwise XOR, OR
9<, >, <=, >=, ==, !=Comparison operators
10notLogical NOT
11andLogical AND
12orLogical OR
13=, +=, -=, *=, /=, //=, %=,**=Assignment operators

📝 Example

result = 10 + 5 * 2 ** 2
print(result)   # 30

#🔎 Breakdown:

# 2 ** 2 → 4 (exponentiation first)
# 5 * 4 → 20 (multiplication next)
# 10 + 20 → 30 (addition last)

💡 Quick Practice

  • Predict output: print(100 / 10 * 5 + 2)
  • Predict output: print(2 ** 3 ** 2)
  • Predict output: print((10 + 2) * 3)