WEBVTT
NOTE Copyright (c) GoSkills Ltd, 2013 - 2022
00:00:04.694 --> 00:00:08.230
In the next video, I want to talk about number data types.
00:00:08.230 --> 00:00:11.790
But before that, in this video, I want to just talk about basic math and
00:00:11.790 --> 00:00:13.030
the math operators.
00:00:13.030 --> 00:00:16.490
So to do math in Python, it is super, super easy.
00:00:16.490 --> 00:00:21.630
We just use the same math symbols that you learned in grade school math for
00:00:21.630 --> 00:00:24.200
basic math operations, addition, subtraction,
00:00:24.200 --> 00:00:27.610
multiplication, division, exponents, and modulus.
00:00:27.610 --> 00:00:30.580
And you're probably familiar with exponents we'll talk about it in a second,
00:00:30.580 --> 00:00:33.600
but the modulus here may be something you haven't seen before,
00:00:33.600 --> 00:00:35.530
we'll get into that in just a minute as well.
00:00:35.530 --> 00:00:40.104
So to do math in Python super, super easy, could not be easier.
00:00:40.104 --> 00:00:43.664
You just go print, just like whenever we want to print something to the screen.
00:00:43.664 --> 00:00:46.888
Now you don't have to use print to use math, but if you want to print the outcome
00:00:46.888 --> 00:00:49.525
of your math onto the screen, obviously you need to use print.
00:00:49.525 --> 00:00:53.759
So we can just go 2 + 3, if we save this and run it,
00:00:53.759 --> 00:00:56.428
it's going to be five obviously.
00:00:56.428 --> 00:01:01.445
So math is really just this easy in Python.
00:01:01.445 --> 00:01:03.477
So 10- 3, obviously is going to be 7.
00:01:03.477 --> 00:01:06.892
To multiply you just use this star.
00:01:06.892 --> 00:01:12.760
Save that, 30, and to divide, let's make this a nice and round number.
00:01:12.760 --> 00:01:14.450
We just use the forward slash.
00:01:14.450 --> 00:01:18.210
Remember we did the backslash to escape something out.
00:01:18.210 --> 00:01:20.750
This is the forward slash, that means divide.
00:01:20.750 --> 00:01:22.880
So if we save this it's going to be 5.
00:01:22.880 --> 00:01:23.790
Super easy.
00:01:23.790 --> 00:01:27.710
So exponents, you're taking something to the power of something.
00:01:27.710 --> 00:01:31.240
So if we took, for instance, 2 to the power of 3,
00:01:31.240 --> 00:01:36.670
we would use this double multiplication sign, which means exponents.
00:01:36.670 --> 00:01:42.473
So 2 to the 3rd power would be basically the same as 2 * 2 * 2.
00:01:42.473 --> 00:01:49.610
Now if it was 2 to the 4th power, it would be * 2, 4 times, 1, 2, 3, 4.
00:01:49.610 --> 00:01:54.840
Here we have 3 *, so it's 1, 2, 3 quick exponent primer.
00:01:54.840 --> 00:01:59.480
If we save this 2 * 2 * 2, 2, 4, so it's going to be 8, right, yep, 8.
00:01:59.480 --> 00:02:01.240
So that just leaves the modulus.
00:02:01.240 --> 00:02:04.657
And the modulus kind of can confuse people sometimes.
00:02:04.657 --> 00:02:07.711
And it's actually very useful for a lot of different things and
00:02:07.711 --> 00:02:09.860
we'll see you later on in the course.
00:02:09.860 --> 00:02:15.270
But if we were to take 10 divided by 3, well, 3 goes into 10 three times.
00:02:15.270 --> 00:02:16.970
So 3 times 3 is 9, right?
00:02:16.970 --> 00:02:19.360
Well, 10 minus 9 is 1.
00:02:19.360 --> 00:02:23.030
So 3 with 1 remainder with 1 leftover.
00:02:23.030 --> 00:02:26.810
Well, the modulus returns that remainder, that leftover thing.
00:02:26.810 --> 00:02:31.410
So if we save this and run it, we'll get one because that's the remainder.
00:02:31.410 --> 00:02:33.130
The modulus just returns the remainder.
00:02:33.130 --> 00:02:38.260
So super useful if we had 2, 10 divided by 2 is 5 with no remainder,
00:02:38.260 --> 00:02:41.860
there's no leftover because 5 times 2 is 10.
00:02:41.860 --> 00:02:44.210
So if we run this, we're going to get 0.
00:02:44.210 --> 00:02:46.330
So that's the modulus, super easy.
00:02:46.330 --> 00:02:49.948
The only kind of weird thing about math is something called order of operations.
00:02:49.948 --> 00:02:51.868
And you probably remember this from grade school math.
00:02:51.868 --> 00:02:57.637
But if we have 2 + 3 * 2, what is the answer going to be here?
00:02:57.637 --> 00:03:03.670
Is it going to be 2 + 3 equals 5 times 2 equals 10?
00:03:03.670 --> 00:03:09.570
Or is it going to be 3 times 2 is 6 plus 2 equals 8.
00:03:09.570 --> 00:03:10.540
Care to make a guess?
00:03:10.540 --> 00:03:14.500
Well, the answer is going to be eight and that's because of the order of operations.
00:03:14.500 --> 00:03:20.130
In math, in math world there's a hierarchy of which things get done first and
00:03:20.130 --> 00:03:24.110
multiplication and division are more important than addition and subtraction.
00:03:24.110 --> 00:03:26.526
So they get one first and then the addition or
00:03:26.526 --> 00:03:28.494
subtraction gets done afterward.
00:03:28.494 --> 00:03:33.990
So in this case we're taking 3 * 2, which is 6, and then adding 2 and we get 8.
00:03:33.990 --> 00:03:38.080
You can override this, and you do that with more parentheses.
00:03:38.080 --> 00:03:42.910
So, for instance, we could go wrap these guys in parentheses.
00:03:42.910 --> 00:03:46.976
And in the world of order of operations parentheses are more important than
00:03:46.976 --> 00:03:48.728
multiplication and division.
00:03:48.728 --> 00:03:52.210
And therefore also more important than addition and subtraction.
00:03:52.210 --> 00:03:54.850
Basically what it means is anything inside of these parentheses
00:03:54.850 --> 00:03:58.880
is going to be done first and then outside your normal order of operations,
00:03:58.880 --> 00:04:01.160
your normal precedence takes over.
00:04:01.160 --> 00:04:04.680
So we have 2 + 3 equals 5, times 2 equals 10.
00:04:04.680 --> 00:04:06.870
If we run this, boom, we get 10.
00:04:06.870 --> 00:04:07.970
So that's math.
00:04:07.970 --> 00:04:10.600
That's order of operations, which is very, very basic.
00:04:10.600 --> 00:04:15.340
And in this video, we took these and we just wrote the numbers right in here.
00:04:15.340 --> 00:04:23.940
You could also put num 1 = 1, num 2 = 2.
00:04:23.940 --> 00:04:27.936
And then with variables you go num 1 + num 2,
00:04:27.936 --> 00:04:31.635
save this we should get 3, and we have 3.
00:04:31.635 --> 00:04:33.180
So we can use the numbers themselves.
00:04:33.180 --> 00:04:34.260
You can use variables.
00:04:34.260 --> 00:04:38.065
You can use all these different operators and these signs +,
00:04:38.065 --> 00:04:41.335
-, *, /, these are called operators.
00:04:41.335 --> 00:04:42.915
They're the math operators.
00:04:42.915 --> 00:04:45.695
So if you hear the word math operators, it just means math sign.
00:04:45.695 --> 00:04:46.928
So that's all for this video.
00:04:46.928 --> 00:04:51.248
In the next video we're going to look at the numbers data
00:04:51.248 --> 00:04:54.708
types specifically floats and integers.
NOTE Copyright (c) GoSkills Ltd, 2013 - 2022