python的tuple(),,转载于:http:/
python的tuple(),,转载于:http:/
转载于:http://www.runoob.com/python/att-tuple-tuple.html
描述
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/pythonaList = [123, ‘xyz‘, ‘zara‘, ‘abc‘];aTuple = tuple(aList)print "Tuple elements : ", aTuple
以上实例输出结果为:
Tuple elements : (123, ‘xyz‘, ‘zara‘, ‘abc‘)
python的tuple()
相关内容
- 【Python】同时安装了python2和python3时,pip命令该如何使
- 【401】Python 求合数的所有质数因子,,对于这样的一个
- python手动编译py_compile,compileall,,python运行之后
- python zip()和zip(*)方法,,欢迎关注本人博客:云
- Python中 list, numpy.array, torch.Tensor 格式相互转化,,1.1 l
- python的list和数组的区别,,list不是数组(额
- python3 练手实例4 九九乘法口诀表,,1 for i in
- 别人用钱,而我用python爬虫爬取了一年的4K高清壁纸,
- python3 事件Event,,python线程的事
- Python安装pip,,进入到Python的
评论关闭