Arithmetic Operators
-
Arithmetic operators in Python are used to perform basic mathematical calculations on numbers. These operators allow you to add, subtract, multiply, divide, find remainders, perform floor division, and calculate powers. Python provides simple and readable symbols such as +, -, *, /, %, //, and ** to handle numeric operations efficiently.
Arithmetic Operator :
An arithmetic operator is a type of operator used to perform mathematical calculations like addition, subtraction, multiplication, division, etc.
Example: + (add), - (subtract), * (multiply), / (divide), % (remainder), ** (power), // (floor division).
Python supports the following arithmetic operators:
Arithmetic Operations Example
Demonstrates all basic arithmetic operations in Python using two numbers.
# Defining two numbers
a = 10
b = 3
# Addition
sum_result = a + b
print("Addition:", sum_result)
# Subtraction
sub_result = a - b
print("Subtraction:", sub_result)
# Multiplication
mul_result = a * b
print("Multiplication:", mul_result)
# Division
div_result = a / b
print("Division:", div_result)
# Floor Division
floor_div = a // b
print("Floor Division:", floor_div)
# Modulus
mod_result = a % b
print("Modulus:", mod_result)
# Exponentiation
exp_result = a ** b
print("Exponentiation:", exp_result)
Key Points
Use // to get integer results without decimals.
% is useful to find remainders or check divisibility.
** allows you to calculate powers efficiently.
Division / always returns a float, even if the result is a whole number.
Division / always returns a float, even if the result is a whole number.