新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:打印元組項(xiàng)目
創(chuàng)新互聯(lián)python教程:

創(chuàng)新互聯(lián)公司專注于白城企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都做商城網(wǎng)站。白城網(wǎng)站建設(shè)公司,為白城等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
編寫一個 Python 程序來打印元組中所有項(xiàng)目的列表。我們可以使用 print 函數(shù)打印整個元組。在這個例子中,我們聲明了字符串和 int 元組并打印它們。
# Print Tuple Items
numTuple = (10, 20, 30, 40, 50)
print("The Tuple Items are ")
print(numTuple )
strTuple = ('C#', 'Java', 'Python', 'C')
print("\nThe String Tuple Items are ")
print(strTuple )在這個 Python 程序中,我們使用 for 循環(huán)范圍來訪問每個元組項(xiàng)。第一個 for 循環(huán)從第一個元組項(xiàng)迭代到最后一個,并打印每個元素。第二個循環(huán)打印字符串元組中的所有水果。
# Print Tuple Items
numTuple = (10, 20, 30, 40, 50)
print("The Tuple Items are ")
for i in range(len(numTuple)):
print("Tuple Item at %d Position = %d" %(i, numTuple[i]))
print("=========")
fruitsTuple = ('apple', 'orange', 'kiwi', 'grape')
for fruit in fruitsTuple:
print(fruit)The Tuple Items are
Tuple Item at 0 Position = 10
Tuple Item at 1 Position = 20
Tuple Item at 2 Position = 30
Tuple Item at 3 Position = 40
Tuple Item at 4 Position = 50
=========
apple
orange
kiwi
grape 網(wǎng)站題目:Python 程序:打印元組項(xiàng)目
網(wǎng)頁網(wǎng)址:http://fisionsoft.com.cn/article/dhhdips.html


咨詢
建站咨詢
