不灭的焱

加密类型:SHA/AES/RSA下载Go
复合类型:切片(slice)、映射(map)、指针(pointer)、函数(function)、通道(channel)、接口(interface)、数组(array)、结构体(struct) Go类型+零值nil
引用类型:切片(slice)、映射(map)、指针(pointer)、函数(function)、通道(channel) Go引用

作者:AlbertWen  添加时间:2020-11-04 14:37:26  修改时间:2025-11-12 11:45:49  分类:22.Python编程  编辑

Python中使用.join()连接list时,出现类型错误的解决办法:

>>> ls = [1,2,3]
>>> print ','.join(ls)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found

解决办法:

对list中的元素进行类型转换到string

 

>>> print ','.join('%s' % id for id in ls)
1,2,3