python 列表元组加减乘除法

元组(typle)列表(list)没有减法和除法,但有加法和乘法。

1、加法,即把元素相加。只可以list和tuple相加,不能加其他类型。

t= (1, ) + (2, 3, 4)
print(t, type(t))

 输出为

(1, 2, 3, 4) <class 'tuple'>

 

2、乘法,只能和整形相乘。即把元素个数翻倍,不能和其他任意类型相加。

l= [80,80,3]*2
print(l,type(l))

 输出为

[80, 80, 3, 80, 80, 3] <class 'list'>

 

posted @ 2018-02-03 21:24  .每天进步一点点  阅读(18835)  评论(0编辑  收藏  举报