What is a For Loop

Introduction to For Loops

What is a For Loop

🙋 Need help? Ask an expert now!

For Loops In Python

What is a For Loop in Python?

The Python for statement iterates over the members of a sequence in order, executing the block each time.

What does this mean? In the case of a list in python, this means that we are going through each value in the list. For example if we had a list like: [1,2,3,4,5], a for loop would iterate through each value. This means starting at the value of 1 and going to 5.

This is particularly important if you want to go through a bunch of data points, or take a specific action multiple times.

As soon as you see code that looks like it is repeating itself multiple times, you know that you have a candidate for a python for loop. It should make sense when you read a for loop and it should sound like plain english. For example to iterate through the list of numbers above, I would say out loud:

For Number in list….

Edit Me on GitHub!