Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

python math operators

Math operators:

  • In python, we have various arithmetic operators.
  • These are called math operators because they perform different types of mathematical operations.
  • Here  we have seven types of arithmetic operators:
  1. +     addition
  2. -      subtraction.
  3. /       division.
  4. %     modulus.
  5. *       multiplication.
  6. //       floor division.
  7. **      exponential.
1.Addition(+): It is used to add two or more operands.
It is Represented by the "+". symbol.
syntax:(a+b).

2.subtraction(-): It subtracts the value of the  one operand to other operands 
syntax:(a-b).

3.Division(/): It divides one operand with another operand and gives the remainder. The result is always in float type only.
It is represented by the symbol "/'.
syntax:(a/b).

4.modulus(%): It is the remainder of the operands.
It is represented by the symbol "%".
syntax:(a%b).

5.Multiplication(*): It multiply the two or more operands.
It is represented by the symbol "*".
syntax:(a*b).

6.floor division(//): It divides the operands and get the result in the whole number only.
It is represented by the symbol "//'.
syntax:(a//b).

7.exponential(**): It is used to calculate the power of the values.
It is represented by the symbol "**'.
syntax:(a**b).


Example: write a python program for integers using math operators.

  1. x=3
  2. y=4
  3. print(x+y)
  4. print(x-y)
  5. print(x/y)
  6. print(x%y)
  7. print(x*y)
  8. print(x//y)
  9. print(x**y)
output:     7
               -1
               0.75
                3
               12
               0
               81






This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

python math operators

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×