# 2.8 Numbers (Deep-Dive) - IP

Video Activity
Join over 3 million cybersecurity professionals advancing their career
or

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