Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Operators and Types of Op...
  6. Precedence of Operators

Precedence of Operators

  • 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

Loading

Views: 24

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments