Welcome back let's talk about a important term when it comes to programming.
And that is operator precedents.
Now what does that mean.
Again we're using our knowledge from math class.
It's the idea that if I do 20 plus three times four it means that different operators have precedence
over different ones.
That is we multiply this first equals to twelve and then 20 gets added to twelve because the Python
interpreter is going to follow a basic set of rules.
For example if I do 20 minus three here and let's print this out click Run I get eight because three
times four gets evaluated first which equals to 12 and then subtracted from 20.
It's not that this goes first and then we multiply 17 by four and this operator precedents shouldn't
be new.
Right.
If you've taken any sort of math class you understand that this is how well math works and this works
the same in all programming languages.
So the order is this first.
We follow the brackets.
So whatever is wrapped in a bracket we do first.
The second is we do the power of.
So whatever is done in the power of will be after parentheses.
For example if I do parentheses here and then to the power of let's say two or less two plus two to
the power of two.
Well the first operation that will happen is 20 minus three because that's the first precedence.
And then we do two to the power of two because that's the next precedence and then only after we do
that we add these two together.
If I click Run I get twenty one which again makes sense.
Seventeen plus four after the power of we have the multiplication and division and then finally the
last precedence is addition and subtraction.
Now this isn't going to be a math class.
Some people really love math.
Some people really don't.
But I want to just give you this basic understanding of operator precedence.
When you see it.
We'll do some exercises here to get accustomed to it.
But trust me this is as mathy as we're gonna get in this course.
The math part of the course is well just here.
It's gonna get a lot more interesting as we learn about different data types.
I'll see in the next one.
Bye bye.