python简单迭代(python simple iteration)
我想问问什么是进行简单迭代的最佳方法。 假设我想重复某个任务1000次,哪一个是最好的? 或者,还有更好的方法?
for i in range(1000): do something with no reference to i i = 0 while i < 1000: do something with no reference to i i += 1非常感谢
i would like to ask what is the best way to make simple iteration. suppose i want to repeat certain task 1000 times, which one of the following is the best? or is there a better way?
for i in range(1000): do something with no reference to i i = 0 while i < 1000: do something with no reference to i i += 1thanks very much
最满意答案
第一个被认为是惯用的。 在Python 2.x中,使用xrange而不是range 。
The first is considered idiomatic. In Python 2.x, use xrange instead of range.
更多推荐
发布评论