日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:打印偶數(shù)位置列表項(xiàng)

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

寫一個(gè) Python 程序,在偶數(shù)位置甚至索引位置打印列表項(xiàng)。在這個(gè) Python 偶數(shù)位置示例中,列表切片從 1 開始,在列表末尾結(jié)束,并遞增 2。

evList = [3, 6, 9, 11, 13, 15, 17, 19]

print('Printing the List Items at Even Position')
print(evList[1:len(evList):2])

Python 程序使用 for 循環(huán)在偶數(shù)索引位置打印列表項(xiàng)。

evList = [17, 24, 36, 48, 55, 79, 82, 93]

print('Printing the List Items at Even Position')
for i in range(1, len(evList), 2):
    print(evList[i], end = '  ')
Printing the List Items at Even Position
24  48  79  93 

Python 程序,使用 while 循環(huán)在偶數(shù)位置打印列表項(xiàng)

evList = [90, 120, 240, 180, 80, 60]

print('Printing the List Items at Even Position')
i = 1
while i < len(evList):
    print(evList[i], end = '  ')
    i = i + 2
Printing the List Items at Even Position
120  180  60 

在這個(gè) Python 示例中,for 循環(huán)從 0 迭代到列表長(zhǎng)度。if 條件檢查索引位置除以二等于 1。如果為真,則打印偶數(shù)位置列表項(xiàng)。

evlist = []
evListTot = int(input("Total List Items to enter = "))

for i in range(1, evListTot + 1):
    evListvalue = int(input("Please enter the %d List Item = "  %i))
    evlist.append(evListvalue)

print('\nPrinting the List Items at Even Position')
for i in range(1, len(evlist), 2):
    print(evlist[i], end = '  ')

print('\nPrinting the List Items at Even Position')
for i in range(len(evlist)):
    if i % 2 != 0:
        print(evlist[i], end = '  ')
Total List Items to enter = 8
Please enter the 1 List Item = 12
Please enter the 2 List Item = 23
Please enter the 3 List Item = 34
Please enter the 4 List Item = 45
Please enter the 5 List Item = 56
Please enter the 6 List Item = 67
Please enter the 7 List Item = 78
Please enter the 8 List Item = 89

Printing the List Items at Even Position
23  45  67  89  
Printing the List Items at Even Position
23  45  67  89 

本文名稱:Python程序:打印偶數(shù)位置列表項(xiàng)
當(dāng)前URL:http://www.dlmjj.cn/article/dpcdpgs.html