- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Python Operators Precedence

The following table lists all operators from highest precedence to lowest.

Sr.No | Operator & Description |
---|---|

1 | **Exponentiation (raise to the power) |

2 | ~ + -Complement, unary plus and minus (method names for the last two are +@ and -@) |

3 | * / % //Multiply, divide, modulo and floor division |

4 | + -Addition and subtraction |

5 | >> <<Right and left bitwise shift |

6 | &Bitwise 'AND'td> |

7 | ^ |Bitwise exclusive `OR' and regular `OR' |

8 | <= < > >=Comparison operatorsp> |

9 | <> == !=Equality operators |

10 | = %= /= //= -= += *= **=Assignment operators |

11 | is is notis is not |

12 | in not inMembership operators |

13 | not or andLogical operators |

Operator precedence affects how an expression is evaluated.

For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first multiplies 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom.

## Example

#!/usr/bin/python a = 20 b = 10 c = 15 d = 5 e = 0 e = (a + b) * c / d #( 30 * 15 ) / 5 print "Value of (a + b) * c / d is ", e e = ((a + b) * c) / d # (30 * 15 ) / 5 print "Value of ((a + b) * c) / d is ", e e = (a + b) * (c / d); # (30) * (15/5) print "Value of (a + b) * (c / d) is ", e e = a + (b * c) / d; # 20 + (150/5) print "Value of a + (b * c) / d is ", e

## Output

When you execute the above program it produces the following result −

Value of (a + b) * c / d is 90 Value of ((a + b) * c) / d is 90 Value of (a + b) * (c / d) is 90 Value of a + (b * c) / d is 50

- Related Articles
- Java Operators Precedence
- Perl Operators Precedence
- What is correct operators precedence in Python?
- Operators Precedence in C++
- C++ Operators with Precedence and Associativity
- Can we change operator precedence in Python?
- Python Arithmetic Operators
- Python Comparison Operators
- Python Assignment Operators
- Python Bitwise Operators
- Python Logical Operators
- Python Membership Operators
- What’s up with the comma operator’s precedence in Python?
- Division Operators in Python?
- Basic Operators in Python

Advertisements