Arithmetic Operators
Arithmetic Operators in Python are used to perform basic mathematical operations like addition, subtraction, multiplication, and division.
Explanation
These operators help us calculate values in a program, just like using a calculator.
They are widely used in:
- School programs
- Coding projects
- Real-life calculations
Learning arithmetic operators in Python is the first step to mastering programming.
Common Arithmetic Operators
- + (Addition) → Adds two values
- - (Subtraction) → Subtracts values
- * (Multiplication) → Multiplies values
- / (Division) → Divides values (gives decimal)
- % (Modulus) → Gives remainder
- ** (Power) → Raises to power
- // (Floor Division) → Gives integer result
Example 1
#Arithmetic operations
a = 10
b = 3
# Perform arithmetic operations
print("Addition:", a + b) # 13
print("Subtraction:", a - b) # 7
print("Multiplication:", a * b) # 30
print("Division:", a / b) # 3.3333
print("Modulus:", a % b) # 1
print("Exponent:", a ** b) # 1000
print("Floor Division:", a // b) # 3
Output:
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Modulus: 1
Exponent: 1000
Floor Division: 3
Explanation of Output
- + → Adds numbers
- - → Subtracts numbers
- * → Multiplies numbers
- / → Gives decimal result
- % → Gives remainder
- ** → Power (10³ = 1000)
- // → Gives whole number
Example 2
# Arithmetic Operators Example
x = 20
y = 4
sum = x + y
difference = x - y
product = x * y
division = x / y
remainder = x % y
power = x ** y
floor_div = x // y
print("Sum =", sum)
print("Difference =", difference)
print("Product =", product)
print("Division =", division)
print("Remainder =", remainder)
print("Power =", power)
print("Floor Division =", floor_div)
Output:
Sum = 24
Difference = 16
Product = 80
Division = 5.0
Remainder = 0
Power = 160000
Floor Division = 5
Real-Life Example
Arithmetic operators are like doing math problems:
- Adding marks
- Finding total price
- Calculating average
Common Beginner Mistakes
- Confusing / and //
- Forgetting operator symbols
- Using wrong operator for calculations
- Not understanding remainder (%)
➤ Key Points
- Arithmetic operators are used for calculations
- Used in daily life math problems
- Important for Python beginners
- Help build logic and problem-solving skills
➤ Tips
- Practice using operators with numbers
- Start with simple programs
- Understand each operator clearly
- Use them in real-life examples