Assignment to arbitrary targets
would also mean permitting iterable unpacking, which is not desired
("x, y := 3, 4"??), and there weren't enough use-cases for
attribute/item assignment to justify creating a rule of "you can
assign to any single target, but can't unpack". In the future, if such
use-cases are found, the grammar can be expanded.
在python-dev邮件列表中给出的赋值表达式中不允许更复杂的赋值,这是有道理的
特别是Chris Angelico:
https://mail.python.org/pipermail/python-dev/2018-July/154628.html
来自圭多本人:
https://mail.python.org/pipermail/python-dev/2018-July/154631.html
这可能是一个尽可能接近的解释。据推测,如果有需求,该功能可能会在未来的某个版本中扩展
因为,正如替代名称(命名表达式)所示,the left hand side of the walrus operator is to be a ^{} 。因此,根据定义,您的问题中提到的表达式以及(例如)函数调用不允许在此表单中分配
文件还规定:
为了进一步说明这个论点,可以注意到,如果表达式为^{,则cPython显式地checks:
相关问题 更多 >
编程相关推荐