What is correct operators precedence in Python?



Following table shows order of precedence of operators in Python starting from highest to lowest precedence.

** : Exponentiation (raise to the power)
~ + - : Ccomplement, unary plus and minus (method names for the last two are +@ and -@)
* / % // : Multiply, divide, modulo and floor division
+ - : Addition and subtraction
>> << : Right and left bitwise shift
& : Bitwise 'AND'

^ | : Bitwise exclusive `OR' and regular `OR'

<= < > >= : Comparison operators

<> == != : Equality operators

= %= /= //= -= += *= **= : Assignment operators

is is not : Identity operators

in not in : Membership operators

not or and : Logical operators


Advertisements