OPERATOR PRECEDENCE IN PYTHON

In python, we have different types of operators.The sequence in which the operators are executed are operator precedence

Below are the rules which are in the order of higher precedence in descending order

PEDMAS – Parentheses,Exponenets,Division/Multiplication,Addition/Subtraction

BEDMAS – Brackets,Exponents,Division/Multiplication,Addition/Subtraction

BODMAS – Brackets,Order,Division/Multiplication,Addition/Subtraction

BIDMAS – Brackets,Index,Division/Multiplication,Addition/Subtraction

Code:

x = 12
y = 3
print(x+y/3-9*12)
print(x+(y/3) - (9*12))
print((((x+y) /3) -9)*12)
print(((x+y)/3 -9)*12)

c = x + y
d = c / 3
e = d - 9
print(e * 12)
print(x / (y * x) / y)

O/P:

-95.0
-95.0
-48.0
-48.0
-48.0
0.1111111111111111

Leave a Reply