Arithmetic operators allow us to perform mathematical operations on numbers. The basic arithmetic operators in Python are:
| Operator | Name | Description |
|---|---|---|
+ | Addition | Adds two values |
- | Subtraction | Subtracts the second value from the first |
* | Multiplication | Multiplies two values |
/ | Division | Divides the first value by the second (returns a float) |
% | Modulo | Returns the remainder of the division of the first value by the second |
** | Exponentiation | Raises the first value to the power of the second |
// | Integer Division | Divides the first value by the second and returns the integer part |
If you want to learn more, check out the Introduction to Programming Course
List of Arithmetic Operators
Addition +
The addition operator (+) is used to add two numbers. It can also be used to concatenate strings and lists in Python.
a = 5
b = 3
result = a + b # result is 8
Subtraction -
The subtraction operator (-) is used to subtract one number from another.
a = 10
b = 7
result = a - b # result is 3
Multiplication *
The multiplication operator (*) is used to multiply two numbers.
a = 5
b = 4
result = a * b # result is 20
Division /
The division operator (/) is used to divide one number by another. In Python 3, division always returns a floating-point number (float).
a = 10
b = 2
result = a / b # result is 5.0
Integer Division //
The integer division operator (//) is used to divide one number by another and return the integer quotient, discarding any decimal part.
a = 10
b = 3
result = a // b # result is 3
Modulo %
The modulo operator (%) is used to get the remainder of a division between two numbers.
a = 10
b = 3
result = a % b # result is 1
Exponentiation **
The exponentiation operator (**) is used to raise a number to a power.
a = 2
b = 3
result = a ** b # result is 8
