Arithmetic Operators
Arithmetic Operators are used to perform basic mathematical arithmetic operators like addition, subtraction, multiplication, etc. The following table lists out all the arithmetic operators in Python.
Operator Symbol | Example | Description |
---|---|---|
+ | x + y | Returns addition of x and y . |
– | x – y | Returns the subtraction of y from x . |
* | x * y | Returns the multiplication of x and y . |
/ | x / y | Returns the result of division of x by y . |
% | x % y | Returns the reminder of division of x by y . Known as modular division. |
** | x ** y | Returns x raised to the power of y . Exponentiation. |
// | x // y | Returns the integer quotient of division of x by y . |
ADVERTISEMENT
Example
In the following program, we will take values in variables x
and y
, and perform arithmetic operations on these values using Python Arithmetic Operators.
Python Program
x = 5 y = 2 addition = x + y subtraction = x - y multiplication = x * y division = x / y modulus = x % y exponentiation = x ** y floor_division = x // y print(f'x + y = {addition}') print(f'x - y = {subtraction}') print(f'x * y = {multiplication}') print(f'x / y = {division}') print(f'x % y = {modulus}') print(f'x ** y = {exponentiation}') print(f'x // y = {floor_division}')Try Online
Output
x + y = 7 x - y = 3 x * y = 10 x / y = 2.5 x % y = 1 x ** y = 25 x // y = 2
Conclusion
In this Python Tutorial, we learned about all the Arithmetic Operators in Python, with examples.