This table gives the operator precedence (from low to high) for Python.
From the lowest priority (the most loosely combined) to the highest priority (the most tightly coupled).
This means that in an expression, Python first calculates the following operator in the table, and then computes the operator that is listed in the upper part of the table.
Python Operator Precedence
operator |
Description |
lambda |
Lambda expression |
or |
Boolean "or" |
and |
Boolean "and" |
not x |
Boolean "Non" |
in,not in |
Member Test |
is,is not |
Identity testing |
<,<=,>,>=,!=,== |
Comparison |
| |
Bitwise OR |
^ |
Bitwise XOR OR |
& |
Bitwise-AND |
<<,>> |
Shift |
+,- |
Addition and subtraction |
*,/,% |
Multiplication, division and redundancy |
+x,-x |
PLUS sign |
~x |
Rollover by bit |
** |
Index |
x.attribute |
Property Reference |
x[index] |
Subscript |
x[index:index] |
Addressing segment |
f(arguments...) |
Function call |
(experession,...) |
Binding or tuple display |
[expression,...] |
List display |
{key:datum,...} |
Dictionary display |
‘expression,...‘ |
String conversions |
Reprint: http://prayer163.blog.163.com/blog/static/29018857201301091850765/
Python Operator Precedence