Home  >  Article  >  Backend Development  >  How to loop through a list in python

How to loop through a list in python

尚
Original
2019-06-29 12:18:449108browse

How to loop through a list in python

You can use a for loop to traverse the list

In order to output each data in the list more efficiently, you can use a loop to complete

Example:

In [3]: list1=["zhang","qing","123",123,"zhang123"In [4]: for temp in list1:
   ...:     print("遍历list1=%s"%temp)
遍历list1=zhang
遍历list1=qing
遍历list1=123
遍历list1=123
遍历list1=zhang123

How to loop through a list in python

You can also use while loop

In [9]: list1=["zhang","qing","123",345
In [10]: i=0
In [11]: while i<len(list1):
   ....:     print(list1[i])
   ....:     i+=1
   ....:    
zhang
qing
123
345

How to loop through a list in python

##For more Python related technical articles, please visit

Python tutorial column for learning!

The above is the detailed content of How to loop through a list in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn