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‘>

 

文章来自:https://www.cnblogs.com/qggg/p/8410795.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3