Fundamentals of programming: programming elements, operators. In our previous lesson, we looked at different types of data, primarily numbers and strings. Now we can talk about operators. Operators are symbols that act on our data types to give us various answers. You're already familiar with many of the basic operators: add, subtract, multiply, and divide. For integers, divide takes different meanings that we're going to take a look at. Including the difference between, since we're talking integers, getting the quotient versus the remainder. Let's take a look at some examples, 5 plus 5 we get back 10. This is why we use this interactive environment. 5 times 5, 30. Now let's try division, 10 divided by 3. Now you'll notice we've gone here from integers, from the 10 and the three to getting a floating point response. If you are not seeing that result in your own system, if you're not using our labs, you might have an older version of Python that didn't automatically promote the division to float. Also notice when we talked about earlier with respect to rounding type errors, you'll notice that 10 divided by 3 is supposed to be threes infinitely. But here at the end we have a five. So to do actual integer division, we use a double slash here, 10, double slash three. That got me the integer quotient and 10 percent three got me the remainder from that division. Operators might work differently with different data types. In this case, we know that in addition to integers and floats, we have strings. There are two operators that we can talk about. Hello with a space plus world, that's hello world that concatenated them together and we did need the space, without it, it would have just been a HelloWorld. Another interesting thing here is Python defines multiply, but it's actually a repetition. Hello space times five. Hello, hello there is five times. Operators might work differently with different data types. We saw how addition with strings is a concatenation and multiply with strings as a replication, whereas with numbers it does the expected. Now in terms of operators, we do have this notion of operator precedence. You may remember PEMDAS from grade school. Parentheses are higher than exponents, multiplication and division come before addition and subtraction. Let's look at some real-world examples. 10 plus 2 times 3. It's 16 because the multiplication comes first. The 2 times 3 comes first, then we add the 10. If it were not for PEMDAS, it might look something like this. We get a completely different result. It's 36 because you say 10 plus 2 well, that's 12 times 3 is 36. But because of PEMDAS, we know that the multiply comes first. Likewise if I were to say ten plus three times two. Well that's still 16, that's still correct because multiply comes first and it doesn't matter which comes in that list first, the two or the three. We can just flip the two and the three and according to the commutative property of multiplication, it doesn't make any difference. But if we were to do that with the parentheses as if PEMDAS wasn't a thing and so the plus comes first, and then we get a whole different result of 26. So PEMDAS exists to make sure that things like the associative and commutative properties of mathematical functions are preserved. As though we get consistent result and that's still true here in our programming languages. Couple of final examples. We talked about exponentiation. Python does have an exponentiation operator I will show it to you. It is the double asterisk. So two squared is four. In terms of following the rules, 1 plus 2 squared times 2. Now if we follow the rules correctly, that should be nine. One final thing since we have exponentiation, if you want to know how to do a square root, just remember that it's the reciprocal of the exponent. The square root of two is the same as raising it to the half power and there is the square root of two. We're not going to be doing that much math in this class, but just wanted to point it out for those of you who do remember your math from school. So that is a look at operators and operator precedence and we started to write some very simple formulas down there where in other words we had more than one operator to demonstrate operator precedence. In our next lesson, we'll start to take advantage of these operators and create expressions, and move to being able to do assignments and variables and creating reusable formulas.