RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Python程序:将列表转换为元组

创新互联python教程:

创新互联主要从事做网站、网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务岱山,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

写一个 Python 程序将列表转换成元组。在 Python 中,我们有一个元组函数,它将列表项转换为元组。这个 Python 示例使用元组函数将列表转换为元组。

intList = [11, 22, 33, 44 ,55]
print("List Items     = ", intList)
print("List Data Type = ", type(intList))

intTuple = tuple(intList)
print("\nTuple Items     = ", intTuple)
print("Tuple Data Type = ", type(intTuple))

将列表转换为元组的 Python 程序示例 2

它允许用户输入列表项,并使用不同的选项将该列表转换为元组。

list1 = []

number = int(input("Enter the Total List Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d List value = " %i))
    list1.append(value)

print("List Items     = ", list1)
print("List Data Type = ", type(list1))

intTuple = tuple(list1)
print("\nTuple Items     = ", intTuple)
print("Tuple Data Type = ", type(intTuple))

intTuple1 = (*list1,)
print("\nTuple Items     = ", intTuple1)
print("Tuple Data Type = ", type(intTuple1))
Enter the Total List Items = 4
Enter the 1 List value = 20
Enter the 2 List value = 50
Enter the 3 List value = 120
Enter the 4 List value = 90
List Items     =  [20, 50, 120, 90]
List Data Type =  

Tuple Items     =  (20, 50, 120, 90)
Tuple Data Type =  

Tuple Items     =  (20, 50, 120, 90)
Tuple Data Type =  

网页名称:Python程序:将列表转换为元组
转载源于:http://www.jxjierui.cn/article/dhhceos.html