2019-04-11
阅读量:
704
什么是Python中的连接(concatenation)?
Python中的连接就是将两个序列连在一起,我们使用+运算符完成:
'22'+'33'
‘2233’
[1,2,3]+[4,5,6]
[1, 2,3, 4, 5, 6]
(2,3)+(4)
TypeError Traceback (most recent call last)
<ipython-input-7-69a1660f2fc5> in <module>
----> 1 (2,3)+(4)
TypeError: can only concatenate tuple (not "int") to tuple
这里运行出错,因为(4)被看作是一个整数,修改一下再重新运行:
(2,3)+(4,)
(2, 3,4)






评论(0)


暂无数据
推荐帖子
2条评论
6条评论
7条评论