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