CMSC 201 |
Lab 2: A Simple ProgramExpressionsWhat are they? An expression is just a fancy name for something that can be "turned" or evaluated to a single value. One of the best examples of this is a mathematical expression like "1 + 2 * 5" which can be evaluated or "turned" into the single value of 11. How do I use them? For now, expressions are mostly used for mathematical equations. If we want to find the addition of two numbers in Python we would write something like sum1 = 4 + 5 4 + 5 evaluates to 9 which was stored in the variable sum1. Now if were to print sum1 it would simply display 9. We could also have done something like this num1 = 4 num2 = 5 sum1 = num1 + num2 Even though we used the variables num1 and num2 to represent the numbers 4 and 5, sum1 will still evaluate to 9. Here is a list of python operators:
|