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

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

新聞中心

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

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

創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括蓮池網(wǎng)站建設(shè)、蓮池網(wǎng)站制作、蓮池網(wǎng)頁制作以及蓮池網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,蓮池網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到蓮池省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

寫一個(gè) Python 程序,打印奇數(shù)位置或奇數(shù)索引位置的列表項(xiàng)。在這個(gè) Python 示例中,我們使用列表切片,從 0 開始,遞增 2,以列表長度(列表的末尾)結(jié)束。

odList = [2, 4, 7, 11, 14, 22, 19, 90]

print('Printing the List Items at Odd Position')
print(odList[0:len(odList):2])

在這個(gè) Python 程序中,我們使用 for 循環(huán)范圍來迭代列表項(xiàng),并在奇數(shù)索引位置打印列表項(xiàng)。

odList = [36, 48, 77, 55, 90, 128, 193, 240]

print('Printing the List Items at Odd Position')
for i in range(0, len(odList), 2):
    print(odList[i], end = '  ')
Printing the List Items at Odd Position
36  77  90  193 

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

odList = [14, 35, 78, 90, 120, 67, 98]

print('Printing the List Items at Odd Position')
i = 0
while i < len(odList):
    print(odList[i], end = '  ')
    i = i + 2
Printing the List Items at Odd Position
14  78  120  98 

在本 Python 列表中奇數(shù)位置的項(xiàng)目示例中,for 循環(huán)從 0 迭代到列表長度。if 條件檢查索引位置除以二是否等于 0。如果為真,打印數(shù)字。

import numpy as np

odlist = []
odListTot = int(input("Total List Items to enter = "))

for i in range(1, odListTot + 1):
    odListvalue = int(input("Please enter the %d List Item = "  %i))
    odlist.append(odListvalue)

print('\nPrinting the List Items at Odd Position')
for i in range(0, len(odlist), 2):
    print(odlist[i], end = '  ')

print('\nPrinting the List Items at Odd Position')
for i in range(len(odlist)):
    if i % 2 == 0:
        print(odlist[i], end = '  ')
Total List Items to enter = 8
Please enter the 1 List Item = 14
Please enter the 2 List Item = 24
Please enter the 3 List Item = 34
Please enter the 4 List Item = 44
Please enter the 5 List Item = 54
Please enter the 6 List Item = 64
Please enter the 7 List Item = 74
Please enter the 8 List Item = 84

Printing the List Items at Odd Position
14  34  54  74  
Printing the List Items at Odd Position
14  34  54  74 

網(wǎng)頁名稱:Python程序:打印奇數(shù)位置的列表項(xiàng)
文章分享:http://m.5511xx.com/article/cdjdogd.html