【发布时间】:2020-11-12 16:41:33
【问题描述】:
我正在尝试打印一个列表。它给出了类型错误。
buyList = ["Potato", "Suger", "Rice", "Oil", "Cake", "Biscuit"]
for i in buyList:
if i % 2 is not 0:
print(i, end=" ")
i += 1
错误
TypeError: not all arguments converted during string formatting
【问题讨论】:
-
i是列表的元素,因此它是一个字符串(例如:“Potato”)而不是数字 -
做,你有什么问题?你有没有做过 any 调试,比如打印
i并查看它是什么?尝试各种操作并举例说明?查找错误消息?请停止像您的个人调试服务一样使用 StackOverflow。另外,永远不要使用is来表示相等,它是身份运算符,这在技术上是错误的(尽管由于实现细节,x is 0大部分时间都可以工作......但不是所有时间)
标签: python python-3.x