简体   繁体   English

TypeError:“ int”对象不是具有循环的Python迭代问题(入门)

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

Ignoring any current issues with avsterr, I want to call the defined function avsterr to run x amount of times where x is length of my list(). 忽略avsterr当前存在的任何问题,我想调用定义的函数avsterr来运行x次,其中x是我的list()的长度。 barcodeCounter defines the max length of the list. barcodeCounter定义列表的最大长度。 I am not sure how to write the syntax and what type of loop I should use (for, while, if). 我不确定如何编写语法以及应该使用哪种类型的循环(for,while,if)。

for _ in barcodeCounter: (av,st) = avsterr(topr[barcodeCounter],toprseq[barcodeCounter]) gives me "TypeError: 'int' object is not iterable" for _ in barcodeCounter: (av,st) = avsterr(topr[barcodeCounter],toprseq[barcodeCounter])给我“ TypeError:'int'对象不可迭代”

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)

I hope this is enough info. 我希望这是足够的信息。 I appreciate any explanations you can give to help me better understand python. 我感谢您可以提供任何有助于我更好地理解python的解释。

Use range() method. 使用range()方法。 You can iterate an int in this way: 您可以通过以下方式迭代一个int:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM