Operator Precendence
What is Operator Precendence
Operator precendence is the order on which operators are evaluated. Python follow a specific rule when multiple operators are present in expression, to determine which operator to apply first.
Operator Precedence Levels
Here is a list of common operators in Python, ordered from highest to lowest precedence:
| Highest | Operator |
|---|---|
| Parentheses () | |
| Exponentiation: ** | |
| Unary Plus and Minus: -X, -X | |
| Multiplication, Division, Floor Division, and Modulus: *, /, //, % | |
| Addition and Subtraction: +, - | |
| Bitwise Shift Operators: <<, >> | |
| Bitwise AND: & | |
| Bitwise XOR: ^ | |
| Bitwise OR: | |
| Comparison Operators: ==, !=, >, <, <=, >= | |
| Identity Operators: is, is not | |
| Membership Operators: in, not in | |
| Logical NOT: not | |
| Logical AND: and | |
| Lowest | Logical OR: or |