Now that we know how to assign variables, let's talk a little bit more about
the data types
that we are using.
So quite simply, with respect to Python, there are many different data types
that you can
utilize in this particular video though.
What I want to focus in on is the string data type as well as the integer.
So let's first begin with this one here.
This sounds pretty strange.
What an earth is it.
Well, the good news is that we've all ready to deal with it.
See for example, this right here, this happens to be a string.
Now really in your mind, just conceptualize a string as a sequence of WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now really in your mind, just conceptualize a string as a sequence of
characters.
It's basically used as the word text data.
Now this text data can also include things like numbers.
Say for example, if I wanted to add in the value of John 2001 at example.com as
an email
in the current context, this is all just one sequence of characters.
So realistically, when we want our variable value to be a word or to be a
sentence, that
type of thing, the type of value we're going to be using is a string value
versus
if we want to utilize numerical values, then we would use something known as an WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
if we want to utilize numerical values, then we would use something known as an
integer.
Now why is this actually important?
Let me just show you why.
Okay.
That's a pretty variable here.
Let's just say name is equal to John.
Okay.
Now watch this.
If I just print out name right here, save this.
If I try to run the example as it's down right here, look at this right there.
It says we have a name error and the name John is not defined.
So what exactly is going on here?
Well, because this is going to be an order that sequence of characters, IAA
string value, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
string value,
the way we actually assign this is we make sure that the value is within
quotation marks.
Watch what happens when I put the quotation marks.
See this?
This actually goes away.
They're a little warning sign.
And if I just rerun the script, suddenly we actually print out the value.
So what this actually means is that the use of the quotation marks is actually
very,
very important.
Let me just highlight to you why.
So that's a pretty variable called first number.
Now if I give it the number, let's say 10 and I use the quotation marks here, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now if I give it the number, let's say 10 and I use the quotation marks here,
we're
actually not using in numerical value, we are really using a string.
So then if I say the second number is equal to and again, I add in with
quotation marks
the number five and I then say the total number is equal to and I take the
first number
and I add it to the second number and then I try to print the value of the
total number.
What do you think the value is going to be?
Now mathematically, if you look at this, you would say, well, 10 plus five is
equal to 15
and we give this particular value to the variable total number. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and we give this particular value to the variable total number.
So we should be printing out the value 15.
This is not what we're going to see though.
Check this out.
If I just run this, look at what we actually get here.
Because we have defined each data type as a string value, they are being
treated as ordered
sequences of characters, not as numerical values.
So realistically, all that is happening here is we've taken the first number,
which is
one zero and then we've added on the second number, which is a five and we've
given the total WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
given the total
value of one or five.
So obviously this is a little bit of a problem, very much so though, when you
want to be dealing
with these numerical values that actually have some type of mathematical
context.
Now really quite simple to define an integer.
All we do is we actually use a number of value in the numerical value, I say,
and we do
not actually use the quotations.
Now just to be clear here, if I only did this once, watch what happens, I'm
trying to add
an integer to a string.
If I run this again, we're going to get a problem. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If I run this again, we're going to get a problem.
It's going to give us a type error.
It's going to say we cannot actually add an integer and a string together.
So check this out.
If I now specify the value here, I'm now using integers.
If I just are up and rerun this, now we're getting that mathematical operation.
Now let me just show you one very good function that you can use with respect
to your data
types.
We actually have a type function that will tell you the type that is used
within a particular WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
within a particular
variable.
So I just happen to print out the type here and I run the script, but actually
seeing
we are returning an integer, whereas if I put both of these values within quot
ations right
here, again, we're going to be concatenating strings together.
If I run it now, we can see we're returning a string value.
So this is a very good way to eyeball the information that you're using.
Now these are just two of the data types that we can be using.
And one last thing to note here, remember I said how Python was dynamic.
We can just assign variable values without defining the data type. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We can just assign variable values without defining the data type.
Watch this.
Say for example, I changed this to five.
We know right here, if I just try to print this out as it is, you're doing
these parentheses,
let's just save this.
We know as it stands, this is going to give us an error as such.
Now we know what I can do is take my variable here and just dynamically reass
ign it so I can
just reassign it right there.
So the first time it was defined, it was a string value stored as this
particular variable
first number, but then we just modify it to completely different type. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
first number, but then we just modify it to completely different type.
So we're not just updating the value of the same type, but actually changing
the type entirely.
Watch what happens now because we are able to dynamically update this.
And I run the script.
Suddenly, everything is working quite just fine.
So the key take home points right here to note are the data types that we
assign to particular
variables actually can have a profound effect on the execution of our program.
And as we can see here, Python, being a dynamic language does not require us to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And as we can see here, Python, being a dynamic language does not require us to
manually specify
which data type we want to be using when creating our variables.
They can just be modified as we need.
And Python will just accept those values dynamically.
So now we know about strings and integers, the next data type that I want to
talk to about
are lists and dictionaries.