【发布时间】:2014-07-26 00:57:43
【问题描述】:
我在 python 中使用了一些条件语句,它们给出了相同的结果。我想知道哪个更好,它们之间在性能和逻辑上有什么区别。
案例一:
if a and b and c:
#some action
对比
if all( (a, b, c) ):
#some action
案例2:
if a or b or c:
#some action
对
if any( (a, b, c) ):
#some action
案例3:
if not x in a:
#some action
对
if x not in a:
#some action
在上述情况下,我想知道性能和逻辑上的差异以及首选方式。
【问题讨论】:
-
有什么区别?速度、逻辑、可读性……?
-
@Tichodromamuraria 编辑了问题。
标签: python conditional-statements