Instructor: Welcome back.
Let's talk about our first data type.
And you know what?
Let's do two at the same time.
We have int and floats.
Int stands for integer, as you can see here,
and float stands for a floating point number.
Hmm.
Let's explore that.
First, let's start off with integer.
An integer is, well, a number.
Three or four or five, these are all integers.
In a programming language,
you can use integers to do mathematical operations,
for example 2 + 4.
If I run this, well, nothing gets printed
because, again, we have to perform some action
on these data types.
And one action that we've learned so far
is this idea of printing.
And we print something
by calling the print keyword with the brackets.
So the brackets is almost like saying,
"Hey, perform this action on these data types."
And if we run this,
we get six right here.
Awesome.
So, not only are we using print,
but we're also using the plus sign to perform an action,
to add the two data types together.
And as you can imagine,
we can do most mathematical operations, the basic ones.
We can do negative.
We can do, let's say 2 times 4,
and then we can also do 2 divided by 4.
And if click run here,
all right, it looks like everything is working.
We've added, we've subtracted, we've multiplied,
and then we've also divided.
Now, here's the interesting part.
Up until now, we've used what we call integers.
That is, these are whole numbers.
There's no decimal places, they're just, well, integers.
And a neat trick that I can do here is I can actually say,
"Hey, what's the type of 2 plus 4?"
If I click run here,
all right, let's decipher what just happened.
I've taught you another action that we can perform
which is something called type
which tells us, "Hey, what data type is this?"
And just like in math, we go bracket by bracket.
So the first part, Python says,
"Hey, what's 2 plus 4?
Well, that's going to be six."
And it's going to say,
"Hey, what's the type of six?"
Well, the type of six, that's an integer.
So it's going to say class int.
We don't have to worry about the class keyword for now.
That's something that we'll talk about later.
But we see here that we're using int for integer.
And then finally, after this gets evaluated by Python,
we print out whatever this does, which is class in.
Now, check this out.
Let's do the same for all these ones as well.
So we're gonna say, type here, type here,
and then type here.
And if this syntax is intimidating, don't worry.
This is something that you get used to.
If this is your first programming language,
it is not going to be easy because well, if it was easy
then everybody would be doing it.
So hang in there.
Trust me, as you practice more
this is going to start making more and more sense.
Now, before I click run,
what do you think the output of each one of these lines are?
Ready? Give it a guess and let's click run.
All right, we got int.
For six, we have negative two here,
which is also an integer.
We have eight here, which again, is also an integer.
But then we have float.
Because two divided by four is 0.5.
Hmm, what is that?
Well, remember we are talking about two data types here.
We're talking about int and float.
And float is what we call a floating point number.
A floating point number is simply a number
with a decimal point.
In our case, this is 0.5, so it's a floating point number.
So if we write a number,
let's say we'll do print, type,
and then I'll say 0.00001.
What do you think we'll get?
Well, we would get a float.
If I do 5.0001, again, we'll get a float.
What about the number zero?
If I click run,
I get an int because, well, there's no decimal points.
Why do we need to make this distinction in programming
and specifically in Python?
Well, it's because a float
takes up actually a lot more space in memory
than an integer, right?
Because, remember, this number, the number six,
this needs to get stored in memory on our machine.
And remember that machines don't really understand this.
They understand zeros and one.
And they store this number
in something called a binary or binary numbers
which is zeros and ones.
Now, the problem is when you have decimal places
like zero point, or let's do 10.56,
it's hard to represent that
in a binary number, zeros and ones because of this point.
So a floating point number essentially stores these numbers
in two different location, one for the 10 and one for 56.
Now, we don't need to get technical here
but that's the idea.
The idea is that we need more memory
to store a number like this
than a number like this.
Now, the topic of floating point numbers is really,
really interesting, and I'll link to a resource.
But the best way to learn more about floating points,
again, it's not super important
that you know the technical details,
but if you go to floating point number Python.
Again, you wanna make sure
that you go to the documentation for version three.
And you can actually learn
about floating point arithmetic.
And these official documentation by Python
are always a good tool for you to use
whenever you get confused about something
or you wanna get a little bit more extra detail.
But let's get back to the topic at hand.
Both int and float are used for well numbers, right?
And, Python is going to automatically format the type
to whatever well, makes sense.
For example, if in here,
I do 20 plus 1.1,
one is a integer,
the other one is a floating point number.
But when I click run here,
automatically Python is going to convert it to float.
Let's remove these here so that
we don't get confused by them.
So if I run this, we see that this whole expression
is converted into, well, a float.
Now if I do, let's say 9.9 here,
which will equal to 11 and I click run,
these two floats add up to,
while still a floating point number
because if I remove the type from here
and I click run, it gives me the result 11.0.
It keeps the floating point numbers.
All right.
But at the end of the day,
what we care about is that
Python works the way we expect it to.
That is we can do mathematical operations.
As a matter of fact, we can do a few other things as well.
There's also this idea of the double multiply.
So this means to the power of so two
to the power of two, well, that's going to equal four.
Two to the power of three is going to equal eight.
We also have the double divide.
That is we can do two divided by four.
But then we use two slashes here.
If I click run here, I get zero.
This actually returns an integer.
Round it down.
If I do three divided by four, I get zero.
But if I do five divided by four, I get one.
This gets rounded down to a integer.
Finally, the last operator
that we're gonna learn about is called modulo.
And it looks something like this.
If I do five modulo, which is the percent sign.
Divided by four or modulo four,
if I run this, I get one.
Modulo is used to represent
what's the remainder of this division.
So if I divide five by four,
the remainder of this division will be one.
If I do six divided by four with modulo
and I run, I get two.
Two is the remainder of four.
All right, let's take a break and learn a little bit more
about these numbers in the next video.
Bye-bye.