1 00:00:00,670 --> 00:00:03,480 We just saw how to pass a script to the Python interpreter. 2 00:00:03,480 --> 00:00:07,260 Another way to use the interpreter is in a more exploratory interactive way. 3 00:00:07,260 --> 00:00:10,370 You can actually open up a prompt that allows you to type Python code 4 00:00:10,370 --> 00:00:11,460 line by line. 5 00:00:11,460 --> 00:00:14,630 This is super handy when you just wanna see what some code does, and 6 00:00:14,630 --> 00:00:16,980 not actually go and create a whole script. 7 00:00:16,980 --> 00:00:20,430 This type of interactive programming prompt is pretty popular in a lot of other 8 00:00:20,430 --> 00:00:21,870 languages. 9 00:00:21,870 --> 00:00:26,595 Generically, this type of exploratory prompt is referred to as a REPL or 10 00:00:26,595 --> 00:00:28,030 R-E-P-L. 11 00:00:28,030 --> 00:00:32,940 which stands for Read, Evaluate, Print, Loop, which is basically what its role is. 12 00:00:32,940 --> 00:00:36,330 It reads the line, it evaluates it, it prints the result and 13 00:00:36,330 --> 00:00:39,185 then it loops back so you can add another line of code. 14 00:00:39,185 --> 00:00:42,770 Python's REPL is often referred to as the Python shell. 15 00:00:42,770 --> 00:00:45,460 It is a wonderful place to hang out as you are learning, 16 00:00:45,460 --> 00:00:47,610 so I definitely want you to be familiar with it. 17 00:00:47,610 --> 00:00:48,660 Come on, let's go explore. 18 00:00:49,760 --> 00:00:53,392 So, to open up the REPL we simply type Python. 19 00:00:55,586 --> 00:00:59,379 And we'll get some information about the version of Python that we're running. 20 00:00:59,379 --> 00:01:03,040 So we're running 3.6.4 on Linux. 21 00:01:03,040 --> 00:01:07,760 Remember, your workspace is running a Linux OS, or operating system. 22 00:01:07,760 --> 00:01:11,320 These three greater than signs, or chevrons, as they're sometimes called, 23 00:01:11,320 --> 00:01:15,030 are communicating to us that this is the place where we can write some code. 24 00:01:15,030 --> 00:01:17,030 So, let's do it. 25 00:01:17,030 --> 00:01:21,170 Since we know we have a working program up here, let's just write that out ourselves. 26 00:01:21,170 --> 00:01:25,450 So, we want to make sure that we type it exactly like it is above. 27 00:01:25,450 --> 00:01:30,170 Make sure that you keep everything lowercase, case matters in Python. 28 00:01:30,170 --> 00:01:34,230 So, this prinT is different than the lowercase print. 29 00:01:34,230 --> 00:01:38,560 So, that's the name of the function that we want to call, and 30 00:01:38,560 --> 00:01:41,190 you call a function using parenthesis. 31 00:01:41,190 --> 00:01:43,130 And now we wanna pass in a string. 32 00:01:43,130 --> 00:01:46,400 And we can create a string using quotation marks. 33 00:01:46,400 --> 00:01:47,760 We'll do that, open that up. 34 00:01:47,760 --> 00:01:53,205 And then our characters, which here happens to be, Hello, World. 35 00:01:53,205 --> 00:01:58,070 And then we close our string with another quotation mark. 36 00:01:58,070 --> 00:02:01,760 And then, finally, we close our function call with a closing paren. 37 00:02:02,960 --> 00:02:05,190 So let's go ahead and run that. 38 00:02:05,190 --> 00:02:06,640 Awesome, Hello, World. 39 00:02:06,640 --> 00:02:10,330 Now, a great thing about the shell is that it keeps it's history. 40 00:02:10,330 --> 00:02:13,520 If you press the up arrow, you can get the last line that you just typed back. 41 00:02:13,520 --> 00:02:15,447 This is handy if you had made a typo or 42 00:02:15,447 --> 00:02:17,841 you wanna write a line that is very similar. 43 00:02:17,841 --> 00:02:20,060 Like for instant, let's just say hello to you. 44 00:02:20,060 --> 00:02:21,830 So I'm gonna put my name in here. 45 00:02:21,830 --> 00:02:22,410 Hello, Craig. 46 00:02:23,790 --> 00:02:26,770 Awesome, and Python shell is also a pretty good calculator. 47 00:02:26,770 --> 00:02:30,657 You can use it to do math-like things, things like 1 + 2. 48 00:02:30,657 --> 00:02:34,820 And so you'll see here that the result printed out 3. 49 00:02:34,820 --> 00:02:38,260 Note that we didn't actually call the print function. 50 00:02:38,260 --> 00:02:40,890 Now this is a good example of the REPL in action. 51 00:02:40,890 --> 00:02:46,282 What happened was it read the line, 1 + 2, it evaluated it, what's 1 plus 2? 52 00:02:46,282 --> 00:02:50,130 And then it printed the result, 3,and it looped back to the prompt. 53 00:02:50,130 --> 00:02:52,740 It showed the result so that we could see it. 54 00:02:52,740 --> 00:02:55,820 We'll get to some more math in the course in just a bit. 55 00:02:55,820 --> 00:02:58,720 Now another thing that is wonderful about the Python prompt 56 00:02:58,720 --> 00:03:01,210 is that you can help when you need it. 57 00:03:01,210 --> 00:03:04,520 So, for instance, if we wanted to know more about the print function, 58 00:03:04,520 --> 00:03:06,330 we could just call the help function. 59 00:03:06,330 --> 00:03:10,190 So we say help and we pass in the function that we're interested in, 60 00:03:10,190 --> 00:03:11,380 we're interested in print. 61 00:03:11,380 --> 00:03:12,100 Let's see what happens. 62 00:03:13,785 --> 00:03:16,505 So this kicks open the documentation for the print function. 63 00:03:16,505 --> 00:03:19,625 Now, this is gonna have some terminology in here that we haven't yet 64 00:03:19,625 --> 00:03:21,355 covered, so don't let that overwhelm you. 65 00:03:21,355 --> 00:03:23,635 Now believe it or not, if you stick with it and 66 00:03:23,635 --> 00:03:26,295 immerse yourself, this will all make sense. 67 00:03:26,295 --> 00:03:29,255 We'll get to all of this, just not right now. 68 00:03:29,255 --> 00:03:32,443 So here's the description, it prints the values to a stream, or 69 00:03:32,443 --> 00:03:35,300 sys.stdout by default. 70 00:03:35,300 --> 00:03:39,260 Standard out is another way of saying the place that you ran the program from, 71 00:03:40,750 --> 00:03:42,170 the default output. 72 00:03:43,190 --> 00:03:47,110 So basically, what this is saying is that we can print to other places, too. 73 00:03:47,110 --> 00:03:51,110 This value here is the hello world string that we passed in. 74 00:03:51,110 --> 00:03:54,230 Then you'll notice that there's a comma and then there's these ellipses, 75 00:03:54,230 --> 00:03:56,140 there's these three ellipses here, right? 76 00:03:56,140 --> 00:04:00,370 So, this means that we can actually pass multiple values to print, and 77 00:04:00,370 --> 00:04:01,180 we'll do that here in a bit. 78 00:04:01,180 --> 00:04:03,170 We'll pass multiple values. 79 00:04:03,170 --> 00:04:06,300 Now, if you look down at the bottom here you'll see that that says END and that's 80 00:04:06,300 --> 00:04:11,130 because we're inside of what is known as a pager, when help opens it does that. 81 00:04:11,130 --> 00:04:14,271 Now, it just so happens that all the help fits on one page but let's go ahead and 82 00:04:14,271 --> 00:04:15,475 let's make that not happen. 83 00:04:15,475 --> 00:04:18,554 So this is something you can do too, you can make the console bigger or smaller, so 84 00:04:18,554 --> 00:04:19,726 I'm going to make it smaller. 85 00:04:19,726 --> 00:04:22,496 And you'll see what happens is, eventually, 86 00:04:22,496 --> 00:04:24,740 there's this like blinking colon. 87 00:04:24,740 --> 00:04:27,050 And I wanted to show you this just in case you opened up help to something else. 88 00:04:27,050 --> 00:04:29,610 You can press the up and down keys and move around. 89 00:04:29,610 --> 00:04:32,160 And space bar actually moves a page at a time. 90 00:04:32,160 --> 00:04:36,203 So, to get out of a pager, what you can do is press Q. 91 00:04:39,298 --> 00:04:42,178 And now normally what would happen when you popped out of here is you would pop 92 00:04:42,178 --> 00:04:43,040 back into your shell. 93 00:04:43,040 --> 00:04:45,600 But it looks like I had a little bit of a workspace problem. 94 00:04:45,600 --> 00:04:49,710 Which I'm glad happened, so I can show you what to do when this happens. 95 00:04:49,710 --> 00:04:50,860 So the console, 96 00:04:50,860 --> 00:04:54,260 you can restart your console always by clicking either this X here. 97 00:04:54,260 --> 00:04:55,730 This will close the console. 98 00:04:55,730 --> 00:04:59,571 And I can up here and say View > Show Console. 99 00:04:59,571 --> 00:05:02,053 It should pop back open, there we go. 100 00:05:02,053 --> 00:05:04,951 And so if we are inside of a shell, 101 00:05:04,951 --> 00:05:07,244 You might wanna know how to get out of here too, right? 102 00:05:07,244 --> 00:05:12,289 So, there is a handy function called exit, and that will pop you out. 103 00:05:12,289 --> 00:05:16,183 But even better, and I know cuz we programmers are lazy, 104 00:05:16,183 --> 00:05:20,330 you can also press Ctrl + D to drop out of there. 105 00:05:20,330 --> 00:05:21,550 There we go. 106 00:05:21,550 --> 00:05:25,270 Awesome, so now you have a place to go and explore when you need to. 107 00:05:25,270 --> 00:05:27,550 Also, you can't break anything in there. 108 00:05:27,550 --> 00:05:28,900 So, feel free to do whatever. 109 00:05:28,900 --> 00:05:31,130 And like you just saw, you can always exit out. 110 00:05:31,130 --> 00:05:35,450 A common thing that happens to people just beginning to learn to code 111 00:05:35,450 --> 00:05:38,270 is that they're afraid to make mistakes, so they freeze up. 112 00:05:38,270 --> 00:05:41,750 Please don't be afraid of making mistakes, that will bite you in the future. 113 00:05:41,750 --> 00:05:45,980 Try to change your point of view to this one, making mistakes is awesome. 114 00:05:45,980 --> 00:05:48,270 Messing up simply means that you're trying, and 115 00:05:48,270 --> 00:05:50,200 you can't learn without trying, can you? 116 00:05:50,200 --> 00:05:51,800 So, don't let those mistake get you down. 117 00:05:51,800 --> 00:05:54,459 It's part of the learning process, and REPL is awesome for 118 00:05:54,459 --> 00:05:56,600 that kind of exploration. 119 00:05:56,600 --> 00:05:57,470 I do get it, though. 120 00:05:57,470 --> 00:06:00,440 Those error messages can be intimidating. 121 00:06:00,440 --> 00:06:02,570 So let's do this, let's take a quick break, and 122 00:06:02,570 --> 00:06:05,500 then take a look at some of the more common errors, and how to handle them.