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