python 列表元组加减乘除法

时间:2018-02-03 23:09:30   收藏:0   阅读:7343

元组(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‘>

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!