【发布时间】:2012-10-31 02:55:00
【问题描述】:
可能重复:
Is it possible to implement a Python for range loop without an iterator variable?
只是想多次做某事所以我写了
for i in range(1, 10):
print 'something'
print 'do not use i'
所以当我运行 PyLint 时,它会说:“未使用的变量 'i'”当然。 那么在我只想循环多次的情况下编写这种类型的循环的正确方法是什么。
i = 0
while i < 10:
print 'test'
i += 1
这是唯一的方法吗?
【问题讨论】:
-
PEP8 在哪里说你不应该有你从未读取过的循环变量?
标签: python loops for-loop unused-variables