1 00:00:00,610 --> 00:00:04,840 So you know that Hello, World string that we used in our hello.py file? 2 00:00:04,840 --> 00:00:09,210 To be a little bit more specific we created the new string. 3 00:00:09,210 --> 00:00:13,540 We did that creation by surrounding our text with quotation marks. 4 00:00:13,540 --> 00:00:16,220 This is what is known as a string literal. 5 00:00:16,220 --> 00:00:19,750 Now, we currently don't keep that string around, we create it, 6 00:00:19,750 --> 00:00:22,550 we use it in our print statement, and then we let it go. 7 00:00:22,550 --> 00:00:26,100 But we can actually store it and use it later. 8 00:00:26,100 --> 00:00:30,260 In the real world, we create things and store them for later use all the time. 9 00:00:30,260 --> 00:00:31,900 Here's an example I can think of right now. 10 00:00:32,920 --> 00:00:36,340 Actually I can't stop thinking though probably because it is about lunch time. 11 00:00:36,340 --> 00:00:38,450 Last night I made some delicious tacos, so 12 00:00:38,450 --> 00:00:40,740 good in fact that I wanted to bring them into work today. 13 00:00:41,940 --> 00:00:44,900 So I grabbed a food storage container, some Tupperware, and 14 00:00:44,900 --> 00:00:47,940 I put the remainder of the delicious meat in it. 15 00:00:47,940 --> 00:00:50,590 When I put it in the refrigerator here at the office, 16 00:00:50,590 --> 00:00:54,710 I decided that I had better label it, mostly so people knew it was mine. 17 00:00:54,710 --> 00:00:59,260 Putting a label on it ensures that no one is just going to throw my food away. 18 00:00:59,260 --> 00:01:00,640 Also I know it's mine. 19 00:01:00,640 --> 00:01:03,630 We have a lot of other labeled Tupperware in our fridge. 20 00:01:03,630 --> 00:01:06,020 Labeling it helps me find my food. 21 00:01:06,020 --> 00:01:07,610 Now, here's a little confession. 22 00:01:07,610 --> 00:01:12,240 I end up making a lot of tacos, and I end up keeping a bunch of leftovers. 23 00:01:12,240 --> 00:01:17,090 And the problem that leads to is this, if I just label this with my name, 24 00:01:17,090 --> 00:01:20,300 I don't actually remember what is in the Tupperware. 25 00:01:20,300 --> 00:01:23,426 Now one way I get around that is by adding another label to it. 26 00:01:23,426 --> 00:01:24,100 This one is beef. 27 00:01:24,100 --> 00:01:25,860 This one is chicken. 28 00:01:25,860 --> 00:01:30,210 Some carnitas and this one is something. 29 00:01:30,210 --> 00:01:34,450 So there are two of these labels referring to the same object. 30 00:01:35,930 --> 00:01:40,160 In Python everything you create is an object and you can label an object so 31 00:01:40,160 --> 00:01:42,960 that you can refer to it later in your program. 32 00:01:42,960 --> 00:01:46,080 These labels that you create are called variables. 33 00:01:46,080 --> 00:01:49,530 Variables allow you to refer to objects that had been created. 34 00:01:49,530 --> 00:01:51,910 They are object references. 35 00:01:51,910 --> 00:01:56,190 Now let's launch our workspace and take our example from Tupperware to software. 36 00:01:56,190 --> 00:01:59,360 Okay, it's time to make this code a little more personal. 37 00:01:59,360 --> 00:02:02,150 Let's change this so it says hello to you. 38 00:02:02,150 --> 00:02:05,320 So I'm gonna come in here and I'm gonna change this to be my name. 39 00:02:05,320 --> 00:02:06,280 I'm gonna type Craig. 40 00:02:06,280 --> 00:02:07,360 You should type your name there. 41 00:02:08,440 --> 00:02:12,050 And now, let's go ahead and add another print statement and 42 00:02:12,050 --> 00:02:13,940 this time write it about yourself. 43 00:02:13,940 --> 00:02:21,260 So we'll do print, call the function, and we'll say, Craig is learning Python. 44 00:02:23,050 --> 00:02:25,600 Now let's go ahead and run the script, again, that's python and 45 00:02:25,600 --> 00:02:29,230 then you can type the start of your file name and then you can press tab and 46 00:02:29,230 --> 00:02:31,010 then it will complete it for you, nice right? 47 00:02:32,960 --> 00:02:38,830 Awesome, now, what if I asked you to change who this program was addressing? 48 00:02:38,830 --> 00:02:42,200 Like instead of you, some other clever person. 49 00:02:42,200 --> 00:02:43,290 Ooh, I know. 50 00:02:43,290 --> 00:02:48,060 Let's change this to greet the very first computer programmer, Ada Lovelace. 51 00:02:48,060 --> 00:02:50,030 She published the first algorithm for 52 00:02:50,030 --> 00:02:53,460 a device called the analytical engine in 1840s. 53 00:02:53,460 --> 00:02:55,810 Pretty clever as putting it lightly. 54 00:02:55,810 --> 00:02:57,720 Check the teacher's notes for more. 55 00:02:57,720 --> 00:03:02,460 So now, I know you could very easily just go and replace your name with Ada's. 56 00:03:02,460 --> 00:03:06,470 But let's do something a little more clever than that. 57 00:03:06,470 --> 00:03:11,260 How about we create a new string with her first name in it? 58 00:03:11,260 --> 00:03:13,060 And then we store it. 59 00:03:13,060 --> 00:03:16,180 So we could use it later in these lines right? 60 00:03:16,180 --> 00:03:17,110 These lines here. 61 00:03:17,110 --> 00:03:18,790 We can use it here and here. 62 00:03:20,080 --> 00:03:22,710 So, you know how to create a string already. 63 00:03:22,710 --> 00:03:26,110 You just surround some text with quotes. 64 00:03:26,110 --> 00:03:28,483 So we'll put Ada's name in there, Ada. 65 00:03:30,567 --> 00:03:34,020 So, that creates a brand new string object. 66 00:03:34,020 --> 00:03:35,730 That's a string literal. 67 00:03:35,730 --> 00:03:40,800 And we wanna keep this around so we need to give it a label or a name. 68 00:03:40,800 --> 00:03:44,310 So let's see, how would we like to refer to the string? 69 00:03:44,310 --> 00:03:46,340 What's a good name for it? 70 00:03:46,340 --> 00:03:49,840 Well, it is a first name, so let's call it that. 71 00:03:51,590 --> 00:03:56,230 Now, there are some naming rules that I've added to the teacher's notes. 72 00:03:56,230 --> 00:04:01,340 But the most important one is that there can't be spaces in a variable name. 73 00:04:01,340 --> 00:04:04,760 So if we say first and I wanted to call this. 74 00:04:04,760 --> 00:04:06,130 We'll move her over here. 75 00:04:06,130 --> 00:04:07,540 So we wanna say first, 76 00:04:07,540 --> 00:04:11,710 and then this is where I would say first space name if I was just naming something. 77 00:04:12,890 --> 00:04:14,648 But we can't have spaces in a variable name. 78 00:04:14,648 --> 00:04:18,060 So what you do, is where you would normally put a space, 79 00:04:18,060 --> 00:04:19,610 you use an underscore. 80 00:04:19,610 --> 00:04:22,700 So we'll put underscore, that's next to the zero key on your keyboard. 81 00:04:22,700 --> 00:04:25,100 I know that that's one that you probably don't use very often. 82 00:04:25,100 --> 00:04:27,300 And then you put the next word so, name. 83 00:04:27,300 --> 00:04:31,350 And you assign object to the label using the equal sign. 84 00:04:31,350 --> 00:04:32,676 This is called assignment. 85 00:04:32,676 --> 00:04:39,580 So the string Ada is assigned to the first_name variable. 86 00:04:39,580 --> 00:04:45,400 And now the first_name variable refers to this string object that we created, Ada. 87 00:04:47,070 --> 00:04:49,150 So let's use it. 88 00:04:49,150 --> 00:04:52,420 But one thing to notice is that we've kept the variable name all lower case. 89 00:04:52,420 --> 00:04:54,250 Remember, case matters. 90 00:04:54,250 --> 00:04:56,740 And it makes a difference in your variable names as well. 91 00:04:56,740 --> 00:04:59,620 We follow the typical Python naming convention. 92 00:04:59,620 --> 00:05:01,570 You keep you variable names lower case. 93 00:05:01,570 --> 00:05:04,030 And you use underscores to separate words. 94 00:05:04,030 --> 00:05:07,430 A fun fact, this naming style is often called snake case. 95 00:05:07,430 --> 00:05:08,800 More in the teacher's notes. 96 00:05:08,800 --> 00:05:11,280 So, first_name is our string, right? 97 00:05:11,280 --> 00:05:12,600 So we should just be able to use it. 98 00:05:12,600 --> 00:05:17,897 So lets see, if I come in here and I just say print(first_name), 99 00:05:17,897 --> 00:05:21,740 let's go see, so I'm gonna use the up arrow, let's see what that did. 100 00:05:21,740 --> 00:05:25,360 We should see Ada and then Hello, Craig. 101 00:05:25,360 --> 00:05:26,840 Awesome, it's right there. 102 00:05:26,840 --> 00:05:30,900 So, in order to fix these other statements we're going to 103 00:05:30,900 --> 00:05:34,050 first explore a little something about the print function. 104 00:05:34,050 --> 00:05:40,215 So the print function as we've used it, is just taking a single argument, right? 105 00:05:40,215 --> 00:05:42,455 We're just giving it one argument here. 106 00:05:42,455 --> 00:05:44,515 Well, it actually takes multiple arguments. 107 00:05:44,515 --> 00:05:47,325 Remember when I talked about the ellipses just briefly when we looked at that 108 00:05:47,325 --> 00:05:48,495 help documentation? 109 00:05:48,495 --> 00:05:52,885 So, what happens is that each value that you add to the print function is printed, 110 00:05:52,885 --> 00:05:56,785 one after the other, separated by spaces by default. 111 00:05:56,785 --> 00:05:57,325 Like this, here. 112 00:05:57,325 --> 00:05:58,025 Here, check this out. 113 00:05:58,025 --> 00:05:59,905 So, if we come in here and we say print. 114 00:06:01,520 --> 00:06:04,900 Now, I'm just gonna create a string called These. 115 00:06:04,900 --> 00:06:09,480 And then I'm going to add a new argument and I do that by typing a comma. 116 00:06:09,480 --> 00:06:13,750 And now I'll type a new string, let's say, will be. 117 00:06:13,750 --> 00:06:17,320 And I'm gonna close that string and then I'll do one more so 118 00:06:17,320 --> 00:06:20,355 we can see that there's just another argument with a comma. 119 00:06:20,355 --> 00:06:26,390 And joined together by spaces. 120 00:06:26,390 --> 00:06:29,150 So if I'm gonna save that and if I just run that one more time, 121 00:06:30,530 --> 00:06:34,790 we'll see each of these strings one after the other separated by spaces. 122 00:06:36,490 --> 00:06:39,740 So let's go ahead and rewrite this line first, so 123 00:06:39,740 --> 00:06:41,860 that we can see them next to each other. 124 00:06:41,860 --> 00:06:44,300 Right, so I'm gonna go ahead, give ourselves some space here. 125 00:06:44,300 --> 00:06:47,740 I'll say print, and I want the first part to be the same. 126 00:06:47,740 --> 00:06:50,980 I want that Hello, that's kind of gonna be the same no matter what. 127 00:06:50,980 --> 00:06:52,570 We'll say, Hello comma. 128 00:06:52,570 --> 00:06:54,510 But now I want to end my string. 129 00:06:55,950 --> 00:06:58,660 And then we want to show our first_name. 130 00:06:58,660 --> 00:07:03,339 So we're going to do a comma, See there's a comma in the string but 131 00:07:03,339 --> 00:07:08,085 there's also a comma on the outside here, cuz that's separating our arguments. 132 00:07:08,085 --> 00:07:09,915 So we're gonna add our next argument. 133 00:07:09,915 --> 00:07:15,810 We'll do first_name, and then we'll close the function call. 134 00:07:17,448 --> 00:07:20,945 So we should see, Hello, Craig, Hello, Ada. 135 00:07:22,790 --> 00:07:24,700 And we do, awesome. 136 00:07:24,700 --> 00:07:26,750 So let's get rid of some of these other lines. 137 00:07:26,750 --> 00:07:29,880 So I'm gonna come here and in the Edit menu if you come here. 138 00:07:29,880 --> 00:07:32,940 You can see that there is a Delete Line. 139 00:07:32,940 --> 00:07:35,310 Which is Shift+Cmd D on a Mac. 140 00:07:35,310 --> 00:07:38,477 I believe it's probably Shift+Ctrl D on Windows. 141 00:07:38,477 --> 00:07:39,720 So I'm gonna go ahead and press that. 142 00:07:39,720 --> 00:07:41,590 You'll see the line went away, but if I come here and 143 00:07:41,590 --> 00:07:44,960 I do Shift+Cmd+D, it goes away. 144 00:07:44,960 --> 00:07:50,530 Now if you mess that up, there is always Edit, Undo, and it will come back, right. 145 00:07:50,530 --> 00:07:53,680 And that was Edit, Undo is Cmd+Z. 146 00:07:53,680 --> 00:07:55,380 And there's a redo, Shift+Cmd+Z. 147 00:07:55,380 --> 00:07:59,106 So if I press Cmd+Z, it will go away and Shift+Cmd+Z they'll go away again. 148 00:07:59,106 --> 00:08:04,000 Cool, so let's rewrite this 149 00:08:04,000 --> 00:08:07,170 learning Python using our variable just like this is. 150 00:08:07,170 --> 00:08:11,221 So we'll say, print, 151 00:08:12,878 --> 00:08:16,560 and actually, why don't you go ahead, and give that a go? 152 00:08:16,560 --> 00:08:19,070 Why don't you make that line, use our variable so 153 00:08:19,070 --> 00:08:20,920 that it says Ada is learning Python. 154 00:08:21,950 --> 00:08:24,600 Pause me, and try to finish the line. 155 00:08:24,600 --> 00:08:27,240 When you're done, unpause me, and I'll show you how I did it. 156 00:08:27,240 --> 00:08:30,040 Now don't worry, you won't break anything, remember? 157 00:08:30,040 --> 00:08:31,120 Ready, Pause me. 158 00:08:32,860 --> 00:08:34,010 So how'd you do? 159 00:08:34,010 --> 00:08:35,310 Here's what i did. 160 00:08:35,310 --> 00:08:37,530 I used our variable first, right? 161 00:08:37,530 --> 00:08:43,460 So, I said, first_name, and then I wanted to add another argument so 162 00:08:43,460 --> 00:08:46,890 I typed a comma and then the remainder of the string. 163 00:08:46,890 --> 00:08:51,670 Now, I'm lazy so I just copied this, came like this, and I did copy and I pasted it. 164 00:08:52,820 --> 00:08:57,480 Close that string here at the end and close the call. 165 00:08:58,580 --> 00:08:59,350 There we go. 166 00:08:59,350 --> 00:09:02,630 And if we come down here, we can clear this. 167 00:09:02,630 --> 00:09:04,500 We press up a couple times, there we go. 168 00:09:05,530 --> 00:09:08,350 Ada is learning Python, I bet she'd love Python. 169 00:09:09,450 --> 00:09:12,560 One final thing that I'd like to point out about our variable, 170 00:09:12,560 --> 00:09:14,840 is that you can actually label any object. 171 00:09:14,840 --> 00:09:15,946 So let's do this. 172 00:09:15,946 --> 00:09:19,010 Let's assign the variable first_name a number. 173 00:09:19,010 --> 00:09:22,010 So let's say, 11. 174 00:09:22,010 --> 00:09:25,190 Right, so now we go and we run it. 175 00:09:26,900 --> 00:09:29,200 And it says 11 is learning Python. 176 00:09:29,200 --> 00:09:31,420 Not a common name, but I've seen stranger things. 177 00:09:31,420 --> 00:09:34,780 11 would love Python too I'm pretty sure. 178 00:09:34,780 --> 00:09:37,820 Aren't you glad that we stored that object for later use? 179 00:09:37,820 --> 00:09:40,310 It's just like those leftovers, mm. 180 00:09:40,310 --> 00:09:41,030 Ooh, that reminds me. 181 00:09:41,030 --> 00:09:45,150 I'm gonna go retrieve my tacos from the fridge by using the label. 182 00:09:45,150 --> 00:09:46,410 After this delicious break, 183 00:09:46,410 --> 00:09:49,910 we'll talk about how to add a little interactivity to our script. 184 00:09:49,910 --> 00:09:50,860 Taco to you soon.