In this section, we will learn what Arithmetic Operators are and how to use them in Python.
Note: we’re assuming you already familiar with operators in general.
What is Arithmetic Operator in Python?
Python arithmetic operators are those operators that allow us to run mathematical operations.
For example, addition `+` operator, multiplication `*` operator, subtraction `-` operator etc. using these operators and more (as you’ll soon see) we can run math operations in Python.
Python List of Arithmetic Operators
Here’s the list of Arithmetic operators supported in Python:
Operator | Symbol | Description |
Addition Operator | + | Using this operator, we can add two values together. |
Subtraction Operator | – | Using this operator, we can subtract two values from each other. |
Multiplication Operator | * | Using this operator, we can multiply two values to each other. |
Division Operator | / | Using this operator, we can subtract two values from each other. |
Exponentiation Operator | ** | This operator is used to raise the value of the left operand to the power of the right operand and then return the result. |
Modulus Operator | % | Using this operator, we can run modulus operation on operands. |
Floor Division | // | Using this operator, we can run floor division on operands. |
Note: for all of operators you see in the list above, there are two operands involve in the operation. These operands can be a value, an expression, or the result of calling a function.
Note: expression is an operation that result a value (for example, a multiplication operation that result a value is considered as an expression). So basically the operand of an arithmetic operation can itself be another operation that results a value.
Addition `+` Operator:
The addition operator is used to add two values (operand) and return the result.
Addition `+` Operator Syntax
LeftOperand + RightOperand
Addition `+` Operator Example:
res = 10 + 40
Here, the result of `10 +40` operation will be assigned to the `res` variable.
Basically, the `res` variable is now pointing to a memory location that contains the value 50.
Note: please check the Python variable section if you’re not familiar with variables.
Python Subtraction `-` Operator:
The subtraction operator is used to subtract two values from each other and return the result
Subtraction `-` Operator Syntax:
LeftOperand - RightOperand
Subtraction `-` Operator Example:
res = 50 – 10
Here, the value 50 is subtracted from the 10 and the result, which is 40, will be stored to a memory location and the `res` variable will point to that memory space.
Python Multiplication `*` operator:
The multiplication operator is used to multiply two operands and return the result.
Multiplication `*` operator Syntax:
LeftOperand * RightOperand
Multiplication `*` operator Example:
res = 4 * 10
Here, the result of this multiplication operation will be stored into a memory space and the `res` variable will point to that memory space.
Python Division `/` operator:
The division operator is used to divide the left operand to the right operand and return the result.
Division `/` operator Syntax:
LeftOperand / RightOperand
Division `/` operator Example:
res = 10 / 2
Here the result of this division operation will be stored in a memory space and the res variable will point to that memory space.
Python Floor Division `//` operator:
Using the floor division operator, we can divide the left operand to the right operand and return the largest possible integer value.
Floor Division `//` operator Syntax:
LeftOperand // RightOperand
Floor Division `//` operator Example:
res = 52 // 7
Here, the result of this floor division operation (which is 7) will be stored into a memory space and the `res` variable will point to that memory location.
Python Exponent ** Operator:
Using the exponent operator, we can run an exponential operation.
Exponent ** Operator Syntax:
LeftOperand ** RightOperand
Exponent ** Operator Example:
res = 8 ** 2
Here the result is 64 and it will be assigned to the res variable.
Python Modulus `%` Operator:
Using the modulus operator, we can run a modulus operation.
Modulus `%` Operator Syntax:
LeftOperand % RightOperand
Modulus `%` Operator Example:
res = 13 % 3
Here, the result of this modulus operation will be stored into a memory space and the `res` variable will point to it.