Friday 4 December 2015

Arithmetic Operators in python

Following are the arithmetic operators supported by python.

Operator
Description
Example
+
Addition
2+3
-
Subtraction
2-3
*
Multiplication
2*3
/
Division always returns a float value. To get only integer result use //.
2/3 returns 0.6666666666666666
//
Floor division discards the fractional part
2//3 returns 0
%
Returns the remainder of the division.
2%3
**
Power
2**3 returns 2 power 3  = 8



>>> 4+2
6
>>> 4-2
2
>>> 4/2
2.0
>>> 4*2
8
>>> 4//2
2
>>> 4**2
16






Previous                                                 Next                                                 Home

No comments:

Post a Comment