WEBVTT

00:00.000 --> 00:02.280
>> Hello everyone.
Welcome back to Intro to

00:02.280 --> 00:04.425
Python here on
Cybrary On Demand.

00:04.425 --> 00:05.850
I'm your instructor Joe Perry.

00:05.850 --> 00:08.385
In this video, in
this lesson Lesson 7,

00:08.385 --> 00:12.105
we're going to be talking
all about Python numbers.

00:12.105 --> 00:15.180
Numbers in Python, we've
used a bunch of them so far,

00:15.180 --> 00:16.605
we've done a bunch
of logic with them,

00:16.605 --> 00:17.460
but I just want to take

00:17.460 --> 00:18.790
a few minutes here
in this lesson,

00:18.790 --> 00:19.890
and just break down all the

00:19.890 --> 00:21.040
different components of them,

00:21.040 --> 00:21.990
so that we can understand

00:21.990 --> 00:23.010
them a little bit
more effectively.

00:23.010 --> 00:24.060
Before I jump to the VM,

00:24.060 --> 00:25.320
I'm jumping in
them a little bit.

00:25.320 --> 00:26.880
Our objectives in this video,

00:26.880 --> 00:28.290
we're going to learn
about the different

00:28.290 --> 00:29.895
math operations in Python,

00:29.895 --> 00:31.020
we're going to learn
about the differences

00:31.020 --> 00:32.490
between ints and floats,

00:32.490 --> 00:34.185
and how to use each of those.

00:34.185 --> 00:35.820
That's really all
we're going to need to

00:35.820 --> 00:37.710
worry about for
numbers in Python.

00:37.710 --> 00:39.240
So much of the hard work of

00:39.240 --> 00:40.710
numbers is abstracted
away from us,

00:40.710 --> 00:42.170
so we don't have to
worry about them.

00:42.170 --> 00:44.410
They do have methods
much like strings do,

00:44.410 --> 00:46.580
but for the sake of an
introductory course,

00:46.580 --> 00:48.595
we're not really going to
be worried about those.

00:48.595 --> 00:50.840
The math operations in
Python are just like

00:50.840 --> 00:53.300
math operations in math.

00:53.300 --> 00:57.815
We could do things
like 4 plus 2,

00:57.815 --> 01:06.400
5 minus 4, or we'll
do 10 times 8,

01:06.400 --> 01:09.440
and as a little
example right here,

01:09.440 --> 01:11.990
20 divided by 5.

01:11.990 --> 01:13.610
Now, you'll notice
this is different,

01:13.610 --> 01:15.925
and I've alluded to it
in previous videos.

01:15.925 --> 01:19.130
That printed 4.0 There
is a difference,

01:19.130 --> 01:20.480
and the difference that
I mentioned right here,

01:20.480 --> 01:23.765
in this objective,
between ints and floats.

01:23.765 --> 01:25.640
In Python, all of these
things are numbers.

01:25.640 --> 01:28.160
In Python, we'll use it and
make it work just fine.

01:28.160 --> 01:31.640
But it is worth noting that
there is something under

01:31.640 --> 01:33.500
the hood being abstracted
away from you that

01:33.500 --> 01:35.600
can be useful and
can be important.

01:35.600 --> 01:36.890
When you're doing division,

01:36.890 --> 01:38.780
if you don't want to get
back in decimal place,

01:38.780 --> 01:40.850
you'll do what's
called floor division,

01:40.850 --> 01:43.310
which is going to just
divide and just give

01:43.310 --> 01:46.340
you the round number
of that division.

01:46.340 --> 01:48.980
Remember from our use of
modulo, in a previous video,

01:48.980 --> 01:50.960
that if we did 20 modulo 5,

01:50.960 --> 01:51.830
it'll give us the remainder,

01:51.830 --> 01:53.570
which in this case,
of course, is 0.

01:53.570 --> 01:56.725
21 modulo 5 would be 1.

01:56.725 --> 02:02.640
If we did 21 modular 5 and
21 floor divided by 5,

02:02.640 --> 02:03.955
we'll see that 4,

02:03.955 --> 02:06.200
even though 21 isn't
evenly divisible by 5,

02:06.200 --> 02:08.450
4 is the dividend,

02:08.450 --> 02:09.530
and 1 is the remainder.

02:09.530 --> 02:10.880
I think I'm using
that word. I think

02:10.880 --> 02:12.200
it's dividend, that
might be divisor.

02:12.200 --> 02:15.050
I haven't actually had
to use the names for

02:15.050 --> 02:18.680
our arithmetic in like 20
years or so [LAUGHTER].

02:18.680 --> 02:19.820
But so that's the basic way of

02:19.820 --> 02:20.780
using ints and floats,

02:20.780 --> 02:21.680
and that's the
difference between them.

02:21.680 --> 02:23.720
The primary thing to
understand about floats

02:23.720 --> 02:26.150
is that floats have
decimal places.

02:26.150 --> 02:29.420
Floats can address
non-whole integers.

02:29.420 --> 02:30.695
Integers are whole numbers.

02:30.695 --> 02:32.450
They can be negative
or positive.

02:32.450 --> 02:34.100
They're just never going to be

02:34.100 --> 02:36.680
fractional numbers
whereas floats

