靚麗時尚館

位置:首頁 > 健康生活 > 心理

tuple函式的作用

心理1.97W
tuple函式的作用

1 #tuple函式的功能和list函式基本上一樣,都是以一個序列作為引數,並把它轉換為元組。如果引數是元組,引數就會被原樣返回。

2 #示例如下:

3 >>> tuple('hello','world') #引數是元組

4 Traceback (most recent call last):

5 File "<pyshell#52>", line 1, in <module>

6 tuple('hello','world') #引數是元組

7 TypeError: tuple() takes at most 1 argument (2 given)

8 >>> tuple(('hello','world')) #引數是元組

9 ('hello', 'world')

10 #由上面的操作看到,tuple函式傳入元組引數後,得到的返回值就是傳入的引數。

標籤:tuple 函式