天天看點

python for循環10次,Python for每秒僅循環一次

python for循環10次,Python for每秒僅循環一次

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

prints only

105000

105002

105004

105006

but I don't know why.

using a function to generate an array from input like

self.arrSplit(105000,105001,105002,105003,105004,105005,105006,105007)

function:

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

prints:

[105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007]

105000

105002

105004

105006

解決方案

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.

繼續閱讀