Python Arithmetic Operators
Arithmetic operators are used to perform mathematical operations on numerical values in Python.
Syntax
Operand1 operator Operand2
Example
x = 10
y = 5
print("Addition:", x + y)
print("Subtraction:", x - y)
print("Multiplication:", x * y)
print("Division:", x / y)
print("Floor Division:", x // y)
print("Exponentiation:", x ** 2)
print("Modulus:", x % y)
Output
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2.0
Floor Division: 2
Exponentiation: 100
Modulus: 0
Explanation
+
- adds two operands-
- subtracts two operands*
- multiplies two operands/
- divides the first operand by the second operand//
- performs the floor division, returns the integer part**
- performs exponentiation%
- performs modulus operation, returns remainder
Use
Arithmetic operators are useful in performing various mathematical computations in Python. They are used in coding algorithms, solving mathematical problems, performing calculations, and much more.
Important Points
- Division (/) always results in a float value.
- Floor Division (//) always returns an integer value.
- Exponentiation operator (**) raises the first operand to a power of the second operand.
- Modulus (%) operator returns the remainder of the division operation.
Summary
In this tutorial, you learned about the Python Arithmetic Operators, their syntax, examples, and output. You also learned about their use cases and important points to keep in mind while working with them.