Hi, in this lecture you're going to learn about variables. So what is a variable?
Well a variable is like a container where you can store various data types
in Python for instance this program now this doesn't have any variable in it for
now, so let me try and execute it and you'll see that this prints out of the
hello string. String is a data type, but we'll cover that later. Now what is the
variable? Well and variables will keep your code more organized. Let me create a
variable here, greeting so you can call your variables whatever you like you can
give them any name however there are some naming rules which I'll mention in
just a bit, so let me create this variable for now. I'll store in this
variable, I said variables are like containers so I'll store this text in the
variable greeting and then what I do is instead of doing print hello I'll do
print greeting and save the script ctrl s and then go through the command line,
the upper arrow key, enter to execute and you get the same output. So this is how
you create a variable you don't use any quotes because when you use quotes you
are creating a string data type not a variable and you can also use a dash
before the variable that would also be fine so you get the output correctly
but you cannot use numbers before the variable ctrl s to save, execute and get
an invalid syntax, so this syntax is not valid in Python, but you can use numbers
after or between the variable name let's say here greeting2. So that would
be fine to use so that's the condition about naming
your variables, you can start them with a letter or a, or an underscore. Now if
you're not experienced with programming you may still be confused on why do we
use these variables? Well this is a very simple program, actually very useless, but
normally your programs will interact with your users. That is what we call a
real program. You create a program to give it to people so they can interact
with the program they can generate all different outputs and so on, so let's go
Ahead and make this program more dynamic, so what I'll do here is I'll get the text
from the user interactively. To do that you need to use the input function, this
is also a Python function and inside the function you can enter a message to the
user so let's say write a greeting. A column and make some space there and then
you print greeting2, save the script. Execute and now the program is asking
us to enter some input so let's go ahead and say hi this time and we get the output
Printed out in here, hi, so what happened here is we created a variable
and that variable will store the value that the user submits in the command line
here, in the terminal so the user submitted the hi text and this text will be
stored in this variable so as I said variables are like containers and then can
use this text in various ways, but in this scenario I'm just passing it to the
print function, so I want to print it out on the terminal here and the print
function will get the value that is stored in the greeting2 variable and
print it out on the terminal. That's it. And yeah, I'd like to close this lecture
now and I'll see you in the next lecture.