Let's talk about some more operators and
starting off with the arithmetic operations.
And this is just like,
you know,
the mathematics or basic mathematics that we learned back when we were kids, right?
So
you have, you know, one times 12 times 23 plus 1, 10 minus seven, that kind of thing,
right?
So
what I've done here is I've assigned the value of 10 to variable A
and the value of three to variable B.
And I've written out several arithmetic operations. In here,
we have A plus B A minus B A times B A divided by B
A modulus B
which will simply return the remainder
when we divide A by B.
And then the last one here is going to be a exponential B which will raise the value of A
by the power of B.
So
what are the results here going to be?
Let me run the program and of course, 10 plus three is 1310 minus three is 7,
10 times three is 3010 divided by three will be 3.3333
and then 10 with the loss three will be one.
And of course,
10 times 10 times 10 will be equal to
1000 right? OK.
So I expect that you obviously knew the answers to all of these operations.
But let's go further, I'm going to remove this. OK? And
I do have some more operations in here.
And the first one in here
is what we call an assignment operator. You can see right there, it says
plus equals right. Let me
add this in new lines
and there you go. OK?
So we have plus equals what this simply means is that we
are going to say X equals X plus five.
It's basically the same thing.
So X plus equals five is, is the exact same thing as an X equals Xr plus five.
This is just a short form of writing this.
So
let me just go ahead and remove this.
So what do you think the answer here would be the answer?
Obviously, here is going to be 15 because 10 plus five equals 15.
Now you can do the opposite. OK? You can say minus and then equals
the answer here obviously would be five because 10 minus five will be five
and you have other ones of course, like the
a multiplication
which will give us a 50.
And then we also have the division
which will give us a 22 point. Oh So
these are what we call the assignment operators.
Now,
I want to draw your attention to one more thing
and this is what we call the operator precedence.
Let me, first of all, remove
the code
and let me drag this to the top
and print on a new line.
Let me copy
this command and come down here
and then print. All right.
So
take a look at this. OK? We have two different expressions. All right.
The first one here says
two plus three times four.
Well, the second one here is we have our brackets two plus three and then times four,
what do you think the results of both expressions are going to be?
Again, this might remind you of the math that you did back in,
in your kindergarten or primary school days.
But I always find this quite fascinating because
here we're going to get two different results.
So you can pause the video and try to
guess what the results of both expressions would be.
If you have your results,
let's go ahead right now and run.
And the first one here will be 14
while the second will be 20.
Why?
Because on the first expression in here, we have two
operators, we have the plus arithmetic operator
and then we have the multiplication.
Python will do the multiplication first before the addition. So
three times four is going to be 1212 plus two is gonna be equal to 14.
However, over here in the second expression,
it's actually going to do
the addition first because they're inside of brackets,
that's why?
So unless I'm mistaken, typically it is,
you will have the parenthesis will be at the very top of the precedent.
If you don't have the parenthesis, it will check for exponentiation.
If there isn't any exponentiation, then it will go to multiplication,
it will go to division, it will go to model loss
addition and then finally subtraction.
And then
in a very complex expression, if you do have a comparison operators,
those will come next.
And then finally,
logical operators, but
no need to go any further than that over here,
we simply have two main operators or whatever we have three, we have the parentheses
which of course will take precedence over the multiplication.
So two plus three is 55, multiplied by four
equals 20. So once again, this is what we call the operator
precedence.
Again, to be honest, we're not really going to be working with these
in
this course. But nevertheless, this is something that you should be aware of.
Thank you for watching. I will see you in the next class.