Iterate over a list in Python Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Python provides several ways to iterate over list. The simplest and the most common way to iterate over a list is to use a for loop. This method allows us to access each element in the list directly.Example: Print all elements in the list one by one using for loop. Python a = [1, 3, 5, 7, 9] # On each iteration val # represents the current item/element for val in a: print(val) Output1 3 5 7 9 Let’s see other different ways to iterate over a list in Python.Table of ContentUsing For-Loop and Range() Method Using While-Loop Using Enumerate() Using List Comprehension Using Iter and Next FunctionsUsing for Loop with range() We can use the range() method with for loop to traverse the list. This method allow us to access elements by their index, which is useful if we need to know the position of an element or modify the list in place. Python a = [1, 3, 5, 7, 9] # Calculate the length of the list n = len(a) # Iterates over the indices from 0 to n-1 (i.e., 0 to 4) for i in range(n): print(a[i]) Output1 3 5 7 9 Using while LoopThis method is similar to the above method. Here we are using a while loop to iterate through a list. We first need to find the length of list using len(), then start at index 0 and access each item by its index then incrementing the index by 1 after each iteration. Python a = [1, 3, 5, 7, 9] # Start from the first index i = 0 # The loop runs till the last index (i.e., 4) while i < len(a): print(a[i]) i += 1 Output1 3 5 7 9 Using enumerate()We can also use the enumerate() function to iterate through the list. This method provides both the index (i) and the value (val) of each element during the loop. Python a = [1, 3, 5, 7, 9] # Here, i and val reprsents index and value respectively for i, val in enumerate(a): print (i, val) Output0 1 1 3 2 5 3 7 4 9 Using List Comprehension List comprehension is similar to for loop. It provides the shortest syntax for looping through list. Python a = [1, 3, 5, 7, 9] # On each iteration val is passed to print function # And printed in the console. [print(val) for val in a] Output1 3 5 7 9 Note: This method is not a recommended way to iterate through lists as it creates a new list (extra space).Related Articles:Iterate Over a List of Lists in PythonIterate Over a Numpy ArrayIterate over multiple lists simultaneouslyIterate through list without using the increment variable Iterate over a list in Python Comment More infoAdvertise with us U Uni_Omni Follow Improve Article Tags : Python python-list Python list-programs Practice Tags : pythonpython-list Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 6 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 6 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like