The table for common arithmetic operators is given below:
There are some points to be noted here
| Expression | ||
|---|---|---|
| ** | 4**2=16 | exponent |
| / | 4/3=1.3333 | float |
| // | 4/3=1 | floor value division |
| * | 4*2=8 | Multiplication |
| % | 4%3=1 | Remainder(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