TypeError: 'int' object is not iterable Python issues with loops (beginner)

TypeError: 'int' object is not iterable Python issues with loops (beginner)

忽略 avsterr 的任何当前问题,我想将定义的函数 avsterr 调用到 运行 x 次,其中 x 是我的 list() 的长度。 barcodeCounter 定义列表的最大长度。我不确定如何编写语法以及我应该使用哪种类型的循环(for、while、if)。

for _ in barcodeCounter: (av,st) = avsterr(topr[barcodeCounter],toprseq[barcodeCounter]) 给我 "TypeError: 'int' object is not iterable"

def avsterr(x,z):
        ave = len(x)/len(z)
        ssq = 0.0
        for y in x:
                ssq += (y-ave)*(y-ave)
        var = ssq / (len(x)-1)        sdev = math.sqrt(var)
        stderr = sdev / math.sqrt(len(x))
        return (ave,stderr)

我希望这些信息足够了。感谢您提供的任何解释,以帮助我更好地理解 python。

使用range()方法。您可以通过这种方式迭代一个 int:

In [1]: for y in range(10):
   ...:     print y
   ...:     
0
1
2
3
4
5
6
7
8
9