本文摘自php中文网,作者藏色散人,侵删。

python tuple什么意思?
python tuple即元组,tuple()函数将列表转换为元组。
tuple()方法语法:
参数
seq -- 要转换为元组的序列。
返回值
返回元组。
以下实例展示了 tuple()函数的使用方法:
实例 1
1 2 3 4 5 6 7 8 9 10 11 | >>>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
1 2 3 4 5 6 | #!/usr/bin/python
aList = [123, 'xyz' , 'zara' , 'abc' ];
aTuple = tuple(aList)
print "Tuple elements : " , aTuple
|
以上实例输出结果为:
1 | Tuple elements : (123, 'xyz' , 'zara' , 'abc' )
|
相关推荐:《Python教程》
以上就是python tuple什么意思的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python怎么求整数n的阶乘?
Python装饰器详细介绍
str Python是什么意思
Python如何将名称映射到序列的元素中(代码)
Python的idle是什么
Python的内存管理机制是什么
Python的gui有哪些
Python列表中函数&方法详解
Python如何整段注释
Python读取csv文件并把文件放入一个list中的实例讲解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python tuple什么意思