Arithmetic Operator in Python

 Arithmetic Operators in Python

Python helps us to solve the mathematical operations in a easy way. In terms of Arithmetic operations, it works the same way as we write with paper and pen.

If you prefer, please have a look into my video about Arithmetic Operators:

Arithmetic Operators in Python:

Operators

Meaning

Example

Result

+

Addition

8 + 4

12

-

Subtraction

8 - 4

4

*

Multiplication

8 * 4

32

/

Division

8 / 2

4.0

%

Module (provides only the remainder)

11 % 4

3

//

Provides only the quotient

11 / 4

2.75

**

Exponent (in other word “to the power of)

4 ** 3

64


Please see the output where I have made Addition, subtraction, multiplication and Division.

From the above output, you can see that the addition, subtraction and multiplication values are displayed in integers. But the output of division is displayed in float(10/2 = 5.0 [instead of 5, it is displayed as 5.0])











From the above output, you can see the operator "//" is used. This will give you the division output in integer value whereas the operator "/" will give you the result in the float.

Modules operator "%" will give you the remainder value. here from the above screenshot, 11 % 3 means, 11 has 3 times of 3 (3 * 3) and the remainder is 2. The output of module "%" is 2 which is the remainder.

Post a Comment