And let's now see what are variables in Python. So
here we have just worked with numbers, okay? And
you can see that so whenever we work with a number
if I want to use number 3, okay, I just print
3, but then well, the 3 is just gone.
Okay? What if I want to keep a value that I can
use later. Well I can use a variable, and to use a
variable, it's very simple, you first have to give
a name to the variable, let's name the first
variable a, and then put an equal sign, and then
put a value, let's put 3. So here, this
statement, this instruction is basically, but
three inside the variable named a, I press enter,
okay, and here, nothing is printed. The
instruction is just to put the value inside the
variable. Now what I can do, I can just write a and
press enter, and now you can see a is evaluated to
3. And the good news is that now that I have
this variable, I can continue to use it. So
whenever I'm going to call a, I'm going to get the
value 3, again, create another variable, let's
name it b, b is equal to and I can also use some
computation that we have seen before, let's say
four times two. Okay, and now if I get b, b is
equal to eight. If I get b again, b is equal to
eight, and a is still here. Okay, so I can use a
and I can use b. Now let's create another variable
named c, and this time, what I'm going to do is
I'm going to create this variable from the
previous variables that we have. So a plus b, I
press enter, and now what do we have in c, we have
11. Because at this time, a is going to be
evaluated to its value, which is here, three, b is
going to be evaluated to eight, and so c is equal
to 11. So you can create variables. And to do
that, it's very simple. You put a name equal, and
then some value, you can add as many operations
you want. And you can also create variables from
other variables. Now let's make a test. Let's say
I change the value in a, instead of three, I'm
going to put five. OK, and now let's see what we
get in c. As you can see, c is still 11. Okay, the
variable c has changed to five, but c is still 11.
Okay, why is that? Because simply when we assign a
value to c, we evaluated a at this point, okay, at
this time, and that's it. If you change a
afterwards, c is not going to be changed. Okay, so
the other of the operation, as you can see is very
important. Because now if I do c is equal to a
plus b, c will be equal to 30. Okay, because I'm
evaluating c and assigning the new value to c
after I have modified a, okay, so here, a was
equal to three, here, c is equal to five, okay, so
variable, you can modify a variable during the
program during the execution. So there is a notion
also of time, okay? The variable can have
different values of a time, depending on if you
modify it, of course. Okay, one other thing I want
to show you is, if I, let's say, I try to get a
case like this, you can see we have an error, NameError:
name A is not defined, okay? Because you
have to respect the case, okay, a, b, c, we have
defined three variables. If I tried to just let's
say test, okay, if I tried to get any other name
for any other variable, I'm going to get an error.
So make sure that you use the exact same name of
the variable, okay, when you call it. And then one last
thing for variable is that, okay, we use a, b, and
c for names for now. So this is nice. And this is
good when we want to make some tests or some very
simple program. But in the future, when we write
real programs, we are going to use meaningful
names for the variables. This is kind of your first best
practice, and this is maybe one of the most
important ones. So let's say you want to store
here, we just use a, b, c for just numbers. Now let's
say you want to store a temperature. So if you
want to store temperature, you're going to write
for example, temperature. That will be the name of
the variable is equal to and let's say 25.
So now you have the temperature variable, temperature
25. If you want to store the age of the user, well
maybe you can just write user_age is equal to
and let's say 45. And then user_age, 45. Note that
so this is a convention I'm going to use okay with
Python is when you want to use different words
for one variable, so this is possible to separate
the words, you're simply going to use an
underscore like this. Okay? You don't use any
uppercase letter, just underscore between any word
of a variable. Alright, so to recap, a variable is
a container that you can use to store value, and
reuse that value later. To create a variable, you
must first give it a name and then assign a value to it.