1
00:00:00,440 --> 00:00:04,220
You can do just about anything with each item in a for loop.

2
00:00:04,250 --> 00:00:10,610
Let's build the previous example by printing a message to each magician and telling them that they performed

3
00:00:10,610 --> 00:00:11,810
a great trick.

4
00:00:12,020 --> 00:00:19,550
Now, after that, inside the form, we will use the print magician format here again.

5
00:00:19,850 --> 00:00:22,220
So we will use a string format.

6
00:00:25,020 --> 00:00:28,560
And here we will magician that title.

7
00:00:28,890 --> 00:00:30,780
And after that we will use.

8
00:00:30,810 --> 00:00:36,420
Yeah, that was a great, great, great trick.

9
00:00:36,420 --> 00:00:36,930
Right?

10
00:00:36,960 --> 00:00:37,770
Trick.

11
00:00:38,100 --> 00:00:40,620
And the only difference in this code here.

12
00:00:41,460 --> 00:00:48,570
Here is where we compose a message to each magician, starting with the magician's name the first time

13
00:00:48,570 --> 00:00:49,380
through the loop.

14
00:00:49,380 --> 00:00:51,570
The value of a magician is Alice.

15
00:00:51,570 --> 00:00:55,590
So Python starts the first message with the name Alice.

16
00:00:55,740 --> 00:01:03,390
The second time, though, the message will begin with a David, and the third time the message will

17
00:01:03,420 --> 00:01:04,830
begin with Caroline.

18
00:01:05,910 --> 00:01:06,840
And the output.

19
00:01:06,840 --> 00:01:10,890
This is the personalized message for each magician and the list.

20
00:01:11,310 --> 00:01:14,490
You can also write as many lines of code as you like in the for loop.

21
00:01:14,760 --> 00:01:21,840
Every indented line following the line for magician in magicians like here.

22
00:01:24,380 --> 00:01:27,110
Considered inside the loop.

23
00:01:27,810 --> 00:01:33,450
And each indented line is executed once for each value in the list.

24
00:01:33,480 --> 00:01:37,560
Therefore, you can do as much work as you like with each value in the list.

25
00:01:37,590 --> 00:01:44,070
Let's add a second line to our message telling each magician that we are looking forward to their to

26
00:01:44,070 --> 00:01:45,120
do their next trick.

27
00:01:45,120 --> 00:01:49,500
So print here f format again.

28
00:01:49,500 --> 00:01:56,130
And now without these braces I or the.

29
00:01:56,800 --> 00:01:57,820
Weavers.

30
00:01:58,240 --> 00:02:06,010
Weavers can not wait to see your next trick.

31
00:02:06,270 --> 00:02:07,300
Dear.

32
00:02:08,230 --> 00:02:16,630
And after that we will enter the magician Magician title because as you remember, our magician names

33
00:02:16,630 --> 00:02:18,820
is written an underscore.

34
00:02:18,820 --> 00:02:22,120
So that's why we're going to write titles here.

35
00:02:22,630 --> 00:02:25,270
So magician dot title.

36
00:02:26,250 --> 00:02:27,060
That's it.

37
00:02:27,420 --> 00:02:29,940
And after that, we will use a new line.

38
00:02:29,940 --> 00:02:30,720
So.

39
00:02:35,310 --> 00:02:38,070
So because now let's rent.

40
00:02:38,370 --> 00:02:39,150
That's it.

41
00:02:40,810 --> 00:02:44,470
Because we have invented both calls to print.

42
00:02:44,500 --> 00:02:48,790
Each line will be executed once for every magicians in the list.

43
00:02:48,790 --> 00:02:52,300
And here the new line here.

44
00:02:52,720 --> 00:02:56,560
The new new line here in the second print.

45
00:02:56,740 --> 00:02:57,580
This is the print.

46
00:02:57,610 --> 00:02:59,020
This is the first print.

47
00:03:00,000 --> 00:03:01,200
This is the second print.

48
00:03:03,050 --> 00:03:03,920
This new line.

49
00:03:03,920 --> 00:03:10,640
The second brand calls insert a blank line after each pass pass through the loop.

50
00:03:10,850 --> 00:03:17,570
So here one new line, two new line, and the third new line is at the bottom here somewhere.

51
00:03:17,570 --> 00:03:18,050
Here.

