新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:將列表轉(zhuǎn)換為元組
創(chuàng)新互聯(lián)python教程:

創(chuàng)新互聯(lián)主要從事做網(wǎng)站、網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)岱山,10余年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
寫一個 Python 程序?qū)⒘斜磙D(zhuǎn)換成元組。在 Python 中,我們有一個元組函數(shù),它將列表項轉(zhuǎn)換為元組。這個 Python 示例使用元組函數(shù)將列表轉(zhuǎn)換為元組。
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))
將列表轉(zhuǎn)換為元組的 Python 程序示例 2
它允許用戶輸入列表項,并使用不同的選項將該列表轉(zhuǎn)換為元組。
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程序:將列表轉(zhuǎn)換為元組
URL鏈接:http://fisionsoft.com.cn/article/dhhceos.html


咨詢
建站咨詢
