运算符优先级
expr++ expr--
unary++expr --expr +expr -expr ~ !
multiplicative* / %
additive+ -
shift<< >> >>>
relational< > <= >= instanceof
equality== !=
bitwise AND&
bitwise exclusive OR^
bitwise inclusive OR|
logical AND&&
logical OR||
ternary? :
assignment= += -= *= /= %= &= ^= |= <<= >>= >>>=
::
Scope resolutionLeft-to-right++
--
Suffix/postfix increment and decrement()
Function call[]
Array subscripting.
Element selection by reference−>
Element selection through pointer++
--
Prefix increment and decrementRight-to-left+
−
Unary plus and minus!
~
Logical NOT and bitwise NOT(type)
Type cast*
Indirection (dereference)&
Address-ofsizeof
Size-ofnew
, new[]
Dynamic memory allocationdelete
, delete[]
Dynamic memory deallocation.*
->*
Pointer to memberLeft-to-right*
/
%
Multiplication, division, and remainder+
−
Addition and subtraction<<
>>
Bitwise left shift and right shift<
<=
For relational operators < and ≤ respectively>
>=
For relational operators > and ≥ respectively==
!=
For relational = and ≠ respectively&
Bitwise AND^
Bitwise XOR (exclusive or)|
Bitwise OR (inclusive or)&&
Logical AND||
Logical OR?:
Ternary conditionalRight-to-Left=
Direct assignment (provided by default for C++ classes)+=
−=
Assignment by sum and difference*=
/=
%=
Assignment by product, quotient, and remainder<<=
>>=
Assignment by bitwise left shift and right shift&=
^=
|=
Assignment by bitwise AND, XOR, and ORthrow
Throw operator (for exceptions),
CommaLeft-to-right++
--
Suffix/postfix increment and decrementLeft-to-right()
Function call[]
Array subscripting.
Structure and union member access−>
Structure and union member access through pointer(type){list}
Compound literal(C99)++
--
Prefix increment and decrementRight-to-left+
−
Unary plus and minus!
~
Logical NOT and bitwise NOT(type)
Type cast*
Indirection (dereference)&
Address-ofsizeof
Size-of_Alignof
Alignment requirement(C11)*
/
%
Multiplication, division, and remainderLeft-to-right+
−
Addition and subtraction<<
>>
Bitwise left shift and right shift<
<=
For relational operators < and ≤ respectively>
>=
For relational operators > and ≥ respectively==
!=
For relational = and ≠ respectively&
Bitwise AND^
Bitwise XOR (exclusive or)|
Bitwise OR (inclusive or)&&
Logical AND||
Logical OR?:
Ternary conditionalRight-to-Left=
Simple assignment+=
−=
Assignment by sum and difference*=
/=
%=
Assignment by product, quotient, and remainder<<=
>>=
Assignment by bitwise left shift and right shift&=
^=
|=
Assignment by bitwise AND, XOR, and OR,
CommaLeft-to-rightclone new
clone 和 new左[
array()非结合++ --
递增/递减运算符非结合~ - (int) (float) (string) (array) (object) (bool) @
类型非结合instanceof
类型右结合!
逻辑操作符左* / %
算术运算符左+ - .
算术运算符 和 字符串运算符左<< >>
位运算符非结合< <= > >= <>
比较运算符非结合== != === !==
比较运算符左&
位运算符 和 引用左^
位运算符左|
位运算符左&&
逻辑运算符左||
逻辑运算符左? :
三元运算符右= += -= *= /= .= %= &= |= ^= <<= >>=
赋值运算符左and
逻辑运算符左xor
逻辑运算符左or
逻辑运算符左,
多处用到这个表给出Python的运算符优先级(从低到高).
从最低的优先级(最松散地结合)到最高的优先级(最紧密地结合)。
这意味着在一个表达式中,Python会首先计算表中较下面的运算符,然后在计算列在表上部的运算符。
lambda
Lambda表达式or
布尔“或”and
布尔“与”not x
布尔“非”in,not in
成员测试is,is not
同一性测试<,<=,>,>=,!=,==
比较|
按位或^
按位异或&
按位与<<,>>
移位+,-
加法与减法*,/,%
乘法、除法与取余+x,-x
正负号~x
按位翻转**
指数x.attribute
属性参考x[index]
下标x[index:index]
寻址段f(arguments...)
函数调用(experession,...)
绑定或元组显示[expression,...]
列表显示{key:datum,...}
字典显示'expression,...'
字符串转换声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。