Python Tuple(元组) tuple()方法

Python 教程 · 2019-02-01 17:26:53

描述

Python 元组 tuple() 函数将列表转换为元组。

语法

tuple()方法语法:

tuple( seq )

参数

  • seq -- 要转换为元组的序列。

返回值

返回元组。

实例

以下实例展示了 tuple()函数的使用方法:

实例 1

>>>tuple([1,2,3,4]) (1, 2, 3, 4) >>> tuple({1:2,3:4}) #针对字典 会返回字典的key组成的tuple (1, 3) >>> tuple((1,2,3,4)) #元组会返回元组自身 (1, 2, 3, 4)

实例 2

#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc']; aTuple = tuple(aList) print "Tuple elements : ", aTuple

以上实例输出结果为:

Tuple elements :  (123, 'xyz', 'zara', 'abc')

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

MongoDB

MongoDB

Kristina Chodorow / O'Reilly Media / 2013-5-23 / USD 39.99

How does MongoDB help you manage a huMONGOus amount of data collected through your web application? With this authoritative introduction, you'll learn the many advantages of using document-oriented da......一起来看看 《MongoDB》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具