Python operator precedence (priority)

Lowest priority has lambdas, conditions, or, and, not. Full table looks like (from low to high):

LOWEST

  1. lambda
  2. ifelse
  3. or
  4. and
  5. not x
  6. in, not in, is, is not, <, <=, >, >=, !=, ==
  7. |
  8. ^
  9. &
  10. <<, >>
  11. +, -
  12. *, /, //, %
  13. +x, -x, ~x
  14. **
  15. x[index], x[index:index], x(arguments...), x.attribute
  16. (expressions...), [expressions...], {key: value...}, {expressions...}

HIGHEST

On same line priority is equel so such operators executed from left to right.

#python
menu 1
Ivan Borshchov profile picture
Dec 05, 2016
by Ivan Borshchov

Best related

Other by Ivan Borshchov