python 列表元组加减乘除法,python加减乘除,元组(typle)列


元组(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]*2print(l,type(l))

 输出为

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

python 列表元组加减乘除法

评论关闭