在python中使用tuple()函数将列表转换为元组的方法
tuple:tuple()函数的作用是将列表转换为元组。
tuple()函数语法:
tuple( iterable )
参数:
iterable:表示需要转换为元组的可迭代序列。
tuple()函数使用方法:
List = [123, 'xyz', 'zara', 'abc'];
aTuple = tuple(List)
print "Tuple elements : ", aTuple
输出结果为:
Tuple elements : (123, 'xyz', 'zara', 'abc')
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python中冒泡排序如何编写