Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (2.2k points)

i) Parentheses

ii) Exponential

iii) Multiplication

iv) Division

v) Addition

vi) Subtraction

A) i,ii,iii,iv,v,vi

B) ii,i,iii,iv,v,vi

C) ii,i,iv,iii,v,vi

D) i,ii,iii,iv,vi,v

3 Answers

0 votes
by (3.9k points)

The correct answer to the question “What is the order of precedence in Python” is option (a). i,ii,iii,iv,v,vi. Python also follows the same concept of precedence as used in Math. In Math, it is known as BODMAS, and in Python, you could remember PEMDAS as the order of precedence.

Looking out for a good course in Python? Check out Intellipaat’s Python course of 42 hours, with 50 hours of project work,  will help you in gaining mastery over Python. If you wish to get started, right away, then watch the following video on Python Course in Hindi.

0 votes
by (37.3k points)

In Python, the correct order of precedence is as follows - 

  • Parentheses have the highest precedence. 

  • Exponentiation is evaluated next. 

  • Multiplication is evaluated after exponentiation, followed by division. 

  • Addition is evaluated after division, followed by subtraction. 

Hence, option A is the correct answer.

0 votes
by (3.1k points)

How The Order Works:

  • The Parentheses(): whatever has its expression inside parentheses it would be evaluated first.
  • Exponential**: It helps you to find the power of the number. (ex: 2**3 = 2x2x2 = 8)
  • Multiplication*: Used for multiplication, the precedence fallows after exponential
  • Division/:  This operator helps you to divide, the precedence fallows after multiplication. 
  • Subtraction- : This operator helps you to subtract, the precedence fallows after division.
  • Addition+: It is fallowed by subtraction, and it is used for adding.

Example:  (2+3)**2*4/2-1+3

Answer: 

(2+3) = 5 => 5**2*4/2-1+3

5**2 = 25 => 25*4/2-1+3

25*4 =  100 => 100/2-1+3

100/2  = 50 => 50-1+3

50-1 = 49  => 49+3

49+3 = 52

===> (2+3)**2*4/2-1+3 = 52

So Answer is D): i, ii, iii, iv, vi, v.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...