Sri*_*thy 1 python syntax comparison
根据python文档,x<y<z比较被转换为x<y and y<z,表达式y最多只评估一次.
现在我的问题是,表达式y(看下面的代码)在这里只评估一次吗?
if(x<y and y<z):
Run Code Online (Sandbox Code Playgroud)
两次:
>>> def f():
... print "F called"
... return 1
...
>>> 0 < f() < 100
F called
True
>>> 0 < f() and f() < 100
F called
F called
True
>>> if (0 < f() and f() < 100):
... print True
...
F called
F called
True
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |