Social Media

12/22/2018

Arithmetic operators

The table for common arithmetic operators is given below:
Operator
Expression
Keyword
**4**2=16exponent
/4/3=1.3333float
//4/3=1floor value division
*4*2=8Multiplication
%4%3=1Remainder(Modulus)

There are some points to be noted here
  • Modulus operator also works on negative numbers. The sign of the denominator is always the sign of the result
  • -4%-3=-1 result sign is same as denominator sign, and perform normal modulus operation
  • 4%-3=-2  result always negative and go to one upper multiple of 3 means 6 here subtract 6-4
  • -4%3=2   result always positive and go to one upper multiple of 3 means 6 here subtract 6-4
  • 2.5%2=0.5
  • 2%3.0=2.0
  • "ab"*3=ababab
  • The precedence order is as:
           **
          / // * %
          +  -

Be First to Post Comment !
Post a Comment