【无标题】TypeError: ‘>‘ not supported between instances of ‘str‘ and ‘int‘
for row in sh.rows:
num = row[1].value
print(num)
>>>2.6
明明结果打印是数字
然而,当我添加了一行时:
for row in sh.rows:
num = row[1].value
if num > 4:
data1.append(row)
else:
data2.append(row)
>>>TypeError: '>' not supported between instances of 'str' and 'int'
却报错了,提示我两边不能进行str和int类型的比较
但是它明明不是str类型的啊
此时我用了一下eval函数,却发现解决了问题
if eval(num) > 4:
程序成功的运行了~
【无标题】TypeError: ‘>‘ not supported between instances of ‘str‘ and ‘int‘最先出现在Python成神之路。
共有 0 条评论