热线电话:13121318867

登录
2018-10-23 阅读量: 879
python错误解析(三)

代码如下:

>>> seq = [1, 2, 3, 4]  
>>> sep = '+'
>>> sep.join(seq)

Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
sep.join(seq)
TypeError: sequence item 0: expected string, int found

【错误分析】join是split的逆方法,是非常重要的字符串方法,但不能用来连接整数型列表,所以需要改成:

复制代码

代码如下:

>>> seq = ['1', '2', '3', '4']  
>>> sep = '+'
>>> sep.join(seq)
'1+2+3+4'
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子