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