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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s