Python - Loop Lists
Python - Loop Lists
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
Python HOME
Python Intro
Python Get Started
Python Syntax
Python Comments
Python Variables
Python - Loop Lists
Python Data Types ❮ Previous Next ❯
Python Numbers
Python Casting
Python Strings
Python Booleans Loop Through a List
Python Operators
Python Lists You can loop through the list items by using a for loop:
Python Lists
Sort Lists
Try it Yourself »
Copy Lists
Join Lists
Learn more about for loops in our Python For Loops Chapter.
Example
Print all items by referring to their index number: COLOR PICKER
thislist = ["apple", "banana", "cherry"]
for i in range(len(thislist)):
print(thislist[i])
ADVERTISEMENT
Use the len() function to determine the length of the list, then start at 0 and loop your way through the list items by referring
to their indexes.
ADVERTISEMENT
Example
Print all items, using a while loop to go through all the index numbers
Try it Yourself »
Learn more about while loops in our Python While Loops Chapter.
Example
A short hand for loop that will print all items in a list:
Try it Yourself »
Learn more about list comprehension in the next chapter: List Comprehension.
ADVERTISEMENT
ADVERTISEMENT
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.