我检查了 "python "的count函数,发现它是整数,但当我试图检查它是否大于某个数字时,它显示我是str
one = 0
two = 0
three = 0
for i in words:
i = str(i)
if (words.count(i) > one):
one = i
elif (words.count(i) > two):
two = i
elif (words.count(i) > three):
three = i
的错误。
if (words.count(i) > one):
TypeError: '>' not supported between instances of 'int' and 'str'
问题就出在这一行。
i = str(i)
所以后来,当你把一个新的值赋给: one
:
one = i
one
变成一个字符串。 而不是改变 i
,改变 if
:
if (words.count(str(i)) > one):