目录
报错内容:
TypeError: sequence item 0: expected str instance, int found
了解join()函数
语法:
str.join(sequence)
参数:
可连接对象:列表,元组,字符串,字典和集合(都得是字符串)
#参数
#sequence - 要连接的元素序列。比如:列表,元组,字符串,字典和集合
#str - 以什么来连接元素
错误分析
L=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
t='-'.join(L)
print(t)
此处我的L列表里面都是非str类型,所以报错:
解决问题:
L=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
t='-'.join(L)
print(t)
运行结果:
1-2-3-4-5-6-7-8-9-10
查看自己要连接的元素是否都为str类型的字符串