Python for每秒仅循环一次Item [英] Python for loops only every second Item
本文介绍了Python for每秒仅循环一次Item的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从来没有这样的问题,甚至不知道如何解决...
never had such a problem and do not know how to solve or even call it...
types = [105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007]
for type in types:
print type
仅打印
105000
105002
105004
105006
但我不知道为什么.
使用函数从类似的输入中生成数组
using a function to generate an array from input like
self.arrSplit(105000,105001,105002,105003,105004,105005,105006,105007)
功能:
def arrSplit(self, arr):
itms = []
for it in arr.split(','):
tt = it.split('-')
if (len(tt) >= 2 and int(tt[0]) < int(tt[1])):
for i in range(int(tt[0]), int(tt[1])+1):
itms.append(i)
else:
itms.append(int(tt[0]))
return itms
要完成此操作,代码应如下所示(最小)
to complete this the code looks like this (its the minimum)
types = self.arrSplit(105000,105001,105002,105003,105004,105005,105006,105007)
print types
for type in types:
print type
打印:
[105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007]
105000
105002
105004
105006
推荐答案
对于for循环,您应该使用以下代码:
For the for loop you should use this:
types = [105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007]
for numbers in types:
print numbers
这对我有用,但是我无法解释为什么它只打印偶数.
This worked for me, but I can't explain why it only printed evens.
这篇关于Python for每秒仅循环一次Item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文