程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Traversal of Python based list

編輯:Python

About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .


One 、 background

Python Is an easy to learn 、 Powerful programming language . It provides an efficient high-level data structure , It's also a simple and effective way of object-oriented programming .Python Elegant grammar and dynamic typing and the essence of interpretive language , Make it an ideal language for scripting and rapid application development on most platforms . Now let's introduce python List traversal related knowledge .


Two 、while Loop through the list

Use while Loop through the list , First, you need to get the length of the list , Take the length of the obtained list as while The judgment condition of cycle . example : Use while Loop through the list .

animal = ['elephant', 'monkey', 'snake', 'tiger'] # Create a list of animal
length = len(animal) # Gets the length of the list assigned to length
i = 0 # Loop traversal i The initial value is 0
while i < length: # When i Less than length Time cycle
print(animal[i]) # Output list element
i += 1 # Cyclic variable plus 1

give the result as follows .


3、 ... and 、for Loop through the list

Use for The way to loop through the list is very simple , Just use the list to be traversed as for A sequence of expressions in a loop . example : Use for Loop through the list .

animal = ['elephant', 'monkey', 'snake', 'tiger'] # Create a list of animal
for name in animal: # Take the list to be traversed as for A sequence in a circular expression
print(name) # Output name

give the result as follows .


Four 、 Reference resources

1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial


5、 ... and 、 summary

The above is about python List traversal related knowledge , You can refer to it , Relevant knowledge will be continuously updated later , Make progress together .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved