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 .
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 .
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 .
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 .
1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial
The above is about python List traversal related knowledge , You can refer to it , Relevant knowledge will be continuously updated later , Make progress together .