1 00:00:00,170 --> 00:00:06,000 It aeration is crucial in programming we do either patience to perform repeated actions in an automatic 2 00:00:06,000 --> 00:00:06,930 way. 3 00:00:06,930 --> 00:00:12,960 Imagine you have 1000 different text files on the site each textfile there are 2000 different values 4 00:00:13,140 --> 00:00:19,580 and you want to calculate the average of each of the 2000 values for each of the 1000 files. 5 00:00:19,950 --> 00:00:25,380 Well to do that you'd have to iterate through each file for each value inside each file. 6 00:00:25,380 --> 00:00:31,660 The good news here is that Python is excellent in doing iterations with just a few lines of code. 7 00:00:31,840 --> 00:00:36,130 A great tool to perform in durations in Python is for loop. 8 00:00:36,420 --> 00:00:41,970 We use the for loop every time we want to iterate through a list of items of the list. 9 00:00:42,060 --> 00:00:49,380 So imagine we have stored the names of the files we want to direct in our file is variable. 10 00:00:49,590 --> 00:00:51,890 Remember the file is variable. 11 00:00:51,900 --> 00:00:57,750 Now we want to just print out the file names on the screen one by one. 12 00:00:58,050 --> 00:01:00,400 To do that we should use iteration. 13 00:01:00,690 --> 00:01:03,880 Here is the syntax to do iterating. 14 00:01:04,110 --> 00:01:07,030 So for item in the file list. 15 00:01:07,320 --> 00:01:12,300 Print out the item and notice that we are using indentation. 16 00:01:12,300 --> 00:01:13,030 Here again. 17 00:01:13,080 --> 00:01:20,250 So what you are telling Python is OK for each item in the least print on the item and Python will do 18 00:01:20,250 --> 00:01:20,930 just that. 19 00:01:22,000 --> 00:01:29,360 It will go through each item and perform the action which in this case is printing the item on the screen. 20 00:01:30,010 --> 00:01:32,230 So we had a list of free items. 21 00:01:32,230 --> 00:01:36,780 Therefore there will be three iterations over the print function. 22 00:01:36,790 --> 00:01:40,520 Sometimes you might need to generate a list automatically automatically. 23 00:01:40,660 --> 00:01:44,520 Remember we had to write the items off on all of this one by one. 24 00:01:44,750 --> 00:01:47,070 But imagine if you had to write a long list. 25 00:01:47,080 --> 00:01:52,800 Let's say from two thousand fifty to three thousand fifteen I'll be very lazy to do that. 26 00:01:52,810 --> 00:01:58,400 But the good news is that there is almost always a way to Automattic or you're walking by them. 27 00:01:58,500 --> 00:02:05,350 In this case we could iterate through such a list of items using the range function. 28 00:02:05,470 --> 00:02:14,660 So again for item in range we are either the first item of a sequence last Suydam the step. 29 00:02:14,930 --> 00:02:20,850 So the step here is incrementing step below comes the action. 30 00:02:20,870 --> 00:02:22,390 You want to perform. 31 00:02:22,520 --> 00:02:26,790 Of course we can perform any action inside the loop and not just print. 32 00:02:26,890 --> 00:02:31,000 We can even do conditionals inside loops. 33 00:02:31,030 --> 00:02:33,390 Let's do one again. 34 00:02:33,430 --> 00:02:44,450 So for each item in the range this starts at 2015 and 2019 incrementing like 2 evil item is equal to 35 00:02:45,110 --> 00:02:46,460 2025. 36 00:02:46,540 --> 00:02:48,030 But in all of them. 37 00:02:48,590 --> 00:02:55,370 So we just told Python to go through each item of the range list and print only the item that is equal 38 00:02:55,640 --> 00:02:58,620 to 2025. 39 00:02:58,670 --> 00:03:04,140 We use indentation here again we don't have that statement because it depends on the follow up. 40 00:03:04,300 --> 00:03:11,500 We also intended the print function below because the print function depends on the if statement. 41 00:03:12,040 --> 00:03:19,210 So to follow up here is conditioned by the fact that the item has to be equal to the 25 for the print 42 00:03:19,220 --> 00:03:21,380 function to be executed. 43 00:03:22,190 --> 00:03:26,260 So there was some basic good information about iterations. 44 00:03:26,350 --> 00:03:28,190 You'll have more about it you know next.