- There can be more than one operator in an expression
- To evaluate these types of expressions there is a rule of precedence in python
- It guides the order in which these operations are carried out
- The operator precedence is listed below
- It is in descending order (i.e., from higher priority to lower priority)
Associativity
- When two operators have the same precedence, associativity helps to determine the order of operations
- Associativity is the order in which an expression is evaluated that has multiple operators of the same precedence
- There are two types of associativity
- Left to right (The operator of same precedence is executed from left to right)
- Right to left (The operator of same precedence is executed from right to left)
- Almost all operators are left to right associativity
- Exponent operator has right to left associativity in python
Good to Know
When two operators have same precedence evaluate left to right except exponentiation
Views: 24