1. 程式人生 > >python 列表元組加減乘除法

python 列表元組加減乘除法

python list python 列表 div 加減 其他 type 加減乘除 相加

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

python 列表元組加減乘除法