1 00:00:06,930 --> 00:00:09,620 - Welcome to lesson three, control statements. 2 00:00:09,620 --> 00:00:11,260 One of the things that you're going to see 3 00:00:11,260 --> 00:00:12,670 as you get into Python 4 00:00:12,670 --> 00:00:15,040 is that it's a smaller programming language 5 00:00:15,040 --> 00:00:17,700 than some of the other C-based languages 6 00:00:17,700 --> 00:00:19,720 you may be familiar with. 7 00:00:19,720 --> 00:00:21,370 You'll start to see that here 8 00:00:21,370 --> 00:00:23,290 in the control statements lesson 9 00:00:23,290 --> 00:00:25,950 because we have fewer overall control statements 10 00:00:25,950 --> 00:00:28,950 than we do in those other programming languages. 11 00:00:28,950 --> 00:00:31,260 Here we're going to start out by taking a look 12 00:00:31,260 --> 00:00:33,980 at the three different forms of the if statement; 13 00:00:33,980 --> 00:00:35,740 for making a single selection, 14 00:00:35,740 --> 00:00:37,870 for choosing between two different actions, 15 00:00:37,870 --> 00:00:41,170 or for choosing among many different actions. 16 00:00:41,170 --> 00:00:42,530 One of the things you'll notice 17 00:00:42,530 --> 00:00:44,720 as you look at the bullet points here 18 00:00:44,720 --> 00:00:47,840 is that you don't see anything called a switch statement 19 00:00:47,840 --> 00:00:50,200 or a select statement like you may have 20 00:00:50,200 --> 00:00:52,850 in some of those other programming languages. 21 00:00:52,850 --> 00:00:55,120 All of that is done in the context 22 00:00:55,120 --> 00:00:56,860 of the multiple selection 23 00:00:56,860 --> 00:00:59,880 if, elif, else statement. 24 00:00:59,880 --> 00:01:03,110 We do have some interesting pattern-matching capabilities 25 00:01:03,110 --> 00:01:05,430 that we can use with that in Python, 26 00:01:05,430 --> 00:01:07,640 which gives us all the features that we need 27 00:01:07,640 --> 00:01:11,210 from those statements in other programming languages. 28 00:01:11,210 --> 00:01:12,090 We're going to take a look 29 00:01:12,090 --> 00:01:13,960 at the augmented assignment operators 30 00:01:13,960 --> 00:01:15,220 as part of this lesson. 31 00:01:15,220 --> 00:01:16,860 You're probably familiar with things 32 00:01:16,860 --> 00:01:19,853 like += from other programming languages. 33 00:01:20,740 --> 00:01:23,030 Perhaps most importantly, we're going to take a look 34 00:01:23,030 --> 00:01:25,440 at the for statement in Python, 35 00:01:25,440 --> 00:01:29,500 which is for iterating over sequences of elements. 36 00:01:29,500 --> 00:01:34,050 Basically for each item in a sequence, do something. 37 00:01:34,050 --> 00:01:36,870 Unlike all of the other C-based programming languages, 38 00:01:36,870 --> 00:01:41,010 Python does not have a counter-controlled for loop. 39 00:01:41,010 --> 00:01:43,320 What we're going to do as we introduce the for loop 40 00:01:43,320 --> 00:01:45,750 is first, we're going to share you how to iterate 41 00:01:45,750 --> 00:01:48,880 over a sequence, like the characters in a string, 42 00:01:48,880 --> 00:01:51,510 and we'll also introduce as part of this lesson 43 00:01:51,510 --> 00:01:55,250 for the first time, the Python list data structure. 44 00:01:55,250 --> 00:01:58,240 We'll iterate through items in a list, 45 00:01:58,240 --> 00:02:00,100 but we're also going to demonstrate 46 00:02:00,100 --> 00:02:03,200 how you can generate a sequence of numbers, 47 00:02:03,200 --> 00:02:05,200 which is how you would, in turn, 48 00:02:05,200 --> 00:02:07,740 do counter-controlled iteration. 49 00:02:07,740 --> 00:02:10,220 There's a nice built-in function called range 50 00:02:10,220 --> 00:02:13,380 which is capable of generating sequences of integers. 51 00:02:13,380 --> 00:02:16,690 If I wanted, for example, to do a test 10 times, 52 00:02:16,690 --> 00:02:20,360 I could say to do that for each of the elements 53 00:02:20,360 --> 00:02:23,280 in a range of integers from zero through nine, 54 00:02:23,280 --> 00:02:25,160 just as a for example. 55 00:02:25,160 --> 00:02:28,080 We'll also demonstrate sentinel-controlled repetition 56 00:02:28,080 --> 00:02:31,500 in the context of the while repetition structure. 57 00:02:31,500 --> 00:02:32,870 You will notice, by the way, 58 00:02:32,870 --> 00:02:36,860 that you do not have a do while statement 59 00:02:36,860 --> 00:02:40,400 as you do in many other programming languages. 60 00:02:40,400 --> 00:02:42,450 We'll introduce the boolean operators here. 61 00:02:42,450 --> 00:02:44,880 We have the and operator, the or operator, 62 00:02:44,880 --> 00:02:46,220 and the not operator. 63 00:02:46,220 --> 00:02:49,480 Those are all keywords of the language in Python. 64 00:02:49,480 --> 00:02:51,580 They're not symbols like many of the other 65 00:02:51,580 --> 00:02:53,710 C-based programming languages. 66 00:02:53,710 --> 00:02:56,100 We'll introduce the break and continue statements, 67 00:02:56,100 --> 00:02:58,270 which work exactly the same way as they do 68 00:02:58,270 --> 00:03:00,340 in the other C-based languages. 69 00:03:00,340 --> 00:03:03,970 However, unlike things like Java and C# 70 00:03:03,970 --> 00:03:06,750 where you have labeled break and continue statements, 71 00:03:06,750 --> 00:03:08,240 we do not have those 72 00:03:08,240 --> 00:03:10,780 in the Python programming language. 73 00:03:10,780 --> 00:03:13,010 Finally, we'll take a look at a table 74 00:03:13,010 --> 00:03:15,830 of the functional-style programming capabilities 75 00:03:15,830 --> 00:03:18,640 that we'll be presenting in subsequent lessons 76 00:03:18,640 --> 00:03:20,740 and where you'll encounter those 77 00:03:20,740 --> 00:03:22,943 in those subsequent lessons as well.