>> Hello everyone. Welcome back to Intro to
Python here on Cybrary On Demand.
I'm your instructor Joe Perry.
In this video, in this lesson Lesson 7,
we're going to be talking all about Python numbers.
Numbers in Python, we've used a bunch of them so far,
we've done a bunch of logic with them,
but I just want to take
a few minutes here in this lesson,
and just break down all the
different components of them,
so that we can understand
them a little bit more effectively.
Before I jump to the VM,
I'm jumping in them a little bit.
Our objectives in this video,
we're going to learn about the different
math operations in Python,
we're going to learn about the differences
between ints and floats,
and how to use each of those.
That's really all we're going to need to
worry about for numbers in Python.
So much of the hard work of
numbers is abstracted away from us,
so we don't have to worry about them.
They do have methods much like strings do,
but for the sake of an introductory course,
we're not really going to be worried about those.
The math operations in Python are just like
math operations in math.
We could do things like 4 plus 2,
5 minus 4, or we'll do 10 times 8,
and as a little example right here,
20 divided by 5.
Now, you'll notice this is different,
and I've alluded to it in previous videos.
That printed 4.0 There is a difference,
and the difference that I mentioned right here,
in this objective, between ints and floats.
In Python, all of these things are numbers.
In Python, we'll use it and make it work just fine.
But it is worth noting that there is something under
the hood being abstracted away from you that
can be useful and can be important.
When you're doing division,
if you don't want to get back in decimal place,
you'll do what's called floor division,
which is going to just divide and just give
you the round number of that division.
Remember from our use of modulo, in a previous video,
that if we did 20 modulo 5,
it'll give us the remainder,
which in this case, of course, is 0.
21 modulo 5 would be 1.
If we did 21 modular 5 and 21 floor divided by 5,
we'll see that 4,
even though 21 isn't evenly divisible by 5,
4 is the dividend,
and 1 is the remainder.
I think I'm using that word. I think
it's dividend, that might be divisor.
I haven't actually had to use the names for
our arithmetic in like 20 years or so [LAUGHTER].
But so that's the basic way of
using ints and floats,
and that's the difference between them.
The primary thing to understand about floats
is that floats have decimal places.
Floats can address non-whole integers.
Integers are whole numbers.
They can be negative or positive.
They're just never going to be
fractional numbers whereas floats
can address fractional numbers.
I showed you, we have plus,
minus, times, divide.
We also have exponentiation available to us.
4 to the power of 4 is going to be 256.
Then we have one more subject and numbers.
Numbers is a much easier lesser than strings.
One more subject to numbers it's really cool to address.
There's a special number in Python.
That's not really a number, so
it is a placeholder for a number.
That's the underscore. You can see here that,
now underscore equals 256,
because it is the result of
the last mathematical operation.
If we did 5 plus 3,
and print the underscore, it'll be 8.
Underscore is just a useful way
to track math, and we can do,
I'll show you in just a second one or
the other really cool things we can do with it,
but I do want to point out,
never ever do that.
Never assign a value explicitly to underscore.
Because what will actually happen there is,
you'll create a new variable and you're going to
blow away the built-in magical underscore,
so never ever do that.
But one of the other things you could do with underscore,
with the pseudo number that is underscore,
is you can use it in loops.
For underscore in range 10, print, hello.
What's cool about this is, what it's
really doing is, it's just saying,
for each number in this range,
without ever actually storing that number anywhere,
it's just a useful shorthand in Python where you're
just trying to use that range to just to
count the number of times you're doing something,
and the number itself isn't relevant.
It's actually all there really is
to math operations in Python.
You do them the same way you would do in algebra.
If you have to use an order of operations,
it works exactly the same way it does in math.
Then we talked about the differences
between integers and floats.
The idea that floats can use fractional numbers.
That's all there is to Lesson 7.
It's a palate cleanser between strings and the,
well, much more interesting and somewhat more
challenging lists and dictionaries that are coming up.
Speaking of which, I hope to
see you back in our next lesson,
Lesson 8, we're going to do a deep dive on lists.
Of course, all of the material for Lessons 5 through 9,
we have a Lab 4,
provided by the Spectacular Company Next Tech.
I know that I keep talking about them.
I actually should probably address
they are a partner of Cybrary,
but they're not actually sponsoring
this video in any way.
I'm not being paid to
talk about them or anything like that,
we just use their lab,
and absolutely, I just love it so very much,
and I want all of you to use it as well.
Please, by all means, take some time,
do those exercises, and really dig into the code.
I'll see you back for Lesson 8.
Thank you as always for watching.
I'm your instructor Joe Perry,
and you've been watching Intro to Python here
on Cybrary On Demand.