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 .
Python Operator Precedence Checker
Was this tool helpful to use?
Your feedback helps us make it better
Quickly check the precedence and associativity rules for all Python operators with our free online lookup tool.
A curated syntax reference, not a compiler or example validator. Local group numbers do not replace version-specific grammar, typing or evaluation rules. Examples keep their original code and literals. Reference
(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: ...Overview
Understand what the tool solves, how it works, and the boundaries of its data.
Operator precedence describes how parts of an expression group when parentheses do not specify the grouping. For example, multiplication binds more tightly than addition, so a + b * c groups like a + (b * c). Associativity describes grouping when operators at the same precedence level repeat; it does not by itself explain every special syntax rule.
Search by symbol, operator name, description, example text, or the displayed level. Category and associativity filters narrow the list. Each result includes a description and sample expression, and its symbol or sample can be copied.
The numbered levels are this page’s sorting labels: level 1 is the strongest binding level, and larger numbers indicate weaker binding. Python’s language reference gives the order of precedence but does not assign these page-specific numbers. Use the official table when exact grammar behavior matters.
Comparisons, membership tests, and identity tests share a precedence level and can chain, as in 0 < x < 10. Exponentiation groups from right to left, while parentheses can make intended grouping explicit.
:= assignment expression entry; checked 2026-09-29.Guide
Follow the workflow and verify inputs and outputs with practical examples.
Try a symbol such as **, a keyword such as and, an operator name, a fragment from an example, or a displayed level number.
Choose a category such as arithmetic, comparison, Boolean, or bitwise, and optionally select left, right, or no associativity label.
Check its level, category, associativity, description, and example together. Treat the level as a lookup label rather than an official Python score.
Copy a symbol or example if useful, then add your own operands and parentheses. For syntax or runtime questions, check the target Python version in an interpreter.
Use cases
See how the tool fits into real work and everyday tasks.
Look up operators such as in, is, shifts, or Boolean keywords, then compare the example with the official language reference.
Use the table to identify the relative binding of arithmetic, comparison, and Boolean operators. Add parentheses in code when they make the intended grouping clearer to another reader.
Search for a symbol from a code sample and inspect its entry before adapting it. The lookup can orient you, but it cannot validate variable types or program behavior.
Q&A
Find concise answers to common questions and confusing cases.
No. In this list, level 1 is highest; larger numbers mean weaker binding. These are page labels, not numbers assigned by Python.
No. It filters a reference list; it does not parse or execute the expression you are working on. Use Python itself to check syntax and runtime behavior.
Meaning depends on syntax and operand types. For example, + can add numbers or concatenate sequences, while == compares values and is tests object identity.
Do not treat a generic associativity label as a complete model for comparisons. Python supports comparison chains such as a < b < c; consult the language reference for their semantics.
Notes
Review scope, result limitations, and important precautions before use.
The list is a quick reference, not a complete grammar or version selector. Python’s syntax can change across releases, and operators such as **, unary signs, comparisons, and the assignment expression have details that a short label cannot capture. When supporting a specific Python version or reviewing complex code, consult that version’s language reference and test the expression in the intended environment.
Related
Discover related tools, collections, and available API capabilities.