【发布时间】:2013-01-23 14:08:32
【问题描述】:
我想知道以下哪项对于元组(也对于列表或 int)执行得更快:
a_tuple = ('a', 'b',)
if (len(a_tuple) != 0): passif (len(a_tuple) > 0): pass
我做了一些 timeit 实验,结果非常相似(每次运行 timeit 100000 次迭代时都会有所不同)。我只是想知道是否有时间收益。
【问题讨论】:
-
像这样的微优化很少有好处。如果您需要速度,请将其外包给 C。
标签: python python-3.x python-2.7