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

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

新聞中心

這里有您想知道的互聯網營銷解決方案
Python程序:打印列表中元素

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

創(chuàng)新互聯建站-專業(yè)網站定制、快速模板網站建設、高性價比洛陽網站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式洛陽網站制作公司更省心,省錢,快速模板網站建設找我們,業(yè)務覆蓋洛陽地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

寫一個 Python 程序,用一個實例打印列表中的元素。

打印列表元素的 Python 程序示例 1

Python 打印功能自動打印列表中的元素。

# Python Program to print Elements in a List 

a = [10, 50, 60, 80, 20, 15]

print("Element in this List are : ")
print(a)
Element in this List are : 
[10, 50, 60, 80, 20, 15]

返回列表元素的 Python 程序示例 2

這個 python 程序同上。但是這次,我們使用 For Loop 來迭代列表中的每個元素,并打印該元素。這種方法對于使用這個 Python 索引位置改變單個項目非常有用。

# Python Program to print Elements in a List 

a = [10, 50, 60, 80, 20, 15]

print("Element in this List are : ")
for i in range(len(a)):
    print("Element at Position %d = %d" %(i, a[i]))
Element in this List are : 
Element at Position 0 = 10
Element at Position 1 = 50
Element at Position 2 = 60
Element at Position 3 = 80
Element at Position 4 = 20
Element at Position 5 = 15

顯示列表元素的 Python 程序示例 3

Python 打印函數還打印列表中的字符串元素。

# Python Program to print Elements in a List 

Fruits = ['Apple', 'Orange', 'Grape', 'Banana']

print("Element in this List are : ")
print(Fruits)

打印列表項輸出

Element in this List are : 
['Apple', 'Orange', 'Grape', 'Banana']

返回列表元素的 Python 程序示例 4

這個 Python 列表項目程序和上面的一樣。但是,我們使用 For 循環(huán)來迭代列表中的每個字符串元素。

# Python Program to print Elements in a List 

Fruits = ['Apple', 'Orange', 'Grape', 'Banana']

print("Element in this List are : ")
for fruit in Fruits:
    print(fruit)
Element in this List are : 
Apple
Orange
Grape
Banana

顯示列表元素的 Python 程序示例 5

這個 Python 程序允許用戶輸入任意整數值,是一個 List 的長度。接下來,我們使用 For 循環(huán)向列表中添加數字。

# Python Program to print Elements in a List 

NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
    value = int(input("Please enter the Value of %d Element : " %i))
    NumList.append(value)

for i in range(Number):
    print("The Element at index position %d = %d " %(i, NumList[i]))


網站欄目:Python程序:打印列表中元素
網頁網址:http://m.5511xx.com/article/cdjdjoe.html