Python – Arithmetic Operators
Arithmetic operators are used to perform mathematical operations.
Addition (+
): Adds two operands.
a = 5
b = 3
print(a + b) # Output: 8
Subtraction (-
): Subtracts the second operand from the first.
print(a - b) # Output: 2
Multiplication (*
): Multiplies two operands.
print(a * b) # Output: 15
Division (/
): Divides the first operand by the second (floating-point division).
print(a / b) # Output: 1.6666666666666667
Floor Division (//
): Divides the first operand by the second and returns the integer part.
print(a // b) # Output: 1
Modulus (%
): Returns the remainder of the division.
print(a % b) # Output: 2
Exponentiation (**
): Raises the first operand to the power of the second.
print(a ** b) # Output: 125