Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Python, you can create a loop using a variety of statements, but the most common are the for and while loops.

A for loop is used to iterate over a sequence (such as a list, tuple, or string) and execute a block of code for each item in the sequence. Here is an example of a for loop that prints each item in a list:

my_list = [1, 2, 3, 4, 5]
for item in my_list:
    print(item)

In Python, you can create a loop using a variety of statements, but the most common are the for and while loops.

A for loop is used to iterate over a sequence (such as a list, tuple, or string) and execute a block of code for each item in the sequence. Here is an example of a for loop that prints each item in a list:

my_list = [1, 2, 3, 4, 5]
for item in my_list:
    print(item)