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元组