【发布时间】:2020-09-10 19:30:14
【问题描述】:
以下代码:
a,b=1,2
print((x:=a)<2<(z:=b) or z>1>x)
print((x:=a)<1<(y:=b) or y>1>x)
给出以下输出:
False
Traceback (most recent call last):
File "C:/Users/phili/PycharmProjects/ML 1/CodingBat exercises.py", line 56, in <module>
print((x:=a)<1<(y:=b) or y>1>x)
NameError: name 'y' is not defined
这似乎完全不一致。一些变化,如
(x:=1)>=2>(y:=9) or y>=2>x
也给了
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'y' is not defined
有人知道发生了什么吗?
【问题讨论】:
标签: python-3.8 walrus-operator