2018-11-09
阅读量:
885
序列相加
可使用加法运算符来拼接序列。
>>> [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)


暂无数据
推荐帖子
0条评论
0条评论
0条评论