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
float's 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, two plus
four, 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, two times
for.
And then we can also do two divided by four and in fact, 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 two plus four?
If I click run here.
All right, let's 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 two
plus four?
Well, that's going to be six.
And it's going to say, hey, what's the type of sex?
Well, the type of sex that's an integer.
So it's going to say class and 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 it for integer.
And then finally, after this gets evaluated by Python, we print out whatever this does, which is
class int.
Now, check this out, let's do the same for all these ones as well.
So we're going to say type here type.
Here and if this syntax is intimidating, don't worry, this is something that you get used to.
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 on.
All right, we got it.
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 zero point five.
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 zero point five.
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 zero point zero zero zero
zero one.
What do you think we'll get?
Well, we would get a float.
If I do five point zero zero zero one again, we'll get a float.
What about the number zero?
I get an ENT because while 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 and something called a binary or binary numbers,
which is zeros and ones.
Now, the problem is when you have a decimal places like zero point or less to ten point five six,
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 locations, one for the
ten and one for fifty six.
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 a floating point, no python.
Again, you want to 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 want to get a
little bit more extra detail.
But let's get back to the topic at hand.
Both eat 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.
Twenty plus one point one.
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 nine point nine 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, eleven point zero.
It keeps the floating point numbers all right.
But at the end of the day, what we care about is that that python works.
The way we expect it to do 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 to to the power of two.
Well, that's going to equal four.
Due to the power of three is going to equal eight.
We also have the double divide.
That is, we can do to divide it by four, but then we used to slash this year 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.
This gets rounded down to a integer.
Finally, the last operator that we're going to learn about is called Modula, and it looks something
like this if I do five modulo, which is the percent sign.
Divided by four or modulo four, five, run this.
Modulo is used to represent what's the remainder of this division.
So if I divide five by for the remainder of this division will be one if I do six divided by four with
Modula and I run, I get to.
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 by.