Python Tuple(元组) tuple()方法

栏目: 编程语言 · Python · 编程教程 · python 教程 · 发布时间: 8年前

内容简介:Python 元组 tuple() 函数将列表转换为元组。

描述

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

语法

tuple()方法语法:

tuple( seq )

参数

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

返回值

返回元组。

实例

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

>>>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)
#!/usr/bin/python
 
aList = [123, 'xyz', 'zara', 'abc'];
aTuple = tuple(aList)
 
print "Tuple elements : ", aTuple

以上实例输出结果为:

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

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beginning Google Maps API 3

Beginning Google Maps API 3

Gabriel Svennerberg / Apress / 2010-07-27 / $39.99

This book is about the next generation of the Google Maps API. It will provide the reader with the skills and knowledge necessary to incorporate Google Maps v3 on web pages in both desktop and mobile ......一起来看看 《Beginning Google Maps API 3》 这本书的介绍吧!

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

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换