How to use a for loop in Python to print out a list

You can use a for loop to iterate through a list, and then use the print function to output each element of the list. Here is an example:

my_list = [1, 2, 3, 4, 5]

for item in my_list:
    print(item)

Output:

1
2
3
4
5

In the above example, a for loop iterates through the list my_list, assigns each element to the variable item, and then uses the print function to output the value of item.

bannerAds