1 00:00:00,000 --> 00:00:04,000 And let's now see what are variables in Python. 2 00:00:04,001 --> 00:00:07,000 So here we have just worked with numbers, okay? 3 00:00:07,001 --> 00:00:10,125 And you can see that, so whenever we work with 4 00:00:10,137 --> 00:00:13,000 a number, if I want to use number 3, okay? 5 00:00:13,001 --> 00:00:17,000 I just print 3, but then, well, the 3 is just gone, okay? 6 00:00:17,001 --> 00:00:22,000 What if I want to keep a value that I can use later? 7 00:00:22,001 --> 00:00:23,000 Well, I can use a variable. 8 00:00:23,001 --> 00:00:25,000 And to use a variable, it's very simple. 9 00:00:25,001 --> 00:00:28,000 You first have to give a name to the variable. 10 00:00:28,001 --> 00:00:34,000 Let's name the first variable a and then put an equal sign and then put a value. 11 00:00:34,001 --> 00:00:35,000 Let's put 3. 12 00:00:35,001 --> 00:00:39,539 So here, this statement, this instruction, is 13 00:00:39,551 --> 00:00:44,000 basically put 3 inside the variable named a. 14 00:00:44,001 --> 00:00:48,000 I press enter, okay? 15 00:00:48,001 --> 00:00:50,000 And here, nothing is printed. 16 00:00:50,001 --> 00:00:55,000 The instruction is just to put the value inside the variable. 17 00:00:55,001 --> 00:01:00,000 Now, what I can do, I can just write a and press enter. 18 00:01:00,001 --> 00:01:04,000 And now you can see a is evaluated to 3. 19 00:01:04,001 --> 00:01:09,000 And the good news is that now that I have this variable, I can continue to use it. 20 00:01:09,001 --> 00:01:14,000 So whenever I'm going to call a, I'm going to get the value 3. 21 00:01:14,001 --> 00:01:16,000 I can create another variable. 22 00:01:16,001 --> 00:01:17,000 Let's name it b. 23 00:01:17,001 --> 00:01:22,000 b is equal to, and I can also use some computation that we have seen before. 24 00:01:22,001 --> 00:01:24,000 Let's say 4 times 2. 25 00:01:26,000 --> 00:01:30,000 Okay, and now if I get b, b is equal to 8. 26 00:01:30,001 --> 00:01:35,000 Okay, and if I get b again, b is equal to 8. 27 00:01:35,001 --> 00:01:37,000 And a is still here, okay? 28 00:01:37,001 --> 00:01:38,000 So I can use a and I can use b. 29 00:01:38,001 --> 00:01:42,000 Now let's create another variable named c. 30 00:01:42,001 --> 00:01:46,000 And this time, what I'm going to do is I'm going to create 31 00:01:46,001 --> 00:01:49,000 this variable from the previous variables that we have. 32 00:01:49,001 --> 00:01:50,000 So a plus b. 33 00:01:50,001 --> 00:01:52,000 I press enter. 34 00:01:52,001 --> 00:01:55,000 And now what do we have in c? 35 00:01:55,001 --> 00:01:56,000 We have 11. 36 00:01:56,001 --> 00:02:02,000 Because at this time, a is going to be evaluated to its value, which is here 3. 37 00:02:02,001 --> 00:02:05,000 b is going to be evaluated to 8. 38 00:02:05,001 --> 00:02:07,000 And so c is equal to 11. 39 00:02:07,001 --> 00:02:09,000 So you can create variables. 40 00:02:09,001 --> 00:02:10,000 And to do that, it's very simple. 41 00:02:10,001 --> 00:02:13,000 You put a name, equal, and then some value. 42 00:02:13,001 --> 00:02:16,000 You can add as many operations you want. 43 00:02:16,001 --> 00:02:20,000 And you can also create variables from other variables. 44 00:02:20,001 --> 00:02:21,000 Now let's make a test. 45 00:02:21,001 --> 00:02:23,000 Let's say I change the value in a. 46 00:02:23,001 --> 00:02:25,000 Instead of 3, I'm going to put 5. 47 00:02:25,001 --> 00:02:30,000 Okay, and now let's see what we get in c. 48 00:02:30,001 --> 00:02:34,000 As you can see, c is still 11, okay? 49 00:02:34,001 --> 00:02:39,000 The variable a has changed to 5, but c is still 11, okay? 50 00:02:39,001 --> 00:02:40,000 Why is that? 51 00:02:40,001 --> 00:02:48,000 Because simply when we assigned a value to c, we evaluated a at this point, okay? 52 00:02:48,001 --> 00:02:49,000 At this time. 53 00:02:49,001 --> 00:02:50,000 And that's it. 54 00:02:50,001 --> 00:02:54,000 If you change a afterwards, c is not going to be changed. 55 00:02:54,001 --> 00:03:00,000 Okay, so the order of the operation, as you can see, is very important. 56 00:03:00,001 --> 00:03:07,000 Because now if I do c is equal to a plus b, c will be equal to 13, okay? 57 00:03:07,001 --> 00:03:10,326 Because I'm evaluating c, I'm assigning a 58 00:03:10,338 --> 00:03:14,000 new value to c after I have modified a, okay? 59 00:03:14,001 --> 00:03:16,000 So here a was equal to 3. 60 00:03:16,001 --> 00:03:19,000 Here a is equal to 5. 61 00:03:19,001 --> 00:03:21,632 Okay, so a variable, you can modify a variable 62 00:03:21,644 --> 00:03:24,000 during the program, during the execution. 63 00:03:24,001 --> 00:03:28,000 So there is a notion also of time, okay? 64 00:03:28,001 --> 00:03:30,855 The variable can have different values over 65 00:03:30,867 --> 00:03:34,000 time, depending on if you modify it, of course. 66 00:03:34,001 --> 00:03:36,894 Okay, one other thing I want to show you is if 67 00:03:36,906 --> 00:03:40,000 I, let's say I try to get a upper case like this. 68 00:03:40,001 --> 00:03:47,000 You can see we have an error, name error, name a is not defined, okay? 69 00:03:47,001 --> 00:03:49,000 Because you have to respect the case, okay? 70 00:03:49,001 --> 00:03:52,000 a, b, c. 71 00:03:52,001 --> 00:03:54,000 We have defined three variables. 72 00:03:54,001 --> 00:03:58,000 If I try to just, let's say test, okay? 73 00:03:58,001 --> 00:04:04,000 If I try to get any other name for any other variable, I'm going to get an error. 74 00:04:04,001 --> 00:04:09,000 So make sure that you use the exact same name of a variable, okay, when you call it. 75 00:04:09,001 --> 00:04:12,057 And then one last thing for variable is that, 76 00:04:12,069 --> 00:04:15,000 okay, we use a, b, and c for names for now. 77 00:04:15,001 --> 00:04:17,956 So this is nice, and this is good when we want 78 00:04:17,968 --> 00:04:21,000 to make some tests or some very simple program. 79 00:04:21,001 --> 00:04:23,930 But in the future, when we write real programs, we 80 00:04:23,942 --> 00:04:27,000 are going to use meaningful names for the variables. 81 00:04:27,001 --> 00:04:30,489 This is kind of your first best practice, and 82 00:04:30,501 --> 00:04:34,000 this is maybe one of the most important ones. 83 00:04:34,001 --> 00:04:38,000 So let's say you want to store here, we just use a, b, c for just numbers. 84 00:04:38,001 --> 00:04:41,000 Now let's say you want to store a temperature. 85 00:04:41,001 --> 00:04:43,605 So if you want to store a temperature, you're 86 00:04:43,617 --> 00:04:46,000 going to write, for example, temperature. 87 00:04:46,001 --> 00:04:51,000 That will be the name of the variable is equal to, and let's say, 25. 88 00:04:51,001 --> 00:04:55,000 So now you have a temperature variable, temperature 25. 89 00:04:55,001 --> 00:04:58,021 If you want to store the age of the user, well, 90 00:04:58,033 --> 00:05:04,000 maybe you can just write user age is equal to, and let's say 45. 91 00:05:04,001 --> 00:05:07,000 And then user age 45. 92 00:05:07,001 --> 00:05:12,000 Note that, so this is a convention I'm going to use, okay, with Python, 93 00:05:12,001 --> 00:05:18,000 is when you want to use different words for one variable, so this is possible, 94 00:05:18,001 --> 00:05:23,000 to separate the words, you are simply going to use an underscore like this, okay. 95 00:05:23,001 --> 00:05:31,000 You don't use any uppercase letter, just underscore between any word of a variable. 96 00:05:31,001 --> 00:05:37,000 All right, so to recap, a variable is a container that 97 00:05:37,001 --> 00:05:39,000 you can use to store a value and reduce that value later. 98 00:05:39,001 --> 00:05:45,000 To create a variable, you must first give it a name and then assign a value to it.