02:36.680 --> 02:38.555
can address fractional numbers.

02:38.555 --> 02:40.160
I showed you, we have plus,

02:40.160 --> 02:42.470
minus, times, divide.

02:42.470 --> 02:44.825
We also have exponentiation
available to us.

02:44.825 --> 02:48.065
4 to the power of 4
is going to be 256.

02:48.065 --> 02:49.880
Then we have one more
subject and numbers.

02:49.880 --> 02:52.175
Numbers is a much easier
lesser than strings.

02:52.175 --> 02:55.475
One more subject to numbers
it's really cool to address.

02:55.475 --> 02:58.340
There's a special
number in Python.

02:58.340 --> 02:59.690
That's not really a number, so

02:59.690 --> 03:01.600
it is a placeholder
for a number.

03:01.600 --> 03:04.650
That's the underscore.
You can see here that,

03:04.650 --> 03:07.080
now underscore equals 256,

03:07.080 --> 03:08.220
because it is the result of

03:08.220 --> 03:11.270
the last mathematical operation.

03:11.270 --> 03:14.065
If we did 5 plus 3,

03:14.065 --> 03:16.515
and print the
underscore, it'll be 8.

03:16.515 --> 03:17.930
Underscore is just a useful way

03:17.930 --> 03:19.115
to track math, and we can do,

03:19.115 --> 03:20.270
I'll show you in
just a second one or

03:20.270 --> 03:21.920
the other really cool
things we can do with it,

03:21.920 --> 03:23.420
but I do want to point out,

03:23.420 --> 03:26.065
never ever do that.

03:26.065 --> 03:29.390
Never assign a value
explicitly to underscore.

03:29.390 --> 03:30.590
Because what will
actually happen there is,

03:30.590 --> 03:32.630
you'll create a new variable
and you're going to

03:32.630 --> 03:35.180
blow away the built-in
magical underscore,

03:35.180 --> 03:36.485
so never ever do that.

03:36.485 --> 03:38.480
But one of the other things
you could do with underscore,

03:38.480 --> 03:40.670
with the pseudo number
that is underscore,

03:40.670 --> 03:42.695
is you can use it in loops.

03:42.695 --> 03:50.190
For underscore in range
10, print, hello.

03:51.290 --> 03:53.430
What's cool about
this is, what it's

03:53.430 --> 03:54.660
really doing is,
it's just saying,

03:54.660 --> 03:56.470
for each number in this range,

03:56.470 --> 03:59.405
without ever actually storing
that number anywhere,

03:59.405 --> 04:02.510
it's just a useful shorthand
in Python where you're

04:02.510 --> 04:04.130
just trying to use
that range to just to

04:04.130 --> 04:05.930
count the number of times
you're doing something,

04:05.930 --> 04:08.830
and the number itself
isn't relevant.

04:08.830 --> 04:10.910
It's actually all
there really is

04:10.910 --> 04:12.360
to math operations in Python.

04:12.360 --> 04:15.010
You do them the same way
you would do in algebra.

04:15.010 --> 04:16.850
If you have to use an
order of operations,

04:16.850 --> 04:18.770
it works exactly the same
way it does in math.

04:18.770 --> 04:20.570
Then we talked about
the differences

04:20.570 --> 04:21.910
between integers and floats.

04:21.910 --> 04:24.260
The idea that floats can
use fractional numbers.

04:24.260 --> 04:26.080
That's all there is to Lesson 7.

04:26.080 --> 04:29.195
It's a palate cleanser
between strings and the,

04:29.195 --> 04:31.190
well, much more interesting
and somewhat more

04:31.190 --> 04:33.395
challenging lists and
dictionaries that are coming up.

04:33.395 --> 04:34.760
Speaking of which, I hope to

04:34.760 --> 04:35.960
see you back in our next lesson,

04:35.960 --> 04:38.690
Lesson 8, we're going to
do a deep dive on lists.

04:38.690 --> 04:42.350
Of course, all of the material
for Lessons 5 through 9,

04:42.350 --> 04:43.540
we have a Lab 4,

04:43.540 --> 04:45.505
provided by the Spectacular
Company Next Tech.

04:45.505 --> 04:47.305
I know that I keep
talking about them.

04:47.305 --> 04:48.680
I actually should
probably address

04:48.680 --> 04:50.240
they are a partner of Cybrary,

04:50.240 --> 04:51.470
but they're not
actually sponsoring

04:51.470 --> 04:53.265
this video in any way.

04:53.265 --> 04:55.100
I'm not being paid to

04:55.100 --> 04:56.330
talk about them or
anything like that,

04:56.330 --> 04:57.500
we just use their lab,

04:57.500 --> 05:00.470
and absolutely, I just
love it so very much,

05:00.470 --> 05:02.360
and I want all of you
to use it as well.

05:02.360 --> 05:04.070
Please, by all means,
take some time,

05:04.070 --> 05:06.880
do those exercises, and
really dig into the code.

05:06.880 --> 05:08.440
I'll see you back for Lesson 8.

05:08.440 --> 05:10.465
Thank you as always
for watching.

05:10.465 --> 05:11.830
I'm your instructor Joe Perry,

05:11.830 --> 05:13.600
and you've been watching
Intro to Python here

05:13.600 --> 05:16.730
on Cybrary On Demand.

