【发布时间】:2014-12-11 10:06:37
【问题描述】:
举个例子:
a = "foo" if True else "bar"
这执行得很好,没有问题。 现在采取:
print("foo") if True else print("bar")
这会引发错误。
我假设第一个像三元运算符一样工作。有没有办法在不诉诸全文的情况下编写第二条语句:
if True:
print("foo")
else:
print("bar")
类似于 Perl 的东西
print("foo") if True
【问题讨论】:
标签: python python-2.7 conditional-statements