1 00:00:00,000 --> 00:00:04,200 And let's now see what are variables in Python. So 2 00:00:04,200 --> 00:00:07,440 here we have just worked with numbers, okay? And 3 00:00:07,440 --> 00:00:09,960 you can see that so whenever we work with a number 4 00:00:09,960 --> 00:00:13,920 if I want to use number 3, okay, I just print 5 00:00:13,950 --> 00:00:16,800 3, but then well, the 3 is just gone. 6 00:00:16,830 --> 00:00:20,400 Okay? What if I want to keep a value that I can 7 00:00:20,400 --> 00:00:23,850 use later. Well I can use a variable, and to use a 8 00:00:23,850 --> 00:00:26,640 variable, it's very simple, you first have to give 9 00:00:26,670 --> 00:00:28,740 a name to the variable, let's name the first 10 00:00:28,740 --> 00:00:33,270 variable a, and then put an equal sign, and then 11 00:00:33,270 --> 00:00:37,050 put a value, let's put 3. So here, this 12 00:00:37,080 --> 00:00:40,740 statement, this instruction is basically, but 13 00:00:40,770 --> 00:00:46,290 three inside the variable named a, I press enter, 14 00:00:46,920 --> 00:00:50,850 okay, and here, nothing is printed. The 15 00:00:50,850 --> 00:00:54,480 instruction is just to put the value inside the 16 00:00:54,480 --> 00:00:59,220 variable. Now what I can do, I can just write a and 17 00:00:59,220 --> 00:01:03,120 press enter, and now you can see a is evaluated to 18 00:01:03,120 --> 00:01:06,690 3. And the good news is that now that I have 19 00:01:06,690 --> 00:01:09,870 this variable, I can continue to use it. So 20 00:01:10,200 --> 00:01:13,290 whenever I'm going to call a, I'm going to get the 21 00:01:13,290 --> 00:01:16,080 value 3, again, create another variable, let's 22 00:01:16,080 --> 00:01:20,100 name it b, b is equal to and I can also use some 23 00:01:20,100 --> 00:01:22,830 computation that we have seen before, let's say 24 00:01:22,830 --> 00:01:29,310 four times two. Okay, and now if I get b, b is 25 00:01:29,310 --> 00:01:34,170 equal to eight. If I get b again, b is equal to 26 00:01:34,200 --> 00:01:37,740 eight, and a is still here. Okay, so I can use a 27 00:01:37,770 --> 00:01:41,280 and I can use b. Now let's create another variable 28 00:01:41,280 --> 00:01:44,250 named c, and this time, what I'm going to do is 29 00:01:44,250 --> 00:01:46,500 I'm going to create this variable from the 30 00:01:46,500 --> 00:01:51,330 previous variables that we have. So a plus b, I 31 00:01:51,330 --> 00:01:55,170 press enter, and now what do we have in c, we have 32 00:01:55,230 --> 00:01:58,590 11. Because at this time, a is going to be 33 00:01:58,620 --> 00:02:03,360 evaluated to its value, which is here, three, b is 34 00:02:03,360 --> 00:02:06,510 going to be evaluated to eight, and so c is equal 35 00:02:06,510 --> 00:02:09,240 to 11. So you can create variables. And to do 36 00:02:09,240 --> 00:02:12,210 that, it's very simple. You put a name equal, and 37 00:02:12,210 --> 00:02:15,510 then some value, you can add as many operations 38 00:02:15,540 --> 00:02:18,360 you want. And you can also create variables from 39 00:02:18,390 --> 00:02:21,570 other variables. Now let's make a test. Let's say 40 00:02:21,570 --> 00:02:24,210 I change the value in a, instead of three, I'm 41 00:02:24,210 --> 00:02:28,950 going to put five. OK, and now let's see what we 42 00:02:28,950 --> 00:02:33,780 get in c. As you can see, c is still 11. Okay, the 43 00:02:33,780 --> 00:02:38,760 variable c has changed to five, but c is still 11. 44 00:02:38,820 --> 00:02:42,870 Okay, why is that? Because simply when we assign a 45 00:02:42,870 --> 00:02:48,450 value to c, we evaluated a at this point, okay, at 46 00:02:48,450 --> 00:02:51,570 this time, and that's it. If you change a 47 00:02:51,600 --> 00:02:55,500 afterwards, c is not going to be changed. Okay, so 48 00:02:55,500 --> 00:02:58,590 the other of the operation, as you can see is very 49 00:02:58,620 --> 00:03:02,370 important. Because now if I do c is equal to a 50 00:03:02,670 --> 00:03:07,590 plus b, c will be equal to 30. Okay, because I'm 51 00:03:07,650 --> 00:03:10,950 evaluating c and assigning the new value to c 52 00:03:10,980 --> 00:03:15,090 after I have modified a, okay, so here, a was 53 00:03:15,090 --> 00:03:19,260 equal to three, here, c is equal to five, okay, so 54 00:03:19,290 --> 00:03:22,710 variable, you can modify a variable during the 55 00:03:22,740 --> 00:03:25,710 program during the execution. So there is a notion 56 00:03:25,740 --> 00:03:29,460 also of time, okay? The variable can have 57 00:03:29,460 --> 00:03:32,610 different values of a time, depending on if you 58 00:03:32,610 --> 00:03:35,940 modify it, of course. Okay, one other thing I want 59 00:03:35,940 --> 00:03:39,600 to show you is, if I, let's say, I try to get a 60 00:03:39,660 --> 00:03:44,280 case like this, you can see we have an error, NameError: 61 00:03:44,280 --> 00:03:47,370 name A is not defined, okay? Because you 62 00:03:47,370 --> 00:03:52,050 have to respect the case, okay, a, b, c, we have 63 00:03:52,050 --> 00:03:56,280 defined three variables. If I tried to just let's 64 00:03:56,280 --> 00:04:00,420 say test, okay, if I tried to get any other name 65 00:04:00,450 --> 00:04:03,840 for any other variable, I'm going to get an error. 66 00:04:04,110 --> 00:04:06,600 So make sure that you use the exact same name of 67 00:04:06,600 --> 00:04:09,800 the variable, okay, when you call it. And then one last 68 00:04:09,840 --> 00:04:13,380 thing for variable is that, okay, we use a, b, and 69 00:04:13,380 --> 00:04:16,440 c for names for now. So this is nice. And this is 70 00:04:16,440 --> 00:04:19,950 good when we want to make some tests or some very 71 00:04:19,950 --> 00:04:23,100 simple program. But in the future, when we write 72 00:04:23,160 --> 00:04:25,860 real programs, we are going to use meaningful 73 00:04:25,860 --> 00:04:29,520 names for the variables. This is kind of your first best 74 00:04:29,520 --> 00:04:32,700 practice, and this is maybe one of the most 75 00:04:32,730 --> 00:04:35,790 important ones. So let's say you want to store 76 00:04:35,820 --> 00:04:39,060 here, we just use a, b, c for just numbers. Now let's 77 00:04:39,060 --> 00:04:41,940 say you want to store a temperature. So if you 78 00:04:41,940 --> 00:04:43,860 want to store temperature, you're going to write 79 00:04:43,860 --> 00:04:46,770 for example, temperature. That will be the name of 80 00:04:46,770 --> 00:04:49,830 the variable is equal to and let's say 25. 81 00:04:50,820 --> 00:04:54,300 So now you have the temperature variable, temperature 82 00:04:54,360 --> 00:04:58,140 25. If you want to store the age of the user, well 83 00:04:58,140 --> 00:05:01,290 maybe you can just write user_age is equal to 84 00:05:01,350 --> 00:05:07,440 and let's say 45. And then user_age, 45. Note that 85 00:05:07,560 --> 00:05:11,220 so this is a convention I'm going to use okay with 86 00:05:11,220 --> 00:05:15,690 Python is when you want to use different words 87 00:05:15,720 --> 00:05:19,080 for one variable, so this is possible to separate 88 00:05:19,080 --> 00:05:21,210 the words, you're simply going to use an 89 00:05:21,270 --> 00:05:24,750 underscore like this. Okay? You don't use any 90 00:05:24,810 --> 00:05:29,190 uppercase letter, just underscore between any word 91 00:05:29,250 --> 00:05:33,630 of a variable. Alright, so to recap, a variable is 92 00:05:33,630 --> 00:05:37,050 a container that you can use to store value, and 93 00:05:37,050 --> 00:05:40,680 reuse that value later. To create a variable, you 94 00:05:40,680 --> 00:05:45,100 must first give it a name and then assign a value to it.