Welcome back.
We're almost done with the math section in this video.
We're going to discuss some of the common important operators that we have in Python.
So here's a simple table.
On the left side is the symbol that you'll use in Python, things you're probably familiar with, at
least plus and minus, and most likely the star and the slash for division.
And then over here is the name of the operator.
Now, these last three I know are kind of weird looking.
If you haven't come across them before, we will get to them in the next video.
But for now, we're just going to talk about addition, subtraction, multiplication, and most importantly,
division.
Okay, so let's go over to my terminal and I'll open up Python three.
We already saw we can do things like one plus three or 40 -4.5 and we get a float because we used a
float as part of the expression.
But what I want to call your attention to is what happens when we divide.
So we could do something like one divided by two.
What do you think the answer will be?
These are two integers, one and two.
So neither one of them is a float.
What type of data, a float or integer will the result be?
All right.
And look at that.
It's a float.
So in some programming languages, this actually would not give you a float and it would round down
to zero and just cut off the decimal.
But in Python division always returns a float.
You always get a float back.
Now there's a way around it.
If you don't want that for some reason, I'll show you in the next video.
But if we do something like one divided by three, we get 0.3333 repeating.
So that's division.
That's probably the most quirky, most important thing to point out in this video.
But I also want to talk about the order of operations.
So if you don't remember the order of operations for math, I won't go into the whole thing.
But there's a hierarchy to how these operations or these operators are evaluated.
So if we just did something like one plus two times five divided by three.
What happens first?
There's this thing called PEM.
Does it help some people remember parentheses, exponents, multiplication, division, addition, subtraction.
So first would be this multiplication and then this division.
So we would get ten divided by three plus one.
So that's 3.3, three, three plus one.
So we get 4.3.
But we could also do with just a couple of parentheses completely alter how this works.
So now we do the one plus 2/1.
So we get three times five is going to be 15 divided by three.
And the answer this time is 5.0.
All right, so I won't bore you.
I promise I keep this short.
But I just wanted to highlight that parentheses work the same way that they do in just paper and pen
math so we can add parentheses wherever we want to manipulate the order that things are calculated in
anyway.
Okay.