首发于 python

[错误] TypeError: sequence item 0: expected str inst

TypeError: sequence item 0: expected str instance, int found
list包含数字,不能直接转化成字符串


小例子:

a = ['1','2','3',1]
print(' '.join(a))

报错:

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/onetest.py", line 188, in <module>
    print(' '.join(a))
TypeError: sequence item 3: expected str instance, int found


解决办法:

print(" ".join('%s' %id for id in list1))

即遍历list的元素,把他转化成字符串。这样就能成功输出1 2 3 1了。





参考:

TypeError: sequence item 0: expected str instance, int found的解决办法

发布于 2021-01-07 09:39

文章被以下专栏收录