Date
Sep. 8th, 2024
 
2024年 8月 6日

Post: Python 运算符优先级 对照表

Python 运算符优先级 对照表

Published 12:11 Nov 10, 2012.

Created by @ezra. Categorized in #Programming, and tagged as #Python.

Source format: Markdown

Table of Content
这个表给出Python的运算符优先级 (从低到高) 。
从最低的优先级 (最松散地结合) 到最高的优先级 (最紧密地结合) 。
这意味着在一个表达式中,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,...' 字符串转换
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系