Your First Steps in Python: A Beginner to Intermediate Guide

Arithmetic Operators: The Math of Programming

Section 6

Variables and Operators: Storing and Manipulating Data

Your First Steps in Python: A Beginner to Intermediate GuideVariables and Operators: Storing and Manipulating Data

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:

  1. 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}")
  1. 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}")
  1. Multiplication (*): This operator multiplies two operands.
num1 = 10
num2 = 5
product_result = num1 * num2
print(f"The product is: {product_result}")
チャプターへ戻る