 In this video we're going to talk a little about arithmetic operations in Python. Simplest are addition and subtraction. So, for example, 4 plus 9 plus 12 gives me 25. If I have something like 25 minus 3 minus 7, the question is, is that going to go from left to right or right to left? In other words, is it going to do 25 minus 3 first and then subtract 7? Or is it going to take the 3 minus 7 first and then subtract that from 25? Let's try it and find out, and the answer is 15. So, operations that are of the same priority addition and subtraction go strictly from left to right. We also have multiplication and division. So, for example, 7 times 6 gives us 42. Now, what happens if I say 7 plus 3 times 2? Which is going to happen first, the multiplication or the addition? According to the rules of arithmetic, multiplication should take priority over addition and the same thing happens in Python. So, the multiplication occurs before the addition does. Something interesting happens when we do division. Let's say I take 4 divided by 2. Notice the result is 2.0. So, when I divide integers by integers, I always get a float as the result. In fact, if I did a type of 4 divided by 2, it would tell us that that is indeed a float. Floats divided by floats, let's say 7.2 divided by 0.4 come back as floats as a result. Sometimes you'll want to do a division that gives you whole number division. For example, let's say I have 57 items and I want to find out how many whole dozens that is. If I just said 57 divided by 12, I get 4.75. But that's really 4 dozen plus 3 quarters of a dozen. When I want integer division, I do 57 and put 2 slashes in a row. 57 divided by 12 as integer division gives me the 4. Well, what about the ones that are left over? That's 0.75 of a dozen. How do I get that integer back? The remainder. To get the remainder, use the percent sign operator, which is called remainder, modulo, or mod. And usually you'll hear me pronouncing it as mod. So, 57 mod 12 is 9. So, 57 items is 4 dozen with 9 items left over. The last operation I want to talk about is exponentiation. If I want to take 12 to the third power, I type 12 star star, meaning to the power 3. And 12 cubed is 1728. I can have fractional exponents. So, if I want the square root of 2, I say 2 to the 0.5 power, which gives me 1.4 or whatever. A word of warning here. Exponentiation is evaluated from right to left instead of left to right. If I take 2 to the third squared, the question is, is that going to be evaluated as 2 cubed squared, which would come out to 64? Or is it going to be evaluated as 2 to the 3 squared, which is 2 to the 9th or 512? Let's try it and find out. And the answer is 512. The moral of the story is, if you want things to be evaluated in a specific order, use parentheses to group it the way you'd like. In order of priority, parentheses take priority over everything else. Next in priority is exponentiation. The next level down from that is multiplication and division operators, such as multiply, divide, integer, division, and modulo. And the level below that is addition and subtraction operators, which are plus and minus. So if I say 3 plus 4 times 2 to the 3rd, the exponentiation will come first. So I'll have 8 times 4 because multiplication is next most important. So I'll have 8 times 4 is 32 plus 3 at the end, and I'll get 35 as the result. If I wanted to be in some other order, I can always use parentheses to get the order I want. So if I wanted 7 squared times 2, and that whole thing to the 3rd power, which would be 20 to the 3rd power, I would put the parentheses this way. When in doubt, use parentheses. Don't be afraid to put in a couple of extra parentheses rather than trying to figure out, well, which one's the most important? It's not that much more time for the computer to evaluate, and your time is much more valuable than the computer's.