We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.


The following list summarizes the operator precedences in Python, from lowest precedence (least binding) to highest precedence (most binding).

Within each group, the operators group left to right (except for exponentiation, which groups from right to left).

Unless the syntax is explicitly given, operators are binary.

  1. Lambda expression: lambda (lambda) (lowest precedence)
  2. Boolean OR: or (or)
  3. Boolean AND: and (and)
  4. Boolean NOT: not x (not)
  5. Membership tests: in, not in (in)
    Identity tests: is, is not (is)
    Comparisons: <, <=, >, >=, <>, !=, == (comparisons)
  6. Bitwise OR: | (operator-or)
  7. Bitwise XOR: ^ (operator-xor)
  8. Bitwise AND: & (operator-and)
  9. Shifts: <<, >> (operator-lshift operator-rshift)
  10. Addition and subtraction: +, (operator-add operator-sub)
  11. Multiplication, division, remainder: *, /, % (operator-mul operator-div operator-mod)
  12. Positive, negative: +x, x (operator-pos operator-neg)
  13. Bitwise not (invert): ~x (operator-invert)
  14. Exponentiation: ** (operator-pow)
  15. Attribute reference: x.attribute (attribute-references)
  16. Subscription: x[index] (subscriptions)
  17. Slicing: x[index:index] (slicings)
  18. Function call: f(arguments…) (calls)
  19. Binding or tuple display: (expressions…) (parenthesized-forms)
  20. List display: [expressions…] (list-displays)
  21. Dictionary display: {key:datum…} (dictionary-displays)
  22. String conversion: `expressions…` (string-conversions) (highest precedence)