in this video I'm going to introduce you to simple variables a variable in Python
is simply just assigning a value to a name in the code so you can use it
multiple times now it might sound a bit confusing but I'll show you it in
practice and it really is quite simple to understand so the way that you assign
variables in Python is you simply type a name of a variable like my_variable
followed by an equal sign followed by the value that you want to
assign to this variable so if I just put test here this will create a new
variable with the text test assigned to it now a couple of things to mention
about variable names in Python is it's best practice to always give your
variable names all lowercase characters so they should be all lowercase they
shouldn't have any spaces they should use underscore only for separating the
different words and they must start with a text, they can't start with a
number they can't start with a numerical value they have to start with a text
character you can however add numerical values at the end or in between the
variables but the first one must be a letter okay so the variables
are useful for reusing data during the execution of your application so let's
say we want it to output a hello world three times instead of just one so one
way to do that would be we could type print hello world and we could type that
multiple times in our code I'm actually going to copy and paste this three times
to demonstrate but what would happen if we wanted to modify this text to
let's say only have one exclamation mark well now we have to remove
those extra two exclamation marks in two different places in our code or three
sorry all three of these statements what we could
do instead is we could create a variable called hello world text we could assign
it the text hello world and then what we could do is instead of printing this
text directly we could print the contents of this variable and if you
save that and then we go back to our command prompt or terminal window and
type Python hello world hit enter you can see that the text outputs three times
now if we need to change this text at any point we can change it just in one
place and save it and then it will automatically change in all three of
those print statements so that's the value of using variables in your code
another type of variable is an integer so you can create variables...
variables can be various different data types
Python is a dynamically typed language which means that you basically don't
need to specify what type of data is going to be assigned to a variable
Python automatically figures it out by the type of input you put into the
variable so don't worry if this is a bit confusing to start with if you're
familiar with other languages like Java you will know that in Java you need to
specify what type of variable is before you assign it so you need to say I want
an integer and I want it to be of type integer and with this value whereas in
Python it automatically knows whether you want a number or text or whatever
you want to assign to your variable based on what is being assigned to it so
if we... further down here let's just do a simple calculation let's add the
variable one called var1 give it the text or give it the number one and then
var two will give it the number let's just say 25 and then what we can do is
we can sum these up so if we do total equals var1 + var2 and then if we
print that total it will output it to the screen now run our hello world again and
you can see that it outputs var1 + var2 which is 26 if we change this to
let's say 10 save it, run it again it's going to output 35 ok so that's the
basics of using variables in Python thank you so much for watching and I'll
see you in the next video