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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:訪問列表索引和值

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

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計、做網(wǎng)站服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)灌南免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

編寫一個 Python 程序來訪問列表的索引和值。在 Python 中,列表項是基于索引值組織的。因此,我們可以使用索引來訪問每個列表項或值。在這個 Python 示例中,for 循環(huán) range (for i in range(len(orgList))迭代列表項,打印雄蕊在每個索引位置打印值。

# Access List Index and Values

orgList = [10, 20, 30, 40, 50]

print("List Index and Values are")
for i in range(len(orgList)):
    print("Index Number = ", i, " and Value = ", orgList[i])

使用枚舉訪問列表索引和值的 Python 程序

# Access List Index and Values

orgList = [2, 4, 6, 8, 10, 12]

print("List Index and Values are")
for index, value in enumerate(orgList):
    print("Index Number = ", index, " and Value = ", value)

Python 使用枚舉輸出訪問列表索引和值

List Index and Values are
Index Number =  0  and Value =  2
Index Number =  1  and Value =  4
Index Number =  2  and Value =  6
Index Number =  3  and Value =  8
Index Number =  4  and Value =  10
Index Number =  5  and Value =  12

在這個 Python 示例中,我們使用列表理解來訪問和返回列表項或值以及相應(yīng)的索引位置。

# Access List Index and Values

orgList = [13, 43, 56, 78, 65]

list2 = ([list((i, orgList[i])) for i in range(len(orgList))])
print("List Index and Values are")
print(list2)

list3 = ([(i, orgList[i]) for i in range(len(orgList))])
print("List Index and Values are")
print(list3)

Python 使用列表理解輸出來訪問列表索引和值

List Index and Values are
[[0, 13], [1, 43], [2, 56], [3, 78], [4, 65]]
List Index and Values are
[(0, 13), (1, 43), (2, 56), (3, 78), (4, 65)]

這個 Python 程序使用 zip 、 range 和 len 函數(shù)來返回列表索引和值。

# Access List Index and Values

orgList = [22, 44, 66, 88, 122]

print("List Index and Values are")
for index, value in zip(range(len(orgList)), orgList):
    print("Index Number = ", index, " and Value = ", value)

Python 使用 zip、range 和 len 函數(shù)輸出來訪問列表值和索引號

List Index and Values are
Index Number =  0  and Value =  22
Index Number =  1  and Value =  44
Index Number =  2  and Value =  66
Index Number =  3  and Value =  88
Index Number =  4  and Value =  122

分享題目:Python程序:訪問列表索引和值
文章地址:http://www.5511xx.com/article/dpcohhg.html