9:59:59.000,9:59:59.000 1[br]00:00:04,960 --> 00:00:10,270[br]Well, in this video, I'm going to talk with you about some of the basic control structures that we have 9:59:59.000,9:59:59.000 2[br]00:00:10,270 --> 00:00:21,050[br]in Python and the syntax that Python uses for indicating different pieces of code. 9:59:59.000,9:59:59.000 3[br]00:00:21,050 --> 00:00:25,490[br]The learning outcomes for this video are for you to be able to write basic python control structures. 9:59:59.000,9:59:59.000 4[br]00:00:25,490 --> 00:00:32,180[br]Understand the python block syntax. No, the standard practice for using whitespace in Python. 9:59:59.000,9:59:59.000 5[br]00:00:32,180 --> 00:00:38,990[br]One of the key concepts here is that Python uses whitespace to detect blocks such as the bodies of loops or conditionals. 9:59:59.000,9:59:59.000 6[br]00:00:38,990 --> 00:00:45,860[br]Unlike other languages such as Java, JavaScript, HPC, etc., all use squiggly braces. 9:59:59.000,9:59:59.000 7[br]00:00:45,860 --> 00:00:56,090[br]Python uses indentation as syntactically significant indicator of what a block is, such as the body of a loop. 9:59:59.000,9:59:59.000 8[br]00:00:56,090 --> 00:01:03,830[br]So in the first Python intro video, we saw a for loop in the for loop iterates over it iterable. 9:59:59.000,9:59:59.000 9[br]00:01:03,830 --> 00:01:11,060[br]So you the, the, the syntax is that we have for ie the variable name in. 9:59:59.000,9:59:59.000 10[br]00:01:11,060 --> 00:01:17,540[br]Range of music range here, but this is the iterable expression. 9:59:59.000,9:59:59.000 11[br]00:01:17,540 --> 00:01:27,770[br]That's something that we can we can loop over and then within within that loop, we are going to we're gonna print and we're using an F string. 9:59:59.000,9:59:59.000 12[br]00:01:27,770 --> 00:01:32,630[br]Remember the F string that says use variables in the string. 9:59:59.000,9:59:59.000 13[br]00:01:32,630 --> 00:01:41,480[br]And so we are we're printing out the iteration number through each iteration of this loop. 9:59:59.000,9:59:59.000 14[br]00:01:41,480 --> 00:01:46,360[br]And then at the end of the loop, we're gonna print done, and that's gonna happen once. 9:59:59.000,9:59:59.000 15[br]00:01:46,360 --> 00:01:52,440[br]Because whitespace still limits blocks. 9:59:59.000,9:59:59.000 16[br]00:01:52,440 --> 00:02:00,400[br]The colon and the and the indentation, they indicate that we're in a new block. 9:59:59.000,9:59:59.000 17[br]00:02:00,400 --> 00:02:06,200[br]And then when the indentation stops and it goes back out to the same level. 9:59:59.000,9:59:59.000 18[br]00:02:06,200 --> 00:02:12,220[br]As the for loop started, that indicates the end of the block. 9:59:59.000,9:59:59.000 19[br]00:02:12,220 --> 00:02:17,710[br]So, as I said, the python block begins with a colon at the end of the line. 9:59:59.000,9:59:59.000 20[br]00:02:17,710 --> 00:02:26,020[br]And there's several different python keywords that. Are something that can start a block the if family f. 9:59:59.000,9:59:59.000 21[br]00:02:26,020 --> 00:02:36,610[br]Else L.F., the loop's foreign while and then the keywords for defining functions and classes, def and class block contents indented one level. 9:59:59.000,9:59:59.000 22[br]00:02:36,610 --> 00:02:40,390[br]The standard practice here is to use force bases. 9:59:59.000,9:59:59.000 23[br]00:02:40,390 --> 00:02:47,830[br]Jupiter, along with most modern python editing environments, default their configuration to force spaces for you automatically. 9:59:59.000,9:59:59.000 24[br]00:02:47,830 --> 00:02:51,970[br]But this convention, while Python does not strictly mandate this. 9:59:59.000,9:59:59.000 25[br]00:02:51,970 --> 00:02:58,700[br]All it mandates is that you are consistent. You can't say mixed tabs and spaces in the same file. 9:59:59.000,9:59:59.000 26[br]00:02:58,700 --> 00:03:03,670[br]This almost universally standard python practice is to indent with four spaces 9:59:59.000,9:59:59.000 27[br]00:03:03,670 --> 00:03:12,040[br]and then the block ends when the indentation returns to the previous level. 9:59:59.000,9:59:59.000 28[br]00:03:12,040 --> 00:03:17,410[br]You can also have comments in Python, a comment begins with a hash and continues until the end of the line. 9:59:59.000,9:59:59.000 29[br]00:03:17,410 --> 00:03:24,700[br]You can have a car line where all it is is a comment. You can also put a comment at the end of a line that contains some code. 9:59:59.000,9:59:59.000 30[br]00:03:24,700 --> 00:03:25,990[br]When we're writing Jupiter notebooks, 9:59:59.000,9:59:59.000 31[br]00:03:25,990 --> 00:03:34,360[br]we're going to put a lot of the discussion and the explanation in markdown cells in the Jupiter notebook rather than in comments. 9:59:59.000,9:59:59.000 32[br]00:03:34,360 --> 00:03:39,040[br]But comments are very useful when you're when you start writing Python scripts. 9:59:59.000,9:59:59.000 33[br]00:03:39,040 --> 00:03:42,970[br]They're also useful when you want when you want to write. 9:59:59.000,9:59:59.000 34[br]00:03:42,970 --> 00:03:50,860[br]Just really briefly, why a particular line in one of your code cells is working the way that it's working? 9:59:59.000,9:59:59.000 35[br]00:03:50,860 --> 00:03:54,370[br]The if statement is structure. 9:59:59.000,9:59:59.000 36[br]00:03:54,370 --> 00:03:58,180[br]It works like the fourth statement in terms of how the blocks work. 9:59:59.000,9:59:59.000 37[br]00:03:58,180 --> 00:04:03,040[br]And we open with if we don't need any parentheses, we have F and we have an expression in this case, 9:59:59.000,9:59:59.000 38[br]00:04:03,040 --> 00:04:13,150[br]we're gonna say if X is greater than or equal to 10, then we're one to print big if Elif is the python else. 9:59:59.000,9:59:59.000 39[br]00:04:13,150 --> 00:04:20,200[br]If you can have as many of these as you want and if you don't have to have one, you don't have to have an else either. 9:59:59.000,9:59:59.000 40[br]00:04:20,200 --> 00:04:28,090[br]But it's not else F or else, if it's just L.F. e-Life is the python syntax for else F. 9:59:59.000,9:59:59.000 41[br]00:04:28,090 --> 00:04:33,460[br]So if it's not greater than 10 but it is greater than or equal to five, it's going to print medium. 9:59:59.000,9:59:59.000 42[br]00:04:33,460 --> 00:04:37,780[br]And that's the one we're actually going to run in this case because X is equal to five. 9:59:59.000,9:59:59.000 43[br]00:04:37,780 --> 00:04:45,940[br]And then finally. Else we're going to print small. So in Python there are several things that are considered false. 9:59:59.000,9:59:59.000 44[br]00:04:45,940 --> 00:04:54,290[br]For the purpose. Most for the purposes of. Of an if statement. 9:59:59.000,9:59:59.000 45[br]00:04:54,290 --> 00:05:02,900[br]The bout valued the boolean value false, which you write with an uppercase F, is considered false as is none, which is a special python value. 9:59:59.000,9:59:59.000 46[br]00:05:02,900 --> 00:05:07,520[br]That is the python's version of a no means no data here. 9:59:59.000,9:59:59.000 47[br]00:05:07,520 --> 00:05:15,650[br]Zero is false. Empty containers, empty lists, sets, tuples and empty strings are all also false. 9:59:59.000,9:59:59.000 48[br]00:05:15,650 --> 00:05:21,980[br]Most other things are true. But those are the. 9:59:59.000,9:59:59.000 49[br]00:05:21,980 --> 00:05:26,600[br]Those are the. That's how ifs work in Python. They aren't strict like in Java. 9:59:59.000,9:59:59.000 50[br]00:05:26,600 --> 00:05:30,220[br]It has to be a boolean python does not require it to be a billion. 9:59:59.000,9:59:59.000 51[br]00:05:30,220 --> 00:05:38,990[br]It requires to be something that can be converted to a boolean. And then these are the things that. 9:59:59.000,9:59:59.000 52[br]00:05:38,990 --> 00:05:50,000[br]These are the things that Python converts to false when it's doing that boolean conversion a while loop iterates until a condition becomes false. 9:59:59.000,9:59:59.000 53[br]00:05:50,000 --> 00:05:56,240[br]I'd put a past statement here. The past is not part of the while loop. The past is just here to make the syntactically valid python. 9:59:59.000,9:59:59.000 54[br]00:05:56,240 --> 00:06:01,070[br]Because while loops can't be empty in general, Bloks cannot be empty. 9:59:59.000,9:59:59.000 55[br]00:06:01,070 --> 00:06:04,790[br]So passe is a python statement that does nothing. 9:59:59.000,9:59:59.000 56[br]00:06:04,790 --> 00:06:10,280[br]It's just needed when you need to make something syntactically valid. Maybe you're in the middle of testing some code. 9:59:59.000,9:59:59.000 57[br]00:06:10,280 --> 00:06:16,250[br]Maybe you're working on an F and you don't have all that figured out yet. So you just want to make one of the branches of the F. 9:59:59.000,9:59:59.000 58[br]00:06:16,250 --> 00:06:26,060[br]Do nothing. For now, you can just say pass. So to wrap up, Python provides the usual control control structures for a programing language. 9:59:59.000,9:59:59.000 59[br]00:06:26,060 --> 00:06:33,620[br]If for while blocks crucially are based on indentation and the standard there is to use for spaces. 9:59:59.000,9:59:59.000 60[br]00:06:33,620 --> 00:06:40,910[br]The hash sign starts a comment. There is some limitations to working with for loops. 9:59:59.000,9:59:59.000 61[br]00:06:40,910 --> 00:06:56,433[br]We're not going to use for work to working with, well, any loops in Python. 9:59:59.000,9:59:59.000