Crus4

logo

Arithmetic Operators Python


Python can also be used to perform mathematical operations, like Addition, Subtraction, Multiplication, Division etc.

To do a calculation in Python you have to just enter the mathematical expression between the brackets after the print statement.

Like this!

print(2 + 5)

Output

7

Note:- The space between the numbers and mathematical operators is not necessarily, but it helps other programmers to read your code clearly.

Similarly

print(3 - 1)
print(7 * 2)
print(6 / 2)

Output

2

14

3

Other Mathematical Operations

Other than Addition, Subtraction, Multiplication and Division, Python can also be used to solve an exponential function, and find reminder and quotient.

Exponentiation Operator:- In Python Exponentiation operator is defined with **. It is used to define the exponential function x^​y.

print (3 ** 2)

Output

9

Modulus Operator:- In Python the percentage sign (%) is called modulus operator. It is used to find the reminder when first number is divided by second number.

print (32 % 6)

Output

2

Floor Division:- In Python double slash // is used for floor division. Floor division is used to find the floor of the quotient when first number is divided by second number.

print (6 // 4)

Output

1


Arithmetic Operators Python

3 thoughts on “Arithmetic Operators Python

Leave a Reply

Your email address will not be published. Required fields are marked *