【发布时间】:2011-07-22 10:18:44
【问题描述】:
可能重复:
How to assign a variable in IF, and then return it. (Python)
在 Python 中有没有更好的方法来做到这一点?:
myVal = getVal()
if not myVal:
continue
我想做这样的事情:
if not (myVal = getVal()):
continue
但这不是有效的语法。有没有其他方法可以像在 PHP 和 Perl 中那样在一行上做到这一点?
【问题讨论】:
-
Python 高度重视代码的清晰度。你不应该这样做。