How to loop through a list in python

Release: 2019-07-08 09:16:20
Original
9106 people have browsed it

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!