1 00:00:00,340 --> 00:00:03,760 Now, we're going to talk a little bit about Python. 2 00:00:05,470 --> 00:00:07,690 Python is a programming language. 3 00:00:07,690 --> 00:00:10,640 Python is a way that we communicate. 4 00:00:11,640 --> 00:00:14,410 Now Python wasn't invented by computers. 5 00:00:14,410 --> 00:00:19,820 We invented Python as humans as a way to encapsulate our instructions. 6 00:00:19,820 --> 00:00:21,690 And there's lots of different programming languages. 7 00:00:21,690 --> 00:00:26,120 Python, Javascript, C++, tons of them. 8 00:00:26,120 --> 00:00:28,470 Python's just one of them that we happen to teach in this class. 9 00:00:31,020 --> 00:00:33,560 Now, I'll start with a little Harry Potter reference. 10 00:00:33,560 --> 00:00:37,179 Parseltongue is the language of serpents and those who converse with them. 11 00:00:38,650 --> 00:00:42,120 An individual who can speak Parseltongue is known as a Parselmouth. 12 00:00:42,120 --> 00:00:45,350 And it's a very uncommon skill, and it may be even hereditary. 13 00:00:45,350 --> 00:00:49,580 Nearly all known Parselmouths are descended from Salazar Slytherin. 14 00:00:49,580 --> 00:00:51,950 There's our Harry Potter reference. 15 00:00:51,950 --> 00:00:54,830 Python is the language of the Python 16 00:00:54,830 --> 00:00:57,650 interpreter, and those who can converse with it. 17 00:00:57,650 --> 00:01:01,210 We're going to converse with the inside of a computer pretty soon. 18 00:01:01,210 --> 00:01:04,980 An individual who can speak Python is known as a Pythonista. 19 00:01:04,980 --> 00:01:07,340 It is an uncommon skill and may be hereditary. 20 00:01:08,450 --> 00:01:10,120 It may not be hereditary too. 21 00:01:10,120 --> 00:01:15,480 Nearly all known Pythonistas use software initially developed by Guido van Rossum. 22 00:01:15,480 --> 00:01:18,150 Guido van Rossum, this guy right here. 23 00:01:18,150 --> 00:01:20,390 Yo Guido, what's up? 24 00:01:20,390 --> 00:01:22,860 Let's put a mustache on, yo Guido. 25 00:01:22,860 --> 00:01:23,350 Sorry. 26 00:01:23,350 --> 00:01:24,690 I should be nice to him. 27 00:01:24,690 --> 00:01:26,190 He is the inventor of Python. 28 00:01:26,190 --> 00:01:28,430 Python's over 20 years old. 29 00:01:28,430 --> 00:01:33,330 He invented it to make it an easy language but was both easy and powerful. 30 00:01:33,330 --> 00:01:37,640 And that's why it's a great language to start your learning with. 31 00:01:37,640 --> 00:01:41,680 It's a powerful language but it's also designed to be easy to use. 32 00:01:41,680 --> 00:01:47,088 Can anyone guess what the reason for the Python language name is? 33 00:01:47,088 --> 00:01:56,072 [BLANK_AUDIO] 34 00:01:56,072 --> 00:02:01,695 So let's see. 35 00:02:01,695 --> 00:02:04,200 [MUSIC] 36 00:02:04,200 --> 00:02:09,912 Python was named after a famous British comedy show that was in the 60s and 70s 37 00:02:09,912 --> 00:02:16,250 and 80s, I think, named Monty Python, Monty Python's Flying Circus. 38 00:02:16,250 --> 00:02:17,640 And so 39 00:02:17,640 --> 00:02:20,100 And I, I think he was trying to capture a 40 00:02:20,100 --> 00:02:24,850 playfulness, a certain kind of silly fun aspect of Python. 41 00:02:24,850 --> 00:02:27,600 And and so there we go, enough of that. 42 00:02:27,600 --> 00:02:28,280 We done? 43 00:02:28,280 --> 00:02:31,380 Yeah, okay, the music's done now, thank heaven for that. 44 00:02:31,380 --> 00:02:38,750 Okay, so again this is a language and this Guido, he made it for us, he made choices. 45 00:02:38,750 --> 00:02:40,960 He said we're going to put a colon here. 46 00:02:40,960 --> 00:02:43,240 I think we should like indent this and do these things. 47 00:02:43,240 --> 00:02:44,880 And he, he's made choices. 48 00:02:44,880 --> 00:02:49,510 And [COUGH] and some languages have people like some different better than others. 49 00:02:49,510 --> 00:02:51,170 It's kind of an artistic choice. 50 00:02:51,170 --> 00:02:55,080 And, and I like to kind of equate this to 51 00:02:55,080 --> 00:02:59,170 learning a language to speak with people, with humans, you know. 52 00:03:00,690 --> 00:03:03,630 You know, when we're a baby we don't know how to talk and 53 00:03:03,630 --> 00:03:07,260 we start babbling, blah, blah, blah, blah, blah, blah. Maybe we just start crying. 54 00:03:07,260 --> 00:03:08,240 That's the first thing that we do. 55 00:03:10,870 --> 00:03:12,633 [SOUND] But we're like, we're like on this strange 56 00:03:12,633 --> 00:03:14,640 planet. We got to talk to this thing. 57 00:03:14,640 --> 00:03:16,000 So we have to learn its language. 58 00:03:16,000 --> 00:03:17,960 And we're not going to learn it right away. 59 00:03:17,960 --> 00:03:20,750 You don't go like, hey study all night and you know this language. 60 00:03:20,750 --> 00:03:22,530 There's no way you can do that. 61 00:03:22,530 --> 00:03:24,340 Although Rosetta Stone might be a good way to 62 00:03:24,340 --> 00:03:27,470 teach programming, maybe I should take some of their ideas. 63 00:03:30,100 --> 00:03:32,690 So, the thing that's different about learning a 64 00:03:32,690 --> 00:03:36,660 human language versus learning a programming language is that 65 00:03:36,660 --> 00:03:39,320 when we're learning a human language we're talking to 66 00:03:39,320 --> 00:03:41,510 a human, and they're going to do correction for us. 67 00:03:41,510 --> 00:03:43,050 So if 68 00:03:43,050 --> 00:03:48,380 if I say a word incorrectly, like," Mama-alah." 69 00:03:48,380 --> 00:03:48,630 Right? 70 00:03:48,630 --> 00:03:49,050 I don't know. 71 00:03:49,050 --> 00:03:50,800 That was pretty dumb. 72 00:03:50,800 --> 00:03:53,630 Someone listening says, oh, I know what he said, I know what he said. 73 00:03:53,630 --> 00:03:58,010 But Python and computers aren't really listening. 74 00:03:58,010 --> 00:03:59,130 They're kind of dumb. 75 00:03:59,130 --> 00:04:02,240 They can't really correct our mistakes for us 76 00:04:02,240 --> 00:04:06,100 because they don't know what we're trying to say, they really don't. 77 00:04:06,100 --> 00:04:06,990 They're very literal. 78 00:04:08,370 --> 00:04:10,600 And, so it is really common 79 00:04:12,900 --> 00:04:16,490 in the beginning to get upset. 80 00:04:16,490 --> 00:04:22,530 Because we say something we think is cute, and it says, syntax error. 81 00:04:22,530 --> 00:04:25,030 And we'd be like, okay let me try this. 82 00:04:25,030 --> 00:04:26,630 And it says, syntax error. 83 00:04:26,630 --> 00:04:29,010 And so we get this notion, and I had this problem when I was 84 00:04:29,010 --> 00:04:32,640 first programming, I was like, I would like, here's my program, do you like it? 85 00:04:32,640 --> 00:04:33,750 It would say, syntax error. 86 00:04:35,140 --> 00:04:39,640 Now, the problem is, they could reword the messages to be a little nicer 87 00:04:39,640 --> 00:04:42,310 perhaps, but the syntax error isn't really a 88 00:04:42,310 --> 00:04:44,750 judgment on you that says you're a failure. 89 00:04:44,750 --> 00:04:50,400 The syntax error is really saying, I, I don't know what you're saying. 90 00:04:50,400 --> 00:04:51,450 I'm confused. 91 00:04:51,450 --> 00:04:57,450 I only know a few things, and what you just said is not something I understand. 92 00:04:57,450 --> 00:05:01,800 So instead of thinking of the program, the Python as some kind of 93 00:05:01,800 --> 00:05:07,620 evil, demonic monster that just hates you and just keeps saying syntax error, 94 00:05:07,620 --> 00:05:10,220 think of Python more like a dog. 95 00:05:11,470 --> 00:05:14,700 Right, the dog's, what can you talk to a dog? 96 00:05:14,700 --> 00:05:19,110 Can you say "lovely sunset we're having" to a dog? 97 00:05:19,110 --> 00:05:21,380 Because the dog's not going to understand that. 98 00:05:21,380 --> 00:05:25,270 The dog does understand some things like food, 99 00:05:25,270 --> 00:05:26,280 back, walk. 100 00:05:26,280 --> 00:05:29,700 But it doesn't understand the accumulated works of Shakespeare. 101 00:05:30,800 --> 00:05:33,400 So when you talk to a dog, you've gotta be careful 102 00:05:33,400 --> 00:05:36,920 to talk the subset of the vocabulary that the dog knows. 103 00:05:36,920 --> 00:05:40,750 And so this is a key thing when you're first learning. 104 00:05:41,920 --> 00:05:44,580 There's only a certain set of things that Python understands. 105 00:05:44,580 --> 00:05:48,370 It turns out it's easier to teach you Python 106 00:05:48,370 --> 00:05:50,940 than to teach Python to listen to whatever you have to say. 107 00:05:52,260 --> 00:05:54,430 Things like Google make it seem intelligent. 108 00:05:54,430 --> 00:05:58,010 So you can kind of type anything into Google, right? 109 00:05:58,010 --> 00:06:00,150 Well, yeah, billions of dollars later 110 00:06:00,150 --> 00:06:02,370 Google, for at least, like, short things, can 111 00:06:02,370 --> 00:06:04,210 seem like it knows what you're talking about. 112 00:06:06,080 --> 00:06:08,720 In terms of programming, it's a lot easier for you to 113 00:06:08,720 --> 00:06:12,130 figure out the exact precise way to say it, rather than make 114 00:06:12,130 --> 00:06:14,710 it so that we have to spend a billion dollars on 115 00:06:14,710 --> 00:06:18,100 something like Python to figure out what you mean in your programs. 116 00:06:18,100 --> 00:06:21,590 So, let's start talking to Python. 117 00:06:22,750 --> 00:06:24,420 We're talking to Python. 118 00:06:24,420 --> 00:06:25,320 So. 119 00:06:25,320 --> 00:06:28,240 If you've installed Python properly, whether it's on a 120 00:06:28,240 --> 00:06:32,390 Mac or a Windows or on a Raspberry Pi, at 121 00:06:32,390 --> 00:06:35,230 some point you'll be in a terminal program and 122 00:06:35,230 --> 00:06:39,160 you'll type Python to make Python run in interactive mode. 123 00:06:39,160 --> 00:06:43,060 You might have to type c:\ something something Python in Windows. 124 00:06:43,060 --> 00:06:45,580 But at some point you're running Python. 125 00:06:45,580 --> 00:06:49,280 Now Python itself is a program, it's a program 126 00:06:49,280 --> 00:06:52,760 that is asking you to type the Python language. 127 00:06:52,760 --> 00:06:55,500 Now the interesting thing is you've got this chevron prompt 128 00:06:55,500 --> 00:07:00,610 here, and it's kind of another version of "what's next?" 129 00:07:00,610 --> 00:07:03,000 I told you that this hardware was designed 130 00:07:03,000 --> 00:07:05,900 to always want the next instruction to come in. 131 00:07:05,900 --> 00:07:07,330 Well. 132 00:07:07,330 --> 00:07:10,510 Python, once we start it, it really has no idea what to do. 133 00:07:10,510 --> 00:07:13,090 It is, is waiting for you to tell it what to do. 134 00:07:13,090 --> 00:07:13,900 Okay? 135 00:07:13,900 --> 00:07:17,020 So, let me see if I can pop something up here. 136 00:07:18,600 --> 00:07:19,780 So here we go. 137 00:07:19,780 --> 00:07:20,210 Clear that. 138 00:07:20,210 --> 00:07:22,400 And now I'm going to type. 139 00:07:22,400 --> 00:07:25,480 Get this a little closer. 140 00:07:25,480 --> 00:07:27,280 I'm going to start Python, so it's the 141 00:07:27,280 --> 00:07:29,370 operating system now is asking me what next, 142 00:07:29,370 --> 00:07:32,680 I'm saying, oh the thing I want to do next is I want to run Python. 143 00:07:34,310 --> 00:07:36,090 So, here we are, we're sitting in 144 00:07:36,090 --> 00:07:39,340 the Python interpreter and it's asking "what next?" 145 00:07:41,270 --> 00:07:42,190 Okay? 146 00:07:42,190 --> 00:07:45,745 Now, I, it's like I just landed on a, on like a 147 00:07:45,745 --> 00:07:48,100 planet. 148 00:07:48,100 --> 00:07:48,660 And it's, like, 149 00:07:49,170 --> 00:07:54,065 take me to your leader. 150 00:07:54,065 --> 00:07:57,690 Take me to your leader. 151 00:07:57,690 --> 00:07:59,290 That's what you always say when you land on a 152 00:07:59,290 --> 00:08:01,950 planet and are confronted by some kind of a robot. 153 00:08:01,950 --> 00:08:04,140 And it says, 154 00:08:04,140 --> 00:08:04,980 Syntax error. 155 00:08:06,300 --> 00:08:07,470 Remember, it's a dog. 156 00:08:07,470 --> 00:08:08,970 It should just say aarf, right? 157 00:08:08,970 --> 00:08:12,080 Could say, take me to your leader, woof, okay? 158 00:08:15,610 --> 00:08:17,770 Are you friendly? 159 00:08:21,810 --> 00:08:24,490 I don't even spell, think I spelled friendly right. 160 00:08:24,490 --> 00:08:25,660 Syntax error. 161 00:08:30,740 --> 00:08:32,436 Are you dumb? 162 00:08:32,436 --> 00:08:35,726 Syntax error. 163 00:08:35,726 --> 00:08:38,563 Pretty dumb. 164 00:08:38,563 --> 00:08:41,344 I hate computers! 165 00:08:41,344 --> 00:08:46,330 [BLANK_AUDIO] 166 00:08:46,330 --> 00:08:47,870 Syntax error. 167 00:08:47,870 --> 00:08:50,460 It doesn't seem to have a sense of humor. 168 00:08:50,460 --> 00:08:50,910 Try this. 169 00:08:50,910 --> 00:08:51,630 Knock knock. 170 00:08:54,190 --> 00:08:54,800 Knock knock. 171 00:08:57,600 --> 00:08:59,380 No sense of humor. 172 00:09:00,580 --> 00:09:02,480 So here's the problem. 173 00:09:02,480 --> 00:09:04,390 It wants us, it's 174 00:09:04,390 --> 00:09:06,290 It doesn't hate us. 175 00:09:06,290 --> 00:09:09,060 It, it just wants to know what we want done. 176 00:09:10,800 --> 00:09:14,150 So, we need to know the Python language. 177 00:09:14,150 --> 00:09:16,320 Luckily, I know a bit of Python. 178 00:09:16,320 --> 00:09:21,230 So I'm going to say, hmm, hey Python, I'm going to want some data. 179 00:09:21,230 --> 00:09:23,620 I want to make a variable named "x". 180 00:09:23,620 --> 00:09:24,900 Just a little place in your memory. 181 00:09:24,900 --> 00:09:25,820 Go find it. 182 00:09:25,820 --> 00:09:29,080 Go find one of your spare places in memory. 183 00:09:29,080 --> 00:09:31,798 And I want you to put 100 in that. 184 00:09:31,798 --> 00:09:33,190 Okay? 185 00:09:33,190 --> 00:09:35,290 Do that. 186 00:09:35,290 --> 00:09:38,130 Now, it's happy because I know the language. 187 00:09:39,310 --> 00:09:40,099 Bonjour. 188 00:09:41,210 --> 00:09:42,850 That we know the language. 189 00:09:42,850 --> 00:09:44,370 Now I want to, but it's saying, "what next?" 190 00:09:44,370 --> 00:09:46,100 So we have to put a program in. 191 00:09:47,750 --> 00:09:49,230 So, let's see. 192 00:09:49,230 --> 00:09:51,730 I'm going to say, hey, Python. 193 00:09:51,730 --> 00:09:56,430 I'm going to make a variable called "y", another area in your memory labeled y, 194 00:09:56,430 --> 00:09:59,500 and I want you to go back and remember that x I gave you before? 195 00:09:59,500 --> 00:10:02,700 Go get that one back and add 50 to that. 196 00:10:02,700 --> 00:10:04,280 And put that in y. 197 00:10:04,280 --> 00:10:10,150 So now I've got something in x and I've got something in y, and let's print y out. 198 00:10:12,840 --> 00:10:13,910 What's in y? 199 00:10:13,910 --> 00:10:18,220 Go look in y where you put that and let's print it out. 200 00:10:18,220 --> 00:10:18,850 150. 201 00:10:18,850 --> 00:10:19,490 So. 202 00:10:20,690 --> 00:10:22,750 We're doing simple things, and actually most 203 00:10:22,750 --> 00:10:24,610 programming is a series of simple things. 204 00:10:24,610 --> 00:10:26,650 The number of statements, different statements 205 00:10:26,650 --> 00:10:30,020 you can do is is relatively few. 206 00:10:30,020 --> 00:10:32,470 So we are talking to Python. 207 00:10:34,010 --> 00:10:36,930 Let's run back to the slides, there we go. 208 00:10:36,930 --> 00:10:37,490 And so. 209 00:10:39,870 --> 00:10:42,010 We give it a series of commands and you 210 00:10:42,010 --> 00:10:44,380 can do the same thing sitting on your computer. 211 00:10:44,380 --> 00:10:47,050 And [SOUND] you type exit or quit with 212 00:10:47,050 --> 00:10:49,400 parentheses to get out of it when you're done. 213 00:10:49,400 --> 00:10:50,920 And that ends the interactive session. 214 00:10:50,920 --> 00:10:55,090 Now this is interactive Python where it's asking us command by command and 215 00:10:55,090 --> 00:10:57,410 then interpreting or running those commands as 216 00:10:57,410 --> 00:10:59,520 we run the command, as we finish. 217 00:10:59,520 --> 00:11:00,020 So. 218 00:11:01,130 --> 00:11:03,140 There'll be, you'll be doing it in some kind of a window. 219 00:11:03,140 --> 00:11:05,060 There's a different way to do it on Windows. 220 00:11:05,060 --> 00:11:08,140 My install documentation on pythonlearn.com gives you 221 00:11:08,140 --> 00:11:10,490 all of this, tells you everything to do. 222 00:11:10,490 --> 00:11:12,590 So now we're basically talking to Python. 223 00:11:13,730 --> 00:11:16,080 So, what language? 224 00:11:16,080 --> 00:11:17,600 I gotta still teach you this language. 225 00:11:19,140 --> 00:11:22,380 So, what do we say when we get ahold of Python, what kinds of things? 226 00:11:23,690 --> 00:11:28,530 Just like any language, a human language, there's like vocabulary, 227 00:11:28,530 --> 00:11:33,710 there's basic words, there's variables and reserved words in Python. 228 00:11:33,710 --> 00:11:36,190 Then we kind of combine those in lines to make 229 00:11:36,190 --> 00:11:39,630 sentence-like structures that themselves are not a full story. 230 00:11:39,630 --> 00:11:41,910 And then we kind of make a story out of it. 231 00:11:41,910 --> 00:11:45,420 Now, the story is in the Python language, not sort of English or 232 00:11:45,420 --> 00:11:49,680 French or a human language, but it still is kind of a 233 00:11:49,680 --> 00:11:52,430 a sequence of small pieces that build to make 234 00:11:52,430 --> 00:11:55,560 bigger pieces that then build to make a whole program. 235 00:11:55,560 --> 00:12:01,040 So here is, again, that same program, right? That same program 236 00:12:01,040 --> 00:12:04,440 of how to count the most common word in a file. 237 00:12:04,440 --> 00:12:07,810 And I mentioned before that it starts by opening the file. 238 00:12:07,810 --> 00:12:09,310 It reads the data from the file. 239 00:12:10,930 --> 00:12:13,350 Splits it into words, counts them all up and 240 00:12:13,350 --> 00:12:16,130 then finds the biggest one and then prints it out. 241 00:12:16,130 --> 00:12:21,240 So "name" is like a word, "equals" is another word, "raw" is a 242 00:12:21,240 --> 00:12:25,500 word, all these things are words, each of these things is like a sentence. 243 00:12:26,600 --> 00:12:29,450 There are blocks of stuff that are kind of paragraphs. 244 00:12:29,450 --> 00:12:32,000 There's kind of a paragraph, paragraph. 245 00:12:32,000 --> 00:12:34,150 I for sure, different color here. 246 00:12:34,150 --> 00:12:37,110 Here's like a paragraph, and a paragraph, and a 247 00:12:37,110 --> 00:12:39,830 paragraph, and then at the end of the day, once you 248 00:12:39,830 --> 00:12:42,300 kind of understand it, and you will understand this before 249 00:12:42,300 --> 00:12:45,690 it's all over, this is kind of like a story. 250 00:12:45,690 --> 00:12:45,890 Right? 251 00:12:45,890 --> 00:12:48,480 It holds together, it has a beginning, a middle, and an end. 252 00:12:49,730 --> 00:12:50,820 Again. 253 00:12:50,820 --> 00:12:54,400 Don't worry about the detail, we've got plenty of chapters to cover this detail. 254 00:12:54,400 --> 00:12:56,370 Don't worry about this particular program. 255 00:12:56,370 --> 00:12:59,400 I'm just sort of getting into the sense that, you'll get it. 256 00:12:59,400 --> 00:13:00,330 But we'll start simple. 257 00:13:01,500 --> 00:13:04,370 So, the first thing that you gotta know how to 258 00:13:06,610 --> 00:13:09,100 do in Python is know what not to do. 259 00:13:09,100 --> 00:13:13,160 Or when you use these reserved words, they have very special meaning to Python. 260 00:13:14,290 --> 00:13:18,280 It's like when you say, "I don't think you're going to get any food today" to a 261 00:13:18,280 --> 00:13:20,800 dog, the dog hears the word "food" and nothing 262 00:13:20,800 --> 00:13:23,760 else. So food is a reserved word for dogs. 263 00:13:23,760 --> 00:13:25,680 Walk, bath, there are other reserved words. 264 00:13:26,720 --> 00:13:28,150 So, what it really means is you can't use 265 00:13:28,150 --> 00:13:31,350 these for anything other than what they mean to Python. 266 00:13:31,350 --> 00:13:34,550 So, print tells it to print things. 267 00:13:34,550 --> 00:13:37,250 Return is used in functions. 268 00:13:37,250 --> 00:13:43,130 Else, if, these are words that if Python sees the word if, it's like, 269 00:13:43,130 --> 00:13:44,320 this means something. 270 00:13:44,320 --> 00:13:47,060 Don't use it for any other purpose except its stated purpose. 271 00:13:47,060 --> 00:13:47,900 We'll learn what those are. 272 00:13:49,520 --> 00:13:51,210 Now if we talk about sentences. 273 00:13:51,210 --> 00:13:55,610 Sentences are kind of, in Python, like a line that kind of have pieces to them. 274 00:13:55,610 --> 00:13:58,760 So here is three pieces of code. 275 00:13:58,760 --> 00:14:00,290 One is x equals 2. 276 00:14:00,290 --> 00:14:03,560 That says, take and find me a piece of memory. 277 00:14:03,560 --> 00:14:05,160 In your RAM. 278 00:14:05,160 --> 00:14:08,130 Allocate it, label it x, and stick 2 in it. 279 00:14:08,130 --> 00:14:11,380 This is kind of like a move 2 into x. 280 00:14:11,380 --> 00:14:18,010 Then this says go get x, add 2 to it, and then put the sum back into x. 281 00:14:18,010 --> 00:14:21,070 Again, little sentences that are kind of like subject predicate, right? 282 00:14:21,070 --> 00:14:24,020 Especially this assignment, it's kind of just, and then print. 283 00:14:24,020 --> 00:14:25,680 Print's a reserved word. 284 00:14:25,680 --> 00:14:26,790 Was one of the was on the list in 285 00:14:26,790 --> 00:14:29,140 the previous slide. And then go read that variable. 286 00:14:29,140 --> 00:14:34,090 So, these are like three sentences in our new little language.