Now that we know how to store and change the value of variables let's do some math! Here are examples of common mathematical operators using Python syntax.
Addition
my_sum = a + bSubtraction
my_difference = x - yMultiplication
my_product = c * dDivision
my_quotient = a / bOrder of Operations
Parentheses can be used to order math operations:
first = 5
second = 7
third = 9
average_value = (first + second + third) / 3
print(average_value)Which prints 7, the average of 5, 7, and 9.
Negative Numbers
Negative numbers in Python work the way you probably expect. Just add a minus sign:
my_negative_num = -420Source: boot.dev