1 00:00:00,410 --> 00:00:01,370 Welcome back. 2 00:00:01,400 --> 00:00:05,190 So we've just learned about the first two. 3 00:00:05,210 --> 00:00:12,200 Well, kind of three, because we also mentioned that there is such a thing as a complex number in Python, 4 00:00:12,200 --> 00:00:18,470 but we talked about the main ones that int and float and there are still a few data types remaining. 5 00:00:19,400 --> 00:00:23,840 But before we get to these, we are missing an important concept. 6 00:00:24,050 --> 00:00:30,170 And this is going to be our first important term in Python and as a matter of fact, in all programming 7 00:00:30,170 --> 00:00:30,920 languages. 8 00:00:31,590 --> 00:00:33,550 It's called variables. 9 00:00:33,570 --> 00:00:34,110 Yep. 10 00:00:34,560 --> 00:00:35,490 That's a term. 11 00:00:36,320 --> 00:00:41,960 Now, if this is your first time learning a programming language, you might not know what this means 12 00:00:41,960 --> 00:00:43,610 if this isn't your first time. 13 00:00:43,610 --> 00:00:47,630 Well, this is very simple, because all languages have variables. 14 00:00:48,020 --> 00:00:50,720 But what are they exactly? 15 00:00:51,230 --> 00:01:00,320 Well, variables store information that can be used in our programs so we can hold perhaps user inputs 16 00:01:00,320 --> 00:01:01,430 like values. 17 00:01:01,670 --> 00:01:09,110 Maybe when you log into Facebook, you need to hold some information such as your profile picture or 18 00:01:09,110 --> 00:01:12,620 maybe your date of birth in a variable. 19 00:01:13,250 --> 00:01:17,510 Variables are ways for us to store information on our computer. 20 00:01:18,280 --> 00:01:19,780 So let's have a look at this. 21 00:01:20,260 --> 00:01:24,880 If we remove this and let's say I'm creating a quiz program. 22 00:01:25,930 --> 00:01:29,560 And this quiz program maybe measures your IQ. 23 00:01:30,010 --> 00:01:36,130 And let's say you just took the quiz and you found out that your IQ is 190 quite high. 24 00:01:36,160 --> 00:01:40,210 Good job, but we need to store that information somewhere. 25 00:01:40,840 --> 00:01:47,770 Well, we can do that with variables so that in Python, all we need to do is name it whatever you want. 26 00:01:47,770 --> 00:01:54,430 In our case, it will be IQ and we're going to say IQ equals 190. 27 00:01:55,610 --> 00:01:59,600 And this IQ here is a variable. 28 00:01:59,810 --> 00:02:02,610 It is something that I just completely made up. 29 00:02:02,630 --> 00:02:04,640 I could name it whatever I want. 30 00:02:04,670 --> 00:02:06,260 That's a variable, too. 31 00:02:06,860 --> 00:02:14,390 The idea is that once we assign to a variable, that is, we're saying 190 is going to be assigned to 32 00:02:14,390 --> 00:02:15,080 IQ. 33 00:02:15,110 --> 00:02:18,060 I can now use it in my program whenever I want. 34 00:02:18,080 --> 00:02:23,660 For example, I can later on print or make sure it's not cap. 35 00:02:23,750 --> 00:02:25,640 Let's do print IQ. 36 00:02:26,000 --> 00:02:30,050 And if I do that and click run, you see that I can use IQ. 37 00:02:30,900 --> 00:02:37,330 So we can pretend here that a user takes a quiz, finds out their IQ is 190. 38 00:02:37,350 --> 00:02:40,020 We can store that information in this variable. 39 00:02:40,020 --> 00:02:45,780 And later on, when they come perhaps online or try to use the program again, they don't have to take 40 00:02:45,780 --> 00:02:49,800 the quiz all over because, well, we store that information in IQ. 41 00:02:51,380 --> 00:02:52,960 And remember what I said at the beginning. 42 00:02:52,970 --> 00:03:00,800 Programs are simply data that's being stored, that's being changed, that's being removed, and that's 43 00:03:00,800 --> 00:03:01,760 all programs are. 44 00:03:01,760 --> 00:03:05,780 And variables are important concepts in Python and all languages. 45 00:03:06,410 --> 00:03:09,380 Now, variables can also sometimes be called names. 46 00:03:09,380 --> 00:03:12,110 So this could be a name, for example. 47 00:03:12,110 --> 00:03:16,460 And assigning a value is also known as binding. 48 00:03:16,730 --> 00:03:25,220 That is, we're binding the value 190 to this variable so that when we request this variable later on 49 00:03:25,220 --> 00:03:29,720 in our program, our computer knows how to look for this information. 50 00:03:29,720 --> 00:03:32,330 It's going to say, Hey, I know what IQ is. 51 00:03:32,330 --> 00:03:36,380 I stored it somewhere in memory and it's going to go look for that. 52 00:03:36,620 --> 00:03:42,800 And because it's being bound to a value, it points to this value. 53 00:03:42,800 --> 00:03:51,680 190 And remember, this number in memory gets stored as a binary representation in zeros and ones, 54 00:03:51,680 --> 00:03:52,310 right? 55 00:03:52,790 --> 00:03:57,320 But it doesn't matter to us because however our machine stores it, we don't care. 56 00:03:57,320 --> 00:03:59,000 We just want to be able to retrieve it. 57 00:03:59,000 --> 00:04:02,720 And then when we print it to do well, get 180. 58 00:04:03,200 --> 00:04:07,190 Now we're going to be using variables all over the course. 59 00:04:07,280 --> 00:04:16,519 But on top of just naming variables however we want, there is some best practices around variables 60 00:04:16,519 --> 00:04:19,279 of how you should write good variables. 61 00:04:19,550 --> 00:04:25,550 And as a matter of fact, these are specific rules that the Python community as a whole has that you'll 62 00:04:25,550 --> 00:04:26,620 just have to remember. 63 00:04:26,630 --> 00:04:33,290 So let's have a look at this variables and remember this is the symbol for best practices are what we 64 00:04:33,290 --> 00:04:35,240 call snake case. 65 00:04:35,970 --> 00:04:41,790 Snake gas means it's all lowercase and then spaces well they don't exist. 66 00:04:41,790 --> 00:04:48,210 We use underscores variables must start with a lowercase or an underscore. 67 00:04:48,840 --> 00:04:54,090 Variables can be anything with letters, numbers and underscores. 68 00:04:54,180 --> 00:05:01,230 But remember, they have to start with lowercase and underscore that means we can start a variable with 69 00:05:01,230 --> 00:05:01,860 a number. 70 00:05:02,040 --> 00:05:04,170 They're also case sensitive. 71 00:05:04,410 --> 00:05:12,150 That means if I create a variable, but let's say this snake case, this variable has a capital E instead 72 00:05:12,150 --> 00:05:15,120 of a lowercase E, they'll be a different variable. 73 00:05:16,000 --> 00:05:19,390 And then finally you can't overwrite keywords. 74 00:05:20,190 --> 00:05:22,290 Let's go through these with some examples. 75 00:05:23,280 --> 00:05:27,240 First, a variable has to be in the form of a snake case. 76 00:05:27,270 --> 00:05:34,920 That is, if I want to call this user IQ, I should technically have an underscore here instead of a 77 00:05:34,920 --> 00:05:41,520 space just to make sure that a programmer maybe I'm working on a team can read this variable. 78 00:05:42,520 --> 00:05:44,890 So that's snake case. 79 00:05:45,130 --> 00:05:53,740 You also have to start your variables with either a letter or an underscore so I can technically do 80 00:05:53,740 --> 00:05:55,510 this and I click run. 81 00:05:55,750 --> 00:05:59,140 Well, that's going to give me an error because I've changed a variable. 82 00:05:59,140 --> 00:06:03,520 So now in order to access that variable, you have to go like this. 83 00:06:03,970 --> 00:06:10,540 Now underscore in Python signifies a private variable, something that we'll go over later on in the 84 00:06:10,540 --> 00:06:11,110 course. 85 00:06:11,660 --> 00:06:17,690 But usually you're starting your variables with a letter and afterwards. 86 00:06:17,690 --> 00:06:20,300 Yeah, you can add numbers if you want in here. 87 00:06:20,300 --> 00:06:21,380 That's no problem. 88 00:06:21,500 --> 00:06:23,110 This is still going to work. 89 00:06:23,120 --> 00:06:25,010 This is a valid variable. 90 00:06:25,720 --> 00:06:28,870 Finally, a variable is case sensitive. 91 00:06:28,960 --> 00:06:34,720 So if I do user IQ here and I do capital letters. 92 00:06:35,570 --> 00:06:37,400 I can't access this. 93 00:06:41,500 --> 00:06:44,710 Like this because, well, it doesn't exist. 94 00:06:44,710 --> 00:06:46,000 Again, it's case sensitive. 95 00:06:46,010 --> 00:06:48,100 We have to make sure that we match. 96 00:06:50,110 --> 00:06:53,860 And finally, we don't want to overwrite key words. 97 00:06:54,100 --> 00:06:55,240 What does that mean? 98 00:06:55,910 --> 00:06:58,220 Key words in Python. 99 00:06:58,370 --> 00:07:01,370 Well, they already mean something in Python, for example. 100 00:07:01,370 --> 00:07:03,500 This print is a keyword. 101 00:07:03,500 --> 00:07:11,030 You can see it highlighted in blue, so that if I create a variable saying print equals 190 and then 102 00:07:11,030 --> 00:07:12,170 I do print. 103 00:07:12,170 --> 00:07:12,950 Print. 104 00:07:13,310 --> 00:07:13,650 Hmm. 105 00:07:13,670 --> 00:07:14,630 Let's see what happens. 106 00:07:16,220 --> 00:07:22,970 We get an error because I can't really assign to this variable because print already mean something. 107 00:07:23,720 --> 00:07:25,160 Now I know what you're wondering. 108 00:07:25,460 --> 00:07:27,590 What are these keywords in Python? 109 00:07:27,620 --> 00:07:31,960 That's a simple Google search away and we'll learn these throughout our course. 110 00:07:31,970 --> 00:07:39,650 If we go to Python keywords by three schools, you'll see that we have these keywords that each mean 111 00:07:39,650 --> 00:07:41,030 something in Python. 112 00:07:41,870 --> 00:07:42,470 Again. 113 00:07:42,470 --> 00:07:45,890 We'll go through these and we'll learn them throughout our course. 114 00:07:46,190 --> 00:07:48,650 And if you look, it's not that intimidating. 115 00:07:48,650 --> 00:07:49,970 There's not that many. 116 00:07:50,000 --> 00:07:53,630 So as we practice, you'll start to get familiar with them. 117 00:07:53,630 --> 00:07:59,780 But the easiest way to tell whether it's keyword or an important word in in Python, well, you see 118 00:07:59,780 --> 00:08:01,340 that it's highlighted in blue. 119 00:08:01,520 --> 00:08:06,740 As soon as you create a variable that is unique, it's highlighted in white. 120 00:08:06,740 --> 00:08:12,890 And this will be the case with whatever environment that you're typing code into as long as it's set 121 00:08:12,890 --> 00:08:13,820 up for Python. 122 00:08:14,240 --> 00:08:22,370 Now, beyond the Python keywords, there are different things like for example, the int for integer 123 00:08:22,370 --> 00:08:23,300 that we've learned. 124 00:08:23,920 --> 00:08:26,590 So these we're going to get familiar with. 125 00:08:26,590 --> 00:08:33,220 So a good rule of thumb for variables is to make them really descriptive, really say what your intention 126 00:08:33,220 --> 00:08:33,610 is. 127 00:08:33,789 --> 00:08:38,890 And a good programmer is somebody that's able to name things really well with their variables. 128 00:08:38,890 --> 00:08:44,140 So if a new developer comes and looks at your code, it's easily understood. 129 00:08:44,560 --> 00:08:48,010 Finally, variables can also be reassigned. 130 00:08:48,280 --> 00:08:57,070 For example, let's say we have IQ here of 190 and then I decide to perhaps have another variable, 131 00:08:57,460 --> 00:08:59,200 call it user. 132 00:09:00,170 --> 00:09:00,740 Age. 133 00:09:01,580 --> 00:09:11,420 And for some reason I want to assign user H to perhaps have IQ divided by four. 134 00:09:12,400 --> 00:09:13,540 Is that going to work? 135 00:09:14,330 --> 00:09:15,170 It should. 136 00:09:15,200 --> 00:09:15,680 Right. 137 00:09:15,680 --> 00:09:20,990 I'm saying user age is going to equal 47.5. 138 00:09:21,630 --> 00:09:29,720 I'm using IQ, which is 190, dividing it by four and then assigning it to user age. 139 00:09:30,290 --> 00:09:37,220 I can maybe assign this to another variable called user H or called A and once again. 140 00:09:38,020 --> 00:09:38,710 I. 141 00:09:39,380 --> 00:09:42,230 Run this and its printing the same thing. 142 00:09:42,680 --> 00:09:47,080 So you can use variables to store that information and use it whenever you want. 143 00:09:47,090 --> 00:09:48,800 You can use it in operations. 144 00:09:48,800 --> 00:09:50,960 You can use it to reassign it. 145 00:09:51,630 --> 00:09:53,610 Whatever your program needs. 146 00:09:53,910 --> 00:09:57,570 Now, later on in the course, we're going to learn about classes. 147 00:09:57,570 --> 00:10:03,090 And classes actually have a different convention than this, but we'll get to that later on. 148 00:10:03,630 --> 00:10:09,120 For now, though, I want to mention two small gotchas with variables that you should be careful with. 149 00:10:09,800 --> 00:10:13,670 For example, there's an idea of constants. 150 00:10:14,090 --> 00:10:18,350 And constants are those things that never change in a program. 151 00:10:18,950 --> 00:10:26,840 For example, if we wanted to create a constant such as the value of PI, let's say for now it's 3.14. 152 00:10:27,200 --> 00:10:29,990 We can have it all in capitals. 153 00:10:30,260 --> 00:10:34,370 And that's going to tell other programmers that, hey, this is a constant. 154 00:10:34,370 --> 00:10:36,600 This number is not meant to change. 155 00:10:36,620 --> 00:10:39,830 I mean, we could change it if we want. 156 00:10:41,060 --> 00:10:41,810 There you go. 157 00:10:41,810 --> 00:10:47,210 I just made PI equal to zero, so it was stored as 3.1 for a memory. 158 00:10:47,210 --> 00:10:50,000 But then we overrode it and reassigned it. 159 00:10:50,360 --> 00:10:51,770 The value of zero. 160 00:10:52,250 --> 00:10:53,510 You can still do that. 161 00:10:53,510 --> 00:10:59,990 But a good convention is that if you see this, that means that this number or this value should never 162 00:10:59,990 --> 00:11:00,710 be changed. 163 00:11:00,950 --> 00:11:05,960 Another type of variable that you're going to see and this is something we'll see later on in the course 164 00:11:05,960 --> 00:11:06,830 are the. 165 00:11:06,860 --> 00:11:12,140 It doesn't look like I just did double underscore here, but it's two underscores and we call these 166 00:11:12,140 --> 00:11:18,590 dunder and as you can see here, we have some dunder variables that Python has. 167 00:11:19,700 --> 00:11:20,090 Now. 168 00:11:20,090 --> 00:11:21,980 We'll learn more about this later on. 169 00:11:21,980 --> 00:11:27,220 But the idea here is that these are meant to be left alone. 170 00:11:27,230 --> 00:11:28,730 You should not touch them. 171 00:11:28,730 --> 00:11:32,540 You shouldn't create a variable with two underscores. 172 00:11:33,210 --> 00:11:35,610 Like this and call it high. 173 00:11:35,610 --> 00:11:36,240 High. 174 00:11:36,920 --> 00:11:38,270 And assign it a value. 175 00:11:38,840 --> 00:11:40,450 I mean, you still can. 176 00:11:40,460 --> 00:11:45,770 However, this is generally not good practice, so you want to be careful with that. 177 00:11:46,610 --> 00:11:52,970 But the one thing that I really want you to take away from this is that variables are really important 178 00:11:52,970 --> 00:11:54,310 concepts and programming. 179 00:11:54,320 --> 00:11:59,180 Naming variables is one of the most important skills you have as a programmer. 180 00:11:59,180 --> 00:12:05,240 I know it sounds silly, but there's so many times that I read code that is so hard to understand simply 181 00:12:05,240 --> 00:12:08,430 because a programmer is not descriptive enough. 182 00:12:08,450 --> 00:12:16,640 So throughout the course we're going to learn how to name things well so that our code reads like English. 183 00:12:17,410 --> 00:12:20,320 And that's the whole point of writing a code. 184 00:12:20,350 --> 00:12:26,350 The point of writing a code is that it's readable and understandable by other programmers. 185 00:12:26,890 --> 00:12:30,190 By the way, to finish off, I just want to show you one quick trick. 186 00:12:30,460 --> 00:12:37,270 There's also a way that you might see in some code bases that uses something like this. 187 00:12:38,380 --> 00:12:40,390 Equals one, two, three. 188 00:12:41,080 --> 00:12:48,870 And this simply is a way for us to rapidly assign values to variables multiple times. 189 00:12:48,880 --> 00:12:57,400 So, for example, if I do print A, then print B, then print C and I run this. 190 00:12:58,370 --> 00:12:58,880 You see that? 191 00:12:58,880 --> 00:13:00,220 I get one, two, three. 192 00:13:00,230 --> 00:13:05,750 We assign value of one to a value of two to B and value of three to C. 193 00:13:06,560 --> 00:13:09,770 Just a quick shorthand way that you might encounter. 194 00:13:09,800 --> 00:13:10,310 All right. 195 00:13:10,310 --> 00:13:12,350 Let's take a break and I'll see you in the next one.