【发布时间】:2011-03-11 14:30:07
【问题描述】:
False 等价于0 和True 等价于1,所以可以这样做:
def bool_to_str(value):
"""value should be a bool"""
return ['No', 'Yes'][value]
bool_to_str(True)
注意值是bool,但用作int。
这种使用Pythonic还是应该避免?
【问题讨论】:
-
这基本上是*.com/questions/2764017/… 的复制品,其答案也很有趣!