Numerical Operations

Normally, when asked to find the sum of two numbers like 8.9 + 86.57, you might use a calculator or a pencil and paper. Well, lets see how we can use Python to perform your calculation?

Let’s try it.

In [2]: # addition of two numbers
8.9 + 86.57
Out[2]: 95.47

As seen above Python can sum up numbers and this can be done for subtraction ( - ), division ( / ) and multiplication ( * ) as seen below.

Subtraction

9 - 4

In [2]: # subtraction of two numbers
9 - 4
Out[2]: 5

Division

20 / 5

In [2]: # division of two numbers
20 / 5
Out[2]: 4.0

Multiplication

9 * 6

In [2]: # multiplication of two numbers
9 * 6
Out[2]: 54

Operators

So far we’ve been using the Arithmetic Operators + , - , / and * but we have more that the python programming shell supports.

Operator Operation Description
+ Addition Adds values on either side of the operator.
- Subtraction Subtracts right hand operand from left hand operand.
* Multiplication Multiplies values on either side of the operator
/ Division Divides left hand operand by right hand operand
% Modulus Divides left hand operand by right hand operand and returns remainder
** Exponent Performs exponential (power) calculation on operators
// Floor Division The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity)

results matching ""

    No results matching ""