Aritmetic operators allow us to perform mathematical operations on numbers. The basic arithmetic operators in Python are as follows:
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) |
% | Modulus | Returns the remainder of the division of the first value by the second |
** | Exponentiation | Raises the first value to the power of the second |
// | Floor Division | Divides the first value by the second and returns the integer part |
If you want to learn more about Arithmetic Operators
consult the Introduction to Programming Course read more
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
Floor Division (//)
The floor 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
Modulus (%)
The modulus operator (%
) is used to obtain 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