python list转换字符串报错 TypeError: sequence item 0: expected str instance, int found

L = [1,2,3,4,5]
print(','.join(L))
以上写法会报错,TypeError: sequence item 0: expected str instance, int found
原因:list包含数字,不能直接转化成字符串


修改成
print(','.join(str(n) for n in L)) 就可以了

posted on 2021-07-26 14:17  Vicky_Zhou  阅读(562)  评论(0编辑  收藏  举报