
Arithmetic Operators: The Math of Programming
Welcome back, budding Pythonistas! Now that you know how to store information using variables, let's explore how to manipulate that data using Python's arithmetic operators. These are the building blocks for performing calculations, just like you'd use in a math class, but now with the power to automate complex computations.
Python provides a familiar set of operators for performing basic arithmetic. Let's break them down:
- Addition (
+): This operator adds two operands (numbers or variables) together.
num1 = 10
num2 = 5
sum_result = num1 + num2
print(f"The sum is: {sum_result}")- Subtraction (
-): This operator subtracts the second operand from the first.
num1 = 10
num2 = 5
difference_result = num1 - num2
print(f"The difference is: {difference_result}")- Multiplication (
*): This operator multiplies two operands.
num1 = 10
num2 = 5
product_result = num1 * num2
print(f"The product is: {product_result}")