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 put 3 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.
I can 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 4 times 2.
Okay, and now if I get b, b is equal to 8.
Okay, and if I get b again, b is equal to 8.
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 3.
b is going to be evaluated to 8.
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 3, I'm going to put 5.
Okay, and now let's see what we get in c.
As you can see, c is still 11, okay?
The variable a has changed to 5, but c is still 11, okay?
Why is that?
Because simply when we assigned 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 order 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 13, okay?
Because I'm evaluating c, I'm assigning a
new value to c after I have modified a, okay?
So here a was equal to 3.
Here a is equal to 5.
Okay, so a 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 over
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 upper case like this.
You can see we have an error, name error, name a is not defined, okay?
Because you have to respect the case, okay?
a, b, c.
We have defined three variables.
If I try to just, let's say test, okay?
If I try 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 a 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 a 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 a 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 are simply going to use an underscore like this, okay.
You don't use any uppercase letter, just underscore between any word of a variable.
All right, so to recap, a variable is a container that
you can use to store a value and reduce that value later.
To create a variable, you must first give it a name and then assign a value to it.