Addition (+)
Adds two operands.
a = 10 b = 5 result = a + b # result is 15
Subtraction (-)
Subtracts the second operand from the first.
a = 10 b = 5 result = a - b # result is 5
Multiplication (*)
Multiplies two operands.
a = 10 b = 5 result = a * b # result is 50
Division (/)
Divides the first operand by the second. The result is a float.
a = 10 b = 3 result = a / b # result is 3.3333333333333335
Floor Division (//)
Divides the first operand by the second and returns the largest integer less than or equal to the result.
a = 10 b = 3 result = a // b # result is 3
Modulus (%)
Returns the remainder of the division of the first operand by the second.
a = 10 b = 3 result = a % b # result is 1
Exponentiation (**)
Raises the first operand to the power of the second operand..
a = 2 b = 3 result = a ** b # result is 8
Python program that demonstrates the use of basic arithmetic operators:
# Arithmetic Operators in Python # Define two numbers num1 = 10 num2 = 5 # Addition addition = num1 + num2 print(f"Addition: {num1} + {num2} = {addition}") # Subtraction subtraction = num1 - num2 print(f"Subtraction: {num1} - {num2} = {subtraction}") # Multiplication multiplication = num1 * num2 print(f"Multiplication: {num1} * {num2} = {multiplication}") # Division division = num1 / num2 print(f"Division: {num1} / {num2} = {division}") # Floor Division floor_division = num1 // num2 print(f"Floor Division: {num1} // {num2} = {floor_division}") # Modulus modulus = num1 % num2 print(f"Modulus: {num1} % {num2} = {modulus}") # Exponentiation exponentiation = num1 ** num2 print(f"Exponentiation: {num1} ** {num2} = {exponentiation}")
Output:
Addition: 10 + 5 = 15 Subtraction: 10 - 5 = 5 Multiplication: 10 * 5 = 50 Division: 10 / 5 = 2.0 Floor Division: 10 // 5 = 2 Modulus: 10 % 5 = 0 Exponentiation: 10 ** 5 = 100000