您的位置:首页 > 产品设计 > UI/UE

[已解决]报错: TypeError: sequence item 0: expected str instance, int found

2020-06-08 07:15 731 查看

钉钉、微博极速扩容黑科技,点击观看阿里云弹性计算年度发布会!>>>

今天敲小例子,报了错TypeError: sequence item 0: expected str instance, int found

小例子

list1=[1,'two','three',4]
print(' '.join(list1))

以为会打印1 two three 4

结果报了错

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    print(" ".join(list1))
TypeError: sequence item 0: expected str instance, int found

上网查了资料,说list包含数字,不能直接转化成字符串。

解决办法:

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

即遍历list的元素,把他转化成字符串。这样就能成功输出1 two three 4结果了。

from: https://www.geek-share.com/detail/2701707012.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sequence
相关文章推荐