```
print(4+2*3) # Output 10
print(4+(2*3)) # Output 10
print((4+2)*3) # Output 18
```

In the first line the output is 10 ( not 18 ) as multiplication is first done and then the addition is performed. In next two lines the operation within the Parentheses is executed first. This action is done based on the precedence to be followed while performing actions using operators. This is in the order of decreasing precedence.

Operator | Details |
---|---|

`( )` | Parentheses ( By grouping the expressions the precedence can change ) |

`**` | Exponent |

`+x` , `-x` , `~x` | Positive, negative, bitwise NOT |

`*` , `@` , `/` , `//` , `%` | Multiplication, matrix multiplication, division, floor division, remainder |

`+` ,`-` | Addition and subtraction |

`<<` , `>>` | Shifts |

`&` | Bitwise AND |

`^` | Bitwise XOR |

`|` | Bitwise OR |

`in` , `not in` , `is` , `is not` , `<` , `<=` , `>` , `>=` , `!=` , `==` | Comparisons, including membership tests and identity tests |

`not x` | Boolean NOT |

`and` | Boolean AND |

`or` | Boolean OR |

`if – else` | Conditional Expression |

`lambda` | Lambda expression |

`:=` | Assignment expression |

PEMDAS :

Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction

MD : multiplication and division have the same precedence.`P`

,`E`

,`MD`

,`AS`

Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction

AS : Addition, Subtraction have the same precedence.

PEMDAS isn't about order of operations, it doesn't decide what order things are evaluated in. It's really about argument grouping.

PEMDAS says that

`x+y+z*a`

is same as `(x+y)+(z*a)`

.
```
math=40
english=50
avg=45
if math>=40 or english>=50 and avg>=50:
print("Passed")
else:
print("Failed")
```

Output is
`Passed`

Due to the higher Precedence of `if math>40 or (english > = 50 and avg > 50) `

The actual grouping should be like this to get correct result.
`(if math>40 or english > = 50) and avg > 50 `

```
print(10/2*6) # output is 30.0
print(24/6//2)# output is 2.0
```

Operators
All Built in Functions in Python dir() ord()
Subscribe to our YouTube Channel here

This article is written by **plus2net.com** team.
https://www.plus2net.com

* indicates required

Post your comments , suggestion , error , requirements etc here

Python Video Tutorials

Python SQLite Video Tutorials

Python MySQL Video Tutorials

Python Tkinter Video Tutorials