1 00:00:00,780 --> 00:00:03,240 Instructor: Hey, you're still sticking around. 2 00:00:03,240 --> 00:00:04,860 That's good, I didn't bore you 3 00:00:04,860 --> 00:00:07,560 with all my talking, but yes, in this video 4 00:00:07,560 --> 00:00:11,490 finally we're going to write some Python code. 5 00:00:11,490 --> 00:00:12,323 Holy moly. 6 00:00:12,323 --> 00:00:14,910 Thank God I thought that was gonna last forever. 7 00:00:14,910 --> 00:00:19,140 All right, so what is our first program going to do? 8 00:00:19,140 --> 00:00:23,490 Well, let's create a very, very simple function. 9 00:00:23,490 --> 00:00:25,350 And probably the first thing 10 00:00:25,350 --> 00:00:30,060 any programmer learns to do, to print our own name. 11 00:00:30,060 --> 00:00:34,500 So in here, once you have your repl.it set up 12 00:00:34,500 --> 00:00:37,953 or remember you can also use glot.io. 13 00:00:39,030 --> 00:00:41,253 We're simply going to write print. 14 00:00:42,210 --> 00:00:43,800 And then you see over here 15 00:00:43,800 --> 00:00:45,150 that it gives us some information, 16 00:00:45,150 --> 00:00:50,150 but all we wanna do is write brackets, a quote. 17 00:00:51,420 --> 00:00:53,160 So you can do double quotes here 18 00:00:53,160 --> 00:00:56,583 or a single quote and just type your name. 19 00:00:59,340 --> 00:01:03,840 And if we click run on the right side, 20 00:01:03,840 --> 00:01:08,550 we've just ran our very first Python program. 21 00:01:08,550 --> 00:01:09,930 Very exciting. 22 00:01:09,930 --> 00:01:12,510 But what's happening here? 23 00:01:12,510 --> 00:01:14,700 Well, let's look at everything. 24 00:01:14,700 --> 00:01:18,870 First of all, if you're confused why my thing is darkened, 25 00:01:18,870 --> 00:01:20,910 yours might be light. 26 00:01:20,910 --> 00:01:23,160 It's because if I go to settings, 27 00:01:23,160 --> 00:01:27,450 I've set my theme to light or to dark. 28 00:01:27,450 --> 00:01:28,950 I prefer the dark version. 29 00:01:28,950 --> 00:01:31,050 But you can change some of your settings. 30 00:01:31,050 --> 00:01:33,600 You can change the font size if you want, 31 00:01:33,600 --> 00:01:35,250 based on when you watch the video. 32 00:01:35,250 --> 00:01:37,260 This website, the look might be different 33 00:01:37,260 --> 00:01:39,633 but most of the settings should be the same. 34 00:01:40,560 --> 00:01:44,550 We see that we have a main.py, 35 00:01:44,550 --> 00:01:46,980 which is the Python extension. 36 00:01:46,980 --> 00:01:51,980 Any file that has a .py or py is a Python file. 37 00:01:52,740 --> 00:01:54,570 So what we've just written here 38 00:01:54,570 --> 00:01:59,570 on line one is a program that prints 39 00:02:00,300 --> 00:02:04,710 in this case Andrei Neagoie or in your case, your own name. 40 00:02:04,710 --> 00:02:07,530 And we've written it to this file. 41 00:02:07,530 --> 00:02:10,620 Now, repl.it takes this file 42 00:02:10,620 --> 00:02:14,880 already has this interpreter for us. 43 00:02:14,880 --> 00:02:19,170 It runs this piece of code, gives this source code 44 00:02:19,170 --> 00:02:24,170 of main.py to the interpreter and runs it right here 45 00:02:24,450 --> 00:02:26,100 on our right side. 46 00:02:26,100 --> 00:02:30,870 If you look over here, we're using Python version 3.6 0.1 47 00:02:30,870 --> 00:02:33,360 and down below we see that, 48 00:02:33,360 --> 00:02:36,093 Oh, we have Andrei Neagoie print it. 49 00:02:37,080 --> 00:02:38,700 That's awesome. 50 00:02:38,700 --> 00:02:41,283 So this is our code running. 51 00:02:42,180 --> 00:02:43,770 Remember this diagram? 52 00:02:43,770 --> 00:02:47,280 All we've done is we have our main.py 53 00:02:47,280 --> 00:02:50,190 where we wrote print Andrei Neagoie. 54 00:02:50,190 --> 00:02:53,490 We gave it to the interpreter that the repl 55 00:02:53,490 --> 00:02:55,470 already provides for us. 56 00:02:55,470 --> 00:02:58,920 That interpreter takes our code, converts it 57 00:02:58,920 --> 00:03:03,450 into bite code, and here it'll say Andrei Neagoie. 58 00:03:03,450 --> 00:03:06,690 And then it runs it in the CPython VM, 59 00:03:06,690 --> 00:03:08,820 which was on the right side that we saw. 60 00:03:08,820 --> 00:03:10,890 And it finally prints our name 61 00:03:10,890 --> 00:03:12,037 because it tells the machine, 62 00:03:12,037 --> 00:03:15,570 "hey we want that text printed". 63 00:03:15,570 --> 00:03:17,340 So that's what we're seeing here. 64 00:03:17,340 --> 00:03:21,330 This is the CPython virtual machine essentially 65 00:03:21,330 --> 00:03:23,077 running this code and telling this machine, 66 00:03:23,077 --> 00:03:25,980 "hey I want you to print this". 67 00:03:25,980 --> 00:03:28,380 All right, but this isn't very exciting. 68 00:03:28,380 --> 00:03:31,650 I mean, let's make this program a little bit more dynamic. 69 00:03:31,650 --> 00:03:32,580 For our first program, 70 00:03:32,580 --> 00:03:36,300 we wanna do something more impressive than just print name. 71 00:03:36,300 --> 00:03:40,980 So I'm going to teach you another thing we can do in Python 72 00:03:40,980 --> 00:03:43,203 and it's called input. 73 00:03:44,490 --> 00:03:47,940 Now, in here I can say input. 74 00:03:47,940 --> 00:03:50,700 And you see that repl actually gives me 75 00:03:50,700 --> 00:03:53,610 some information saying that, "Oh, I have this". 76 00:03:53,610 --> 00:03:58,530 You can just click here, and this input over here. 77 00:03:58,530 --> 00:03:59,790 Well, what can we do? 78 00:03:59,790 --> 00:04:02,670 This input is going to prompt a user. 79 00:04:02,670 --> 00:04:06,540 And if I hover over it, you can see how it's giving me 80 00:04:06,540 --> 00:04:07,920 some information. 81 00:04:07,920 --> 00:04:11,850 But input simply gives us a way to capture information. 82 00:04:11,850 --> 00:04:15,183 So let's say, what is your name? 83 00:04:17,070 --> 00:04:18,783 And if I run this code, 84 00:04:20,459 --> 00:04:24,510 we see that we have our Python code running, 85 00:04:24,510 --> 00:04:26,640 and it's asking me what is my name 86 00:04:26,640 --> 00:04:28,230 with this cursor here. 87 00:04:28,230 --> 00:04:30,030 So I can actually type something here. 88 00:04:30,030 --> 00:04:35,030 I can say Andrei, and if I hit enter, well, there you go. 89 00:04:37,890 --> 00:04:41,640 I've just typed in my own name. 90 00:04:41,640 --> 00:04:43,800 Nothing that exciting, right? 91 00:04:43,800 --> 00:04:46,830 But this is where code becomes interesting 92 00:04:46,830 --> 00:04:51,420 because we can store this information on our computer. 93 00:04:51,420 --> 00:04:54,180 So again, these are things that we're gonna go over 94 00:04:54,180 --> 00:04:57,780 in detail in our basics Python section, 95 00:04:57,780 --> 00:05:00,240 but just to write our first code. 96 00:05:00,240 --> 00:05:03,780 Let's assign this to memory. 97 00:05:03,780 --> 00:05:08,780 That is, let's say that name equals whatever is the input 98 00:05:08,940 --> 00:05:10,203 of what is your name. 99 00:05:11,820 --> 00:05:16,173 And then finally, we can just print the name. 100 00:05:17,940 --> 00:05:19,320 So remember the interpreter 101 00:05:19,320 --> 00:05:20,970 is going to take this first line. 102 00:05:21,840 --> 00:05:24,690 It's going to ask, What is your name? 103 00:05:24,690 --> 00:05:28,140 I'm going to type something, that typed information 104 00:05:28,140 --> 00:05:31,620 is going to get assigned to name. 105 00:05:31,620 --> 00:05:35,430 And then finally, we print name. 106 00:05:35,430 --> 00:05:38,820 Remember, an interpreter takes line by line, 107 00:05:38,820 --> 00:05:42,003 converts code to bite code, and then finally runs it. 108 00:05:42,900 --> 00:05:44,190 So let's give this a try. 109 00:05:44,190 --> 00:05:45,363 I'm going to click run. 110 00:05:46,770 --> 00:05:48,510 All right, what's your name? 111 00:05:48,510 --> 00:05:50,133 My name is Andrei. 112 00:05:51,900 --> 00:05:52,750 Did you see that? 113 00:05:54,000 --> 00:05:57,570 I typed in my name hit enter, 114 00:05:57,570 --> 00:05:59,793 and then it printed out Andrei. 115 00:06:00,990 --> 00:06:05,220 So for the final feed, let's greet. 116 00:06:05,220 --> 00:06:10,220 So we're going to say print hello, and then plus name. 117 00:06:14,640 --> 00:06:17,370 Now, don't worry about this syntax, we're gonna go over it, 118 00:06:17,370 --> 00:06:20,130 but all we're doing is saying hello 119 00:06:20,130 --> 00:06:24,783 and then adding our name to the end of this. 120 00:06:25,650 --> 00:06:26,820 So let's see what happens 121 00:06:26,820 --> 00:06:30,090 if I run this and say, What is your name? 122 00:06:30,090 --> 00:06:32,823 My name is Andrei and I hit enter. 123 00:06:33,900 --> 00:06:37,080 I get, "hello Andrei", but no spaces. 124 00:06:37,080 --> 00:06:38,910 So let's add a little space. 125 00:06:38,910 --> 00:06:42,240 Hit run again for the fourth time. 126 00:06:42,240 --> 00:06:45,897 My name's Andrei and it says, "hello, Andrei". 127 00:06:46,740 --> 00:06:47,640 There it is. 128 00:06:47,640 --> 00:06:50,490 Our first Python program. 129 00:06:50,490 --> 00:06:54,630 Now, it's not very exciting because it is our first program. 130 00:06:54,630 --> 00:06:56,580 We're just learning the steps here. 131 00:06:56,580 --> 00:07:00,930 But I hope because we've covered some of these topics 132 00:07:00,930 --> 00:07:01,890 ahead of time, 133 00:07:01,890 --> 00:07:05,490 that this isn't just pure magic, right? 134 00:07:05,490 --> 00:07:08,130 You understand that this is source code. 135 00:07:08,130 --> 00:07:11,040 This is main.py that we give 136 00:07:11,040 --> 00:07:15,930 to an interpreter that runs our code line by line 137 00:07:15,930 --> 00:07:19,590 and then executes our program. 138 00:07:19,590 --> 00:07:23,013 In this case, our what is your name program? 139 00:07:24,060 --> 00:07:27,060 How cool is that? 140 00:07:27,060 --> 00:07:28,590 This is just the beginning. 141 00:07:28,590 --> 00:07:31,860 We're gonna get more and more advanced here. 142 00:07:31,860 --> 00:07:33,780 See if you can play around with this. 143 00:07:33,780 --> 00:07:35,670 We don't know that much about Python yet 144 00:07:35,670 --> 00:07:38,640 but I hope this gets you excited because well, 145 00:07:38,640 --> 00:07:40,740 there's a lot more coding coming along. 146 00:07:40,740 --> 00:07:42,300 I'll see you in the next one. 147 00:07:42,300 --> 00:07:43,133 Bye-bye.