Here is a pretty table listing the Mathematical Operators in Python:
Also, when working with math note that if you do not enter an equation in as a decimal, the result will not have a decimal. So if I said 14 / 3, it would give me the result of 4. If I used the expression 14.0 / 3.0 it would return 4.66666666667. In addition, you give mathematical equations precedence by using parentheses(). So: 3 * 2 + 2 would equal 8, whereas 3 * (2+2) would equal 12. This is because Python sees the parentheses and knows to calculate that portion first, then multiply by 3. Commenting You may have noticed earlier that I used the # symbol followed by some text. This is known as a comment. When Python sees the # it gets scared and runs away to the next line. It won't even read what you have written. Comments are used to leave notes for yourself or other programmers who may eventually view your code. They are typically used to describe what a particular snippet of code does. That way when you view your code six years later at four A.M. you don't rip your arm hair out trying to remember what the heck that function was supposed to do. Well that is it for this episode. In our next action-packed show, we will discuss how to get data from the user and how to use it, and my good buddy the variable. As always, thanks for dropping in and hope to see you soon. Till then...
blog comments powered by Disqus |