It aeration is crucial in programming we do either patience to perform repeated actions in an automatic
way.
Imagine you have 1000 different text files on the site each textfile there are 2000 different values
and you want to calculate the average of each of the 2000 values for each of the 1000 files.
Well to do that you'd have to iterate through each file for each value inside each file.
The good news here is that Python is excellent in doing iterations with just a few lines of code.
A great tool to perform in durations in Python is for loop.
We use the for loop every time we want to iterate through a list of items of the list.
So imagine we have stored the names of the files we want to direct in our file is variable.
Remember the file is variable.
Now we want to just print out the file names on the screen one by one.
To do that we should use iteration.
Here is the syntax to do iterating.
So for item in the file list.
Print out the item and notice that we are using indentation.
Here again.
So what you are telling Python is OK for each item in the least print on the item and Python will do
just that.
It will go through each item and perform the action which in this case is printing the item on the screen.
So we had a list of free items.
Therefore there will be three iterations over the print function.
Sometimes you might need to generate a list automatically automatically.
Remember we had to write the items off on all of this one by one.
But imagine if you had to write a long list.
Let's say from two thousand fifty to three thousand fifteen I'll be very lazy to do that.
But the good news is that there is almost always a way to Automattic or you're walking by them.
In this case we could iterate through such a list of items using the range function.
So again for item in range we are either the first item of a sequence last Suydam the step.
So the step here is incrementing step below comes the action.
You want to perform.
Of course we can perform any action inside the loop and not just print.
We can even do conditionals inside loops.
Let's do one again.
So for each item in the range this starts at 2015 and 2019 incrementing like 2 evil item is equal to
2025.
But in all of them.
So we just told Python to go through each item of the range list and print only the item that is equal
to 2025.
We use indentation here again we don't have that statement because it depends on the follow up.
We also intended the print function below because the print function depends on the if statement.
So to follow up here is conditioned by the fact that the item has to be equal to the 25 for the print
function to be executed.
So there was some basic good information about iterations.
You'll have more about it you know next.