#6 - Arithmetic operators - Bringing maths in coding

Arithmetic Operators






Till now we have learned about print function and variables and going towards learning about arithmetic operators and how to implement them in our code.

How to implement basic operators in the code?

It's so simple to perform things like add, subtract, multiply and divide in python. We just have to use the symbols.

------------------------------------------------

code:-

a = 5

b = 10

c = a + b

print(c)

output:-

15

-------------------------------------------------

Other operators in python are:-

OperatorDescriptionExample
+ AdditionAdds values on either side of the operator.a + b = 30
- SubtractionSubtracts right hand operand from left hand operand.a – b = -10
* MultiplicationMultiplies values on either side of the operatora * b = 200
/ DivisionDivides left hand operand by right-hand operandb / a = 2
% ModulusDivides left hand operand by right-hand operand and returns remainderb % a = 0
** ExponentPerforms exponential (power) calculation on operatorsa**b =10 to the power 20
//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) −9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0

What coming next?

Now let's learn about Data types. Remember that this is one of the most important topics in Coding.

Data Types

Comments

Post a Comment

Popular Posts