Python Tuple(元组) tuple()方法

Python 教程 · 2019-02-03 06:29:25

描述

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://codercto.com/courses/l/8.html

查看所有标签

Realm of Racket

Realm of Racket

Matthias Felleisen、Conrad Barski M.D.、David Van Horn、Eight Students Northeastern University of / No Starch Press / 2013-6-25 / USD 39.95

Racket is the noble descendant of Lisp, a programming language renowned for its elegance and power. But while Racket retains the functional goodness of Lisp that makes programming purists drool, it wa......一起来看看 《Realm of Racket》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码