We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
If this tool helped you, you can buy us a coffee ☕
Quickly check the precedence and associativity rules for all Python operators with our free online lookup tool.
(expressions...)Primary Expressions & AccessLeft-associative用圆括号分组表达式或创建元组,是优先级最高的语法结构。
(a + b) * c[expressions...]Primary Expressions & AccessLeft-associative构造列表字面量,可使用列表推导式。
[x * 2 for x in items]{key: value, ...}Primary Expressions & AccessLeft-associative构造字典字面量,可使用字典推导式。
{k: v for k, v in pairs}{expressions...}Primary Expressions & AccessLeft-associative构造集合字面量,可使用集合推导式。
{x for x in items}x[index]Primary Expressions & AccessLeft-associative通过索引访问序列、映射或可下标对象的元素。
items[0]x[start:end]Primary Expressions & AccessLeft-associative对序列进行切片操作,支持步长 start:end:step。
text[1:5:2]x(arguments...)Primary Expressions & AccessLeft-associative调用函数、方法或可调用对象。
len(items)x.attributePrimary Expressions & AccessLeft-associative访问对象的属性或方法。
user.nameawait xAwaitRight-associative在协程中挂起执行并等待可等待对象的结果。
result = await fetch()**ExponentiationRight-associative计算左操作数的右操作数次幂;右结合,2**3**2 等价于 2**(3**2)。
2 ** 10+xUnary OperationsRight-associative保留数值本身,通常用于显式表示正值,部分自定义类可重载。
+count-xUnary OperationsRight-associative返回操作数的相反数。
-offset~xUnary OperationsRight-associative对整数每一位取反,结果为 -(x+1)。
~0b1010*Multiplicative OperationsLeft-associative数值相乘;字符串/序列与整数相乘可实现重复。
width * scale@Multiplicative OperationsLeft-associativePython 3.5+ 的矩阵乘法运算符,常用于 NumPy 等库。
matrix_a @ matrix_b/Multiplicative OperationsLeft-associative真除法,结果始终为浮点数。
total / count//Multiplicative OperationsLeft-associative向下取整除法,结果向负无穷取整。
10 // 3%Multiplicative OperationsLeft-associative整数取余;对字符串可执行旧式 % 格式化。
index % 2+Additive OperationsLeft-associative数值相加;序列拼接,如字符串、列表、元组。
x + y-Additive OperationsLeft-associative数值相减;集合差集操作不通过此运算符。
max_value - min_value<<Bitwise Shift OperationsLeft-associative将整数二进制位向左移动指定数量,相当于乘以 2 的幂。
1 << bit>>Bitwise Shift OperationsLeft-associative将整数二进制位向右移动指定数量,相当于整除 2 的幂。
flags >> 1&Bitwise OperationsLeft-associative对两个整数逐位执行与运算;对集合表示交集。
options & MASK^Bitwise OperationsLeft-associative对两个整数逐位执行异或运算;对集合表示对称差集。
set_a ^ set_b|Bitwise OperationsLeft-associative对两个整数逐位执行或运算;对集合表示并集。
FLAG_A | FLAG_B==Comparison OperationsLeft-associative比较两个对象的值是否相等,调用对象的 __eq__ 方法。
status == 200!=Comparison OperationsLeft-associative比较两个对象是否不相等。
value != None>Comparison OperationsLeft-associative判断左操作数是否大于右操作数。
count > limit>=Comparison OperationsLeft-associative判断左操作数是否大于或等于右操作数。
count >= minimum<Comparison OperationsLeft-associative判断左操作数是否小于右操作数。
index < total<=Comparison OperationsLeft-associative判断左操作数是否小于或等于右操作数。
index <= last_indexinComparison OperationsLeft-associative判断元素是否在容器中,调用容器的 __contains__ 方法。
key in mappingnot inComparison OperationsLeft-associative判断元素是否不在容器中。
name not in blacklistisComparison OperationsLeft-associative判断两个引用是否指向同一对象,比较 id() 值。
value is Noneis notComparison OperationsLeft-associative判断两个引用是否指向不同对象。
result is not Nonenot xBoolean OperationsRight-associative对布尔或条件表达式取反,结果为 True 或 False。
not is_emptyandBoolean OperationsLeft-associative短路与;左侧为假值时返回左侧,否则返回右侧的求值结果。
user and user.is_activeorBoolean OperationsLeft-associative短路或;左侧为真值时返回左侧,否则返回右侧的求值结果。
value or default_valuex if cond else yConditional ExpressionsRight-associative三元条件运算,当 cond 为真返回 x,否则返回 y。
title if title else 'Untitled'lambdaLambda ExpressionsNon-associative创建匿名函数,返回单个表达式的值。
square = lambda x: x * x:=Walrus AssignmentRight-associativePython 3.8+ 的命名表达式,在表达式中完成赋值;优先级最低。
if (n := len(items)) > 10: ...When writing Python expressions, operator precedence determines which operations are executed first. Forgetting the exact order often leads to logical errors. This tool allows you to instantly check the precedence level and associativity of built-in Python operators, helping developers accurately understand the evaluation order of expressions and avoid potential bugs.
*, +, or the logical operator and.* outputs precedence 13, associativity: left-to-right; entering ** outputs precedence 15, associativity: right-to-left.This lookup only supports built-in Python operators. Entering custom operators or non-operator characters will return an error prompt. The results are based on the official Python documentation and apply to CPython 3.x versions; different implementations may vary slightly. This tool performs client-side queries and does not collect any user input data.
It is recommended to memorize common precedence rules: exponentiation ** is the highest, followed by unary plus/minus and bitwise NOT. Multiplication and division take precedence over addition and subtraction. Comparison operators have lower precedence than arithmetic ones, and the logical operators not, and, and or decrease in precedence respectively. In the expression a + b * c, b * c is evaluated first. For 2 ** 1 ** 3, because ** is right-associative, it is equivalent to 2 ** (1 ** 3), resulting in 2. When writing complex expressions during development, we highly recommend using parentheses to explicitly control the evaluation order and improve code readability.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.

Python Regex Tester
Test Python regular expression patterns online. Get real-time match results, capture groups, and position info to quickly debug text processing rules.
Python Code Formatter
Free online Python code formatter and beautifier. Automatically indent and organize your scripts to improve readability and adhere to PEP 8 standards.

PYC Version Checker
Identify the Python version of .pyc files via magic numbers to resolve compatibility issues.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.

Python Regex Tester
Test Python regular expression patterns online. Get real-time match results, capture groups, and position info to quickly debug text processing rules.
Python Code Formatter
Free online Python code formatter and beautifier. Automatically indent and organize your scripts to improve readability and adhere to PEP 8 standards.

PYC Version Checker
Identify the Python version of .pyc files via magic numbers to resolve compatibility issues.

JSON to Python Class Converter
Automatically convert JSON data into standard Python class definitions for API responses, config files, and more.