热线电话:13121318867

登录
2018-11-13 阅读量: 892
序列相加

可使用加法运算符来拼接序列。

>>> [1, 2, 3] + [4, 5, 6]
[1, 2, 3, 4, 5, 6]
>>> 'Hello,' + 'world!'
'Hello, world!'
>>> [1, 2, 3] + 'world!' Traceback (innermost last):
File "<pyshell>", line 1, in ?
[1, 2, 3] + 'world!'
TypeError: can only concatenate list (not "string") to list

从错误消息可知,不能拼接列表和字符串,虽然它们都是序列。一般而言,不能拼接不同类 型的序列。

0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子