Python3 tuple.tuple()方法

tuple()方法轉換列表(元組)中的專案到元組

語法

以下是 tuple() 方法的語法-
tuple( seq )

參數

  • seq -- 這是將被轉換成元組的元組。

返回值

此方法返回一個元組。

示例

下麵的示例演示 tuple() 方法的使用。
#!/usr/bin/python3
list1= ['maths', 'che', 'phy', 'bio']

tuple1=tuple(list1)
print ("tuple elements : ", tuple1)

當我們運行上面的程式,會產生以下結果 -
tuple elements :  ('maths', 'che', 'phy', 'bio')

上一篇: Python3列表 下一篇: Python3元組