Learn Python
Number
4.6
Lesson

PEMDAS in Python

The operator precedence in Python works in the order of PEMDAS:

P - parentheses - ( )

E - exponential - e

M - multiplication - *

D - division - /

A - addition - +

S - subtraction - -

Parentheses have the highest priority and subtraction the lowest.

For example,

expression_1 = 30-(10+ 8)*2 / 4

In this expression, the order of calculation is as follows using the PEMDAS rule:

Step 1: 10 + 8 = 18

Step 2: 18 * 2 = 36

Step 3: 36 / 4 = 9

Step 4: 30 - 9 = 21