You can do just about anything with each item in a for loop.
Let's build the previous example by printing a message to each magician and telling them that they performed
a great trick.
Now, after that, inside the form, we will use the print magician format here again.
So we will use a string format.
And here we will magician that title.
And after that we will use.
Yeah, that was a great, great, great trick.
Right?
Trick.
And the only difference in this code here.
Here is where we compose a message to each magician, starting with the magician's name the first time
through the loop.
The value of a magician is Alice.
So Python starts the first message with the name Alice.
The second time, though, the message will begin with a David, and the third time the message will
begin with Caroline.
And the output.
This is the personalized message for each magician and the list.
You can also write as many lines of code as you like in the for loop.
Every indented line following the line for magician in magicians like here.
Considered inside the loop.
And each indented line is executed once for each value in the list.
Therefore, you can do as much work as you like with each value in the list.
Let's add a second line to our message telling each magician that we are looking forward to their to
do their next trick.
So print here f format again.
And now without these braces I or the.
Weavers.
Weavers can not wait to see your next trick.
Dear.
And after that we will enter the magician Magician title because as you remember, our magician names
is written an underscore.
So that's why we're going to write titles here.
So magician dot title.
That's it.
And after that, we will use a new line.
So.
So because now let's rent.
That's it.
Because we have invented both calls to print.
Each line will be executed once for every magicians in the list.
And here the new line here.
The new new line here in the second print.
This is the print.
This is the first print.
This is the second print.
This new line.
The second brand calls insert a blank line after each pass pass through the loop.
So here one new line, two new line, and the third new line is at the bottom here somewhere.
Here.
So this creates a set of messages that are neatly grouped for each person in the list here.
You can use as many lines as you like in your for loops.
In practice, you will often find it useful to do a number of different operations with each item in
a list.
When you use a for loop.
So what happens once a for loop has finished executing?
Usually you will want to summarize a block of output or move on to the other work that your your program
must accomplish.
Any lines of code after the for loop that are not indented are executed once without repetition.
Let's write a thank you to the group of Magicians as a whole and thanking them for putting on an excellent
show.
So to display this, a group message.
After all of the individual messages have been printed, we place a thank you message after the for
loop without indentation.
So now we just write Without indentation, we will press on the backspace.
That's it.
Now signs are crucial.
Is here somewhere.
Here we are out of the loop so we are not in the loop.
So whenever whatever we write here, it will not count as loop here.
Okay.
So that's it.
Now print.
Thank you, everyone.
Everyone for watching and especially for magicians.
Split.
Especially for magicians.
That that was a.
Spectacular spec.
Tacular show.
That's it.
Here.
Now let's run our code again.
That's it.
This is how it works.
The first two cards to print are repeated once for each magicians in the list, as you saw earlier.
However, because the last line is not indented, it's printed only once.
Here.
It's printed only once.
Look at this.
That's it.
And.
This is the output that we wrote here.
And when you're processing data using a for loop, you will find that this is a good way to summarize
an operation that was performed on an entire dataset.
For example, you might use a for loop to initialize a game by running through the list of characters
and displaying each character on the screen.
And you might want to, you might want then write some additional code after the loop that displays
a play.
No button.
After all the characters have been drawn to the screen.