All right so let's talk about variables and methods.
So to do this we're going to make a new file.
So let's do get it and we're going to call this one script up high because in the last video I told
you we're just going to start building off of these scripts and orders and keep it in one script and
keep it going.
So let's get a script out pie.
We'll do one more shebang here of bean Python 3 and then we're going to go ahead and just fill this
out.
I'm going to drag this over just a little bit so let's put a another common up here and let's call this
variables and methods and let's define a variable so let me show you what a variable looks like and
then we'll define what a variable really is.
So let's start with a quote and you can pick your favorite quote here and we're just going to say something
like.
All is fair in love and war.
OK.
So what's happening here is we are creating a variable of a quote now a variable.
All you can think of a variable is as a place holder.
So instead of typing out all is fair in love and war we can just call this place holder at a later time
and it knows hey I'm going to call this information so it's going to store this information inside of
quote and then later we just call quote and then I'll print it out so we can do something like print
quote and save this and I forgot to ampersand.
So excuse me we're in a close it and let's just run script that pie.
Sorry.
Python 3 script up high.
You can see it says all is fair in love and war.
So if we get at this and add the ampersand now so we defined what was in our variable here which was
this this string right we've talked about strings we put a string here as our quote and we printed the
quote.
So if we didn't put the print in here we just swing and copy this and just delete it.
If we save this and we go to print this now there's nothing telling this to print.
So we have quote and we have a quote stored in our quote variable but nothing instructing it to print
so we can we can leave the print back in there.
Just copy and paste it back and now it'll print that quote.
Now we also have what are called methods.
OK so methods are basically functions that are available for a given object.
OK.
So don't worry too much about that description.
That's very dictionary based description.
Just think about what a method does.
So I'll show you these methods here.
So a method might look something like print quote and then let's say we want to make quote upper.
So in order to make it uppercase all uppercase we're just going to throw in this method of upper.
So we just say dot upper if we were to save that and print it
look now the text is all uppercase and you can make a note in here if you want to say it makes it uppercase
and we can copy this.
Let's just copy this whole line like this and let's paste a couple here so we could also do something
like lower for a lower case or we can do something like title for a title case and we can make notes
here of lower case and title case and we say that.
And when you print it what do you think's gonna happen here.
So we're gonna save all is fair in love and war all is fair in love and war and you can see entitled
Case not perfect is capitalizing the and here and the N and the IS but it does capitalize every first
letter as it's instructed to do here.
So these are methods.
There's also other things that we can do.
We can do something like say we want to get the length of this quote We want to know how many characters
are inside the quote we can do something like print length of quote OK we can just say Save and let's
see what it prints out OK so twenty eight.
Now it's 28 characters completely we are to count this all up including the spaces there's 28 characters
there.
So let's make this a little bit more interesting and let's talk a little bit more more about math and
bring that into it and try to tie this all together with what we've learned so far.
So let's use your name.
Let's define a variable of your name and we're going to set it as a string.
So my name is Heath.
So will this say this is a string right.
And let's also define your age.
Now I'm 30 and we'll say this is what is called an end or an integer OK.
And let's say.
What's your grade point average and my grade point average was three point seven.
And this is what is called a float.
Now what is the difference between an integer and a float.
Well an integer has no decimal point a float does.
So if I was a 30 day or 30 years and twenty seven days I might be thirty point one years old.
Right but if I only define as an integer I say int 30.
Then that's going to define that this number is an integer and nothing else.
Same thing with float.
If we want to have the decimal point there we can float a number and define it as like three point seven.
So let's make more sense of this.
We can print out the integer of my age and we can also print out the integer of my or we could say thirty
point one and let's see what happens.
As we discussed here let's save this and let's just print out those two and look it takes thirty point
one and makes it 30 and it takes Integer Integer age and makes it 30 as well.
Now what if this is thirty point nine.
What you think is going to happen you think it's going around it in fact does not around.
So you could see thirty point nine still came out of thirty down here.
It doesn't matter it just takes us first number when we call an integer.
So make sure that if you ever use integer you know that it does not around so let's build upon this
again.
We could take a string now and let's print out a string.
We could say something like My name is and then you could say plus name.
Make sure you add the space in there right.
And you can also say space and I am space and then let's define an age.
So if we try to put age in here watch what happens.
So we're going to say age and we'll say space years old
and let's save this here like this and I'll give you a second to catch up.
So again we're adding a space space in the beginning space at the end space at the end here just so
that we have the syntax right or else it's going to all bunch up together.
So try to print this out and you could see cannot concatenate a string not integer to string.
So this h here is sitting here as an integer.
You can't concatenate a string with an integer.
So how do we fix that.
Well we can do here is we can actually put this into a string format so we'll just say string of age
something like this and save it.
And now it makes it to a string so similar as we made something into an integer and how we can make
something into a float.
We can also make something into a string.
So if we come through here and we hit Enter you could see now that it works.
My name is Heath and I'm 30 years old so a couple more things to know.
What if we had something like our age and you know we got a year older.
Well we can just say something like age plus equals one and we could say friend our age.
Now watch what happened.
Age is now thirty one even up until that point.
Age has been 30.
Right.
You see age coming through here we're utilizing it in all three places.
Now we print age down here and it's 31 because we have changed what is stored in the variable.
So again the variable here of age we had 30 stored in it up until the instruction is called to add one
plus equals one.
So we're just adding one to this age variable here then it stays 30.
Now it is 31 until we change it again so we can also do something along the lines of birthday equals
1.
So we have a value of birthday and then we could say age plus equals birthday and then you're going
to print your age again and guess how old we're gonna be we're gonna be 32.
So it doesn't matter how you store it you can do the plus equals here or minus equals if you wanted
to take away and you can start incorporating your math into your variables you can incorporate your
variables into your strings and you can start tying this all together.
So if you need to re watch this and to make more sense of it that's absolutely fine.
I'm going to harp one more time on this.
Take good notes.
Practice practice practice.
This is stuff that can get overwhelming very quick but hopefully I'm explaining it slow enough and your
you're getting it if you're not getting it please do re watch the video please take notes in Please
utilize outside resources as well.
I understand that I might not always be the best at teaching a particular subject or sometimes it takes
another person hearing it again from somebody else to see this coding is not necessarily easy but once
it clicks it clicks in a lot of it is just repetition.
So that is it for this video.
We've started to tie everything together now from here.
We're going to move into what are called functions and build upon all of this.
So I'll catch you over in the next video on functions.