52
00:03:18,850 --> 00:03:25,270
So this creates a set of messages that are neatly grouped for each person in the list here.

53
00:03:26,480 --> 00:03:29,630
You can use as many lines as you like in your for loops.

54
00:03:29,670 --> 00:03:34,760
In practice, you will often find it useful to do a number of different operations with each item in

55
00:03:34,760 --> 00:03:35,300
a list.

56
00:03:35,330 --> 00:03:38,420
When you use a for loop.

57
00:03:41,630 --> 00:03:44,890
So what happens once a for loop has finished executing?

58
00:03:44,900 --> 00:03:51,800
Usually you will want to summarize a block of output or move on to the other work that your your program

59
00:03:51,800 --> 00:03:53,000
must accomplish.

60
00:03:53,000 --> 00:03:59,540
Any lines of code after the for loop that are not indented are executed once without repetition.

61
00:03:59,570 --> 00:04:06,380
Let's write a thank you to the group of Magicians as a whole and thanking them for putting on an excellent

62
00:04:06,380 --> 00:04:06,770
show.

63
00:04:06,770 --> 00:04:09,530
So to display this, a group message.

64
00:04:09,650 --> 00:04:14,900
After all of the individual messages have been printed, we place a thank you message after the for

65
00:04:14,900 --> 00:04:17,360
loop without indentation.

66
00:04:17,750 --> 00:04:24,260
So now we just write Without indentation, we will press on the backspace.

67
00:04:24,260 --> 00:04:24,920
That's it.

68
00:04:24,950 --> 00:04:27,530
Now signs are crucial.

69
00:04:27,530 --> 00:04:28,970
Is here somewhere.

70
00:04:28,970 --> 00:04:33,530
Here we are out of the loop so we are not in the loop.

71
00:04:33,530 --> 00:04:39,770
So whenever whatever we write here, it will not count as loop here.

72
00:04:40,500 --> 00:04:41,070
Okay.

73
00:04:42,480 --> 00:04:43,860
So that's it.

74
00:04:43,890 --> 00:04:45,300
Now print.

75
00:04:46,350 --> 00:04:49,590
Thank you, everyone.

76
00:04:52,200 --> 00:04:59,280
Everyone for watching and especially for magicians.

77
00:05:02,280 --> 00:05:02,760
Split.

78
00:05:03,720 --> 00:05:05,370
Especially for magicians.

79
00:05:06,160 --> 00:05:09,310
That that was a.

80
00:05:10,400 --> 00:05:12,500
Spectacular spec.

81
00:05:13,550 --> 00:05:14,840
Tacular show.

82
00:05:16,430 --> 00:05:17,240
That's it.

83
00:05:18,260 --> 00:05:18,740
Here.

84
00:05:20,800 --> 00:05:22,360
Now let's run our code again.

85
00:05:24,680 --> 00:05:25,900
That's it.

86
00:05:25,910 --> 00:05:26,980
This is how it works.

87
00:05:26,990 --> 00:05:34,130
The first two cards to print are repeated once for each magicians in the list, as you saw earlier.

88
00:05:34,130 --> 00:05:41,570
However, because the last line is not indented, it's printed only once.

89
00:05:42,050 --> 00:05:42,560
Here.

90
00:05:44,310 --> 00:05:47,340
It's printed only once.

91
00:05:47,670 --> 00:05:48,240
Look at this.

92
00:05:51,970 --> 00:05:52,570
That's it.

93
00:05:54,970 --> 00:05:55,720
And.

94
00:05:56,940 --> 00:05:59,910
This is the output that we wrote here.

95
00:05:59,910 --> 00:06:05,430
And when you're processing data using a for loop, you will find that this is a good way to summarize

96
00:06:05,430 --> 00:06:09,330
an operation that was performed on an entire dataset.

97
00:06:09,360 --> 00:06:14,220
For example, you might use a for loop to initialize a game by running through the list of characters

98
00:06:14,220 --> 00:06:16,620
and displaying each character on the screen.

99
00:06:16,620 --> 00:06:23,160
And you might want to, you might want then write some additional code after the loop that displays

100
00:06:23,160 --> 00:06:23,580
a play.

101
00:06:23,580 --> 00:06:24,150
No button.

102
00:06:24,150 --> 00:06:26,550
After all the characters have been drawn to the screen.
