Python中“=”的运算符优先级是多少?

2024-04-25 07:31:46 发布

您现在位置:Python中文网/ 问答频道 /正文

Python's documentation没有提到=的运算符优先级。那是什么?你知道吗


Tags: documentation运算符
1条回答
网友
1楼 · 发布于 2024-04-25 07:31:46

=不是运算符。=assignment statement。你知道吗

因为它是一个语句,所以它不能是表达式的一部分(表达式是某些语句的一部分,而不是相反),所以排序是不相关的。表达式总是被执行以提供语句。你知道吗

对于赋值,语法指定在=符号之后允许特定类型的表达式:

assignment_stmt ::=  (target_list "=")+ (starred_expression | yield_expression)

该语句的文档详细说明了执行的顺序:

An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right.

相关问题 更多 >