1 00:00:00,000 --> 00:00:01,000 Okey-Dokey. 2 00:00:01,080 --> 00:00:05,100 Now we can actually start getting into learning Python properly. 3 00:00:05,110 --> 00:00:09,660 So a little while ago what we did, we had this thing called 4 00:00:09,670 --> 00:00:11,910 a 'print' statement or a 'print' function, 5 00:00:12,080 --> 00:00:15,170 and we said, "Hello World", hit 'Shift + Enter', 6 00:00:15,170 --> 00:00:16,280 and it says "Hello World". 7 00:00:16,420 --> 00:00:19,780 And that is essentially all it takes to run a Python program. 8 00:00:20,000 --> 00:00:22,190 But there are these things called variables. 9 00:00:22,200 --> 00:00:24,680 And what I'm going to do is just delete that. 10 00:00:24,690 --> 00:00:29,090 And a variable is really just a way to assign some sort of 11 00:00:29,100 --> 00:00:31,800 'name' to have some sort of value. 12 00:00:31,800 --> 00:00:33,800 So let's not do 'name', 13 00:00:33,800 --> 00:00:37,500 let's do 'course', that's a variable name, is equal to, '=', and 14 00:00:37,530 --> 00:00:39,920 we see just one equal sign. 15 00:00:41,000 --> 00:00:43,040 Maybe I can make that a bit bigger here. 16 00:00:43,050 --> 00:00:44,570 'course =', 17 00:00:44,580 --> 00:00:47,610 and then we have different variable types, data types, 18 00:00:47,620 --> 00:00:49,260 but we're going to keep this simple for now. 19 00:00:49,270 --> 00:00:50,400 So let's use a quotation, 20 00:00:50,600 --> 00:00:55,080 so we've an opening and closing quotation mark there. Not 21 00:00:55,080 --> 00:00:58,000 "Course", let's do "Python for Everybody". 22 00:00:58,060 --> 00:00:59,470 Hit 'Shift + Enter', 23 00:00:59,470 --> 00:01:01,700 and it looks like nothing happened. 24 00:01:01,700 --> 00:01:06,730 But if we type 'course', and then do 'Shift + Enter', our interactive 25 00:01:06,739 --> 00:01:09,700 shell here will tell us that it is a value of "Python for 26 00:01:09,710 --> 00:01:13,750 Everybody". And now what you can do is 'print()', your course name, 27 00:01:13,960 --> 00:01:15,340 "Python for Everybody". 28 00:01:15,350 --> 00:01:18,580 Now, the difference here is 'print' will actually print this 29 00:01:18,590 --> 00:01:21,520 out, whereas just because we're in an interactive shell here, 30 00:01:21,600 --> 00:01:26,100 this is sort of displaying it for us. In terms of which one you should use, 31 00:01:26,100 --> 00:01:29,000 currently, when you're using Jupyter Notebook you can use either one, 32 00:01:29,030 --> 00:01:30,040 it doesn't really matter. 33 00:01:30,050 --> 00:01:33,130 But in a Python program, when you're actually creating a 34 00:01:33,130 --> 00:01:36,540 '.py' file, you'll want to use the 'print' statement because 35 00:01:36,550 --> 00:01:39,600 that will actually display text in your terminal, or in your 36 00:01:39,600 --> 00:01:40,600 command line program. 37 00:01:40,600 --> 00:01:45,000 So what I would like you to do is create a new Jupyter Notebook, 38 00:01:45,020 --> 00:01:47,770 or open up your Python shell on your command line, 39 00:01:47,780 --> 00:01:52,140 type in 'course = "Python for Everybody", and then 40 00:01:52,140 --> 00:01:54,800 type in 'course', and then 'print(course), and that's it. 41 00:01:54,840 --> 00:01:57,960 At that point in time, you have already assigned a variable. 42 00:01:58,180 --> 00:02:01,870 Now, the nice thing about a variable is you can reassign 43 00:02:01,880 --> 00:02:05,510 it. So we can say initially, 'course = "Python for 44 00:02:05,520 --> 00:02:08,930 Everybody"'. But we could also say if we wanted to change that 45 00:02:08,940 --> 00:02:13,169 value, we could say the course is now going to, for some 46 00:02:13,169 --> 00:02:16,900 reason, transform into "JavaScript for Everybody", 47 00:02:16,900 --> 00:02:22,500 and if I hit 'course', 'Enter', 'print(course)', 'Shift + Enter', 48 00:02:22,540 --> 00:02:27,140 you can actually see if I scroll up here 49 00:02:27,800 --> 00:02:30,500 'course' was originally "Python for Everybody". We printed it. 50 00:02:30,570 --> 00:02:32,240 We know that that's exactly what it is. 51 00:02:32,520 --> 00:02:34,980 And then we changed it to "JavaScript for Everybody". 52 00:02:35,600 --> 00:02:36,600 Printed that. 53 00:02:36,700 --> 00:02:41,360 And we now know that 'course' is now "JavaScript for Everybody". 54 00:02:41,370 --> 00:02:45,040 So anytime we access it down the road, it's always going 55 00:02:45,050 --> 00:02:46,960 to be "JavaScript for Everybody". 56 00:02:47,120 --> 00:02:51,260 So we set the value "Python for Everybody", and then we overwrote it. 57 00:02:51,270 --> 00:02:54,430 Now, that's basically how variables work. 58 00:02:54,600 --> 00:02:58,090 It's just a name that points to something. 59 00:02:58,380 --> 00:03:00,240 And that's actually the key behind a variable. 60 00:03:00,240 --> 00:03:04,200 What a lot of courses won't tell you is how a variable works behind the scenes. 61 00:03:04,280 --> 00:03:06,320 So a variable is just a name. 62 00:03:06,330 --> 00:03:10,220 Python behind the scenes does not care what this is called. 63 00:03:10,230 --> 00:03:12,230 It could be called literally anything. 64 00:03:12,230 --> 00:03:13,200 There are some rules. 65 00:03:13,200 --> 00:03:15,700 It should not start with a number, for instance. Should not 66 00:03:15,720 --> 00:03:16,880 start with special characters. 67 00:03:16,890 --> 00:03:19,520 Just give it a normal name with just regular letters and 68 00:03:19,520 --> 00:03:20,500 maybe underscores, 69 00:03:20,560 --> 00:03:22,210 and if you want uppercase letters. 70 00:03:22,220 --> 00:03:26,510 So something like that. As long as it's just a regular text 71 00:03:26,510 --> 00:03:28,460 name, Python doesn't care what it's called. 72 00:03:28,560 --> 00:03:29,970 Then we use an equal sign. 73 00:03:29,980 --> 00:03:33,790 And what this says is, "Hey, Python, please give me a little 74 00:03:33,800 --> 00:03:35,290 piece of memory from the computer. 75 00:03:35,520 --> 00:03:39,450 So a little piece of that RAM that's going on or some processing 76 00:03:39,460 --> 00:03:42,450 power, however, memory is allocated on the particular computer, 77 00:03:42,450 --> 00:03:47,300 I just need, let's say, 128 bytes of memory. 78 00:03:47,380 --> 00:03:50,080 And wherever that is, I don't really care where it is 79 00:03:50,090 --> 00:03:52,180 just give me 128 bytes of memory. 80 00:03:52,320 --> 00:03:56,100 And then I'm just going to use a code name 'course' to 81 00:03:56,100 --> 00:03:57,900 access those 128 bytes of memory". 82 00:03:57,940 --> 00:04:01,920 Now, at this point in time, that 128 bytes of memory inside 83 00:04:01,920 --> 00:04:04,600 of it says, "Python for Everybody". 84 00:04:04,680 --> 00:04:07,800 And so really, what we're doing, is we're taking this text, 85 00:04:08,300 --> 00:04:14,120 and we're jamming it into some sort of memory inside of your 86 00:04:14,130 --> 00:04:17,329 computer. And so when the script runs, Python says, "Okay, 87 00:04:17,339 --> 00:04:19,600 there's a name called 'course'. 88 00:04:19,610 --> 00:04:23,110 I know that's sort of a code name for this piece of memory 89 00:04:23,120 --> 00:04:26,350 that's, I don't know, way over here, and the user never needs 90 00:04:26,350 --> 00:04:29,980 to know about it. But I know that it has a code name, of 'course'. 91 00:04:29,990 --> 00:04:32,170 And inside of it, it says "Python for Everybody". 92 00:04:32,380 --> 00:04:37,150 So whenever the user types 'course', I know that it's supposed 93 00:04:37,160 --> 00:04:38,260 to be "Python for Everybody"." 94 00:04:38,420 --> 00:04:42,530 So really, all it is, is you've got let's say a code name, 95 00:04:42,530 --> 00:04:45,620 aka a variable name, is equal to, 96 00:04:45,630 --> 00:04:48,920 and this will actually assign a piece of memory to this variable 97 00:04:48,930 --> 00:04:51,860 for you, and then, "Anything you want in here". 98 00:04:51,870 --> 00:04:54,020 And I'm actually going to undo that because I don't need 99 00:04:54,030 --> 00:04:57,000 that. But then let's say down the road, I overwrite that 100 00:04:57,000 --> 00:04:58,100 variable, which we did. 101 00:04:58,100 --> 00:05:01,400 Now Python is going to say, "Okay, well, this has the same variable name. 102 00:05:01,460 --> 00:05:03,850 It's already allocated to "Python for Everybody". 103 00:05:04,300 --> 00:05:06,580 But what do I do about it? 104 00:05:06,590 --> 00:05:08,890 I mean, it already has some data here. 105 00:05:08,950 --> 00:05:10,060 So what do I do?" 106 00:05:10,900 --> 00:05:13,500 And behind the scenes, Python is going to say, "This already 107 00:05:13,570 --> 00:05:14,460 exists. You know what. 108 00:05:14,470 --> 00:05:16,650 Throw it out. Delete it. Get rid of it. 109 00:05:16,650 --> 00:05:17,600 Get out of here. 110 00:05:17,600 --> 00:05:20,600 And I'm going to create a new variable with code name, of 111 00:05:20,690 --> 00:05:23,110 'course'." So it's just going to be the exact same code name, 112 00:05:23,110 --> 00:05:26,300 but is going to point to a different memory location. 113 00:05:26,320 --> 00:05:28,630 That's how a variable works behind the scenes. 114 00:05:28,640 --> 00:05:31,600 Now, that's a little important to understand 115 00:05:31,610 --> 00:05:34,000 down the road, you don't need to know about it too much right 116 00:05:34,010 --> 00:05:36,220 now. But just tuck that in your back pocket, because we're 117 00:05:36,220 --> 00:05:39,100 going to reference this a little bit later in this course. 118 00:05:39,100 --> 00:05:41,440 For now, setting a variable is super easy. 119 00:05:41,450 --> 00:05:46,070 You say the variable name is equal to, and then whatever 120 00:05:46,080 --> 00:05:48,350 the value is going to be. Make sure you have quotations in there, 121 00:05:48,360 --> 00:05:50,900 because that is a particular data type that allows you 122 00:05:50,900 --> 00:05:54,800 to use spaces and characters like P-Y-T-H-O-N. 123 00:05:54,860 --> 00:05:57,470 So go ahead, give this a shot, create a variable, and then 124 00:05:57,480 --> 00:05:58,490 print that variable out. 125 00:05:58,500 --> 00:06:01,400 Once you have done that, I think we are ready to move on 126 00:06:01,400 --> 00:06:03,100 to the next lesson.