In Python, a statement that has variables, values, and operators involved is called an expression.
Like what:
#字符串表达式 " Hello " #运算表达式 2+3#赋值表达式test "hello"#变量表达式test
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 |
About shift Operations
Shift right: Shift right one representation divided by 2
8>>228>>318>>4 0
Here, the shift number is the number of the >> right, and the number shifted is the number of >> left.
Shift left: Shift left one means multiply by 2
3<<4
Here, the shift number is the number of the << right, and the number shifted is the number of << left.
Summary: The shift number is always on the right side of the shift symbol (<< or >>), and the shifted number is always on the left side of the shift symbol.
Priority level
Operator precedence is from low to high in the table above.
Other priority levels are as follows:
#以下优先级排名从高到低, in the same operation, the first execution of the high priority is low, and so on. #Top1: Function call, address, subscript #top2: Power Operation * *Prioritynumber=2*2**3print Prioritynumber #输出结果: -#Top3: Rollover Operation ~#Top4: Sign Print1+2*-3#输出结果:-5#Top5:*、/、%Print2+1*2/5#输出结果:2#Top6: +,-Print3<<2+1#输出结果: -#Top7:<<, >>#Top8: Bitwise &, ^, |#Top9: comparison operator priority=2*3+2<=2+1*7Print Priority #输出结果: True#topTen: Logical Not and Or#top One: lambda expression
General operation, left to right, assignment operation from right to left .
1+3>>> a4
Parentheses Precedence Action
>>> B = (1+2) *3>>> b9
Python Learning op-expression precedence