TypeError:“类型”对象在for循环中不可迭代

时间:2020-01-02 22:30:58

标签: python python-3.x exception typeerror

我看过其他线程,无法弄清楚出了什么问题。所有答案都太复杂了,我无法很好地处理。

我一直收到以下错误:

TypeError: 'type' object is not iterable

我不知道为什么。

这是一个代码段:

calcWhat = 4
elif o == "^":
    pwr = int(input("To the power of what? "))
    pwr = pwr - 1 #So that if it's one then it doesnt multiply at all
    ans = calcWhat * calcWhat
    for pwr in range:
        ans = ans + (calcWhat * calcWhat)

我认为这是正确的代码,但是如果不解决此错误,我什至看不到!

怎么了?

1 个答案:

答案 0 :(得分:1)

您似乎正在尝试遍历range的{​​{1}}(如错误所提到)。您可能要调用函数type并为其指定范围限制。在您的情况下,将是:

range()