日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:向元組中添加一個(gè)項(xiàng)

創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)專注于企業(yè)營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站重做改版、卓尼網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、商城網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為卓尼等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

編寫一個(gè) Python 程序向元組中添加一個(gè)條目。Python 元組不允許您向現(xiàn)有元組中添加項(xiàng)目。下面的 Python 示例將通過連接新項(xiàng)目和當(dāng)前元組來創(chuàng)建一個(gè)新元組。

# Add an Item to Tuple

intTuple = (10, 20, 30, 40, 50)
print("Tuple Items = ", intTuple)

intTuple = intTuple + (70,)
print("Tuple Items = ", intTuple)

intTuple = intTuple + (80, 90)
print("Tuple Items = ", intTuple)

intTuple = intTuple[2:5] + (11, 22, 33, 44) + intTuple[7:]
print("Tuple Items = ", intTuple)

在這個(gè) Python 示例中,我們?cè)试S用戶輸入 tuple 項(xiàng),并將它們添加到一個(gè)空 Tuple 中。為了達(dá)到同樣的目的,我們使用 for 循環(huán)范圍來迭代元組項(xiàng)。

# Add an Item to Tuple

intTuple = ()

number = int(input("Enter the Total Number of Tuple Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d Tuple value = " %i))
    intTuple = intTuple + (value,)

print("Tuple Items = ", intTuple)
Enter the Total Number of Tuple Items = 4
Enter the 1 Tuple value = 22
Enter the 2 Tuple value = 99
Enter the 3 Tuple value = 122
Enter the 4 Tuple value = 77
Tuple Items =  (22, 99, 122, 77)

當(dāng)前標(biāo)題:Python程序:向元組中添加一個(gè)項(xiàng)
文章網(wǎng)址:http://www.5511xx.com/article/dpseihe.html