以下代码:
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
有谁知道发生了什么?