Articles → Python → Order Of Calculation In Python

Order Of Calculation In Python






PEMDAS







Example




#PEMDAS Stands For

#P stands for Parenthesis
#E stands for Exponent
#M stands for Multiplication
#D stands for Division
#A stands for Addition
#S stands for Subtraction


print(2-3*5)
print(2**3*5)
print((2-3)*5)


  1. In the first expression, preference will be given to multiply followed by subtraction. So, the calculation would be 2 – 15 = -13.
  2. In the second expression, preference will be given to multiply followed by subtraction. So, the calculation would be (3 times 2) 8 * 5 = 40.
  3. In the second expression, preference will be given to parenthesis followed by multiplication. So, the calculation would be -1 * 5 = -5.


Picture showing the output of how the order of calculation works in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, February 15, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250