Python Operators and their precedence


Operator
  • ( )
  • **
  • +x
  • -x
  • ~x
  • *
  • /
  • //
  • %
  • +
  • -
  • <<
  • >>
  • &
  • ^
  • |
  • <
  • >
  • <=
  • >=
  • ==
  • !=
  • is
  • is not
  • in
  • not in
  • not
  • and
  • or
Precedence
  • 1
  • 2
  • 3
  • 3
  • 3
  • 4
  • 4
  • 4
  • 4
  • 5
  • 5
  • 6
  • 6
  • 7
  • 8
  • 9
  • 10
  • 10
  • 10
  • 10
  • 10
  • 10
  • 11
  • 11
  • 11
  • 11
  • 12
  • 12
  • 12
Associativity
  • left to right
  • right to left
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
  • left to right
Description
  • Parentheses
  • Exponent
  • Unary plus
  • Unary minus
  • Bitwise NOT
  • Multiplication
  • Division
  • Floor division
  • Modulus
  • Addition
  • Subtraction
  • Bitwise shift left
  • Bitwise shift right
  • Bitwise AND
  • Bitwise XOR
  • Bitwise OR
  • less than
  • greater than
  • less than or equal to
  • greater than or equal to
  • equal to
  • not equal to
  • identity
  • non identity
  • membership
  • non membership
  • logical NOT
  • logical AND
  • logical OR
datai analytics