1、
'/'
performs float division and '//'
performs integer division
<span style="color:#39424e;">>>> </span><span style="color:#ff0000;">from __future__ import division</span><span style="color:#39424e;">
>>> print 4/3
1.3333333333333333
>>> print 4//3
1</span>
2、
One of the built-in functions of Python is divmod, which takes two arguments a and b and returns a tuple containing the quotient of a/b ( a//b ) and remainder a .
Here a/b can be compared with integer division a//b .
>>> print divmod(177,10)
(17, 7)
Here 177//10 => 17
and 177%10 => 7
3、
We have only heard of the powers of Python, so far; now we will witness them :)
Power or exponent in Python can be calculated using the built-in power function. Which can be called as for ab
>>> pow(a,b)
or
>>> a**b
It's also possible to calculate abmodm .
>>> pow(a,b,m)
This is very helpful in computations where you have to print result % mod.
Note that here a and b can be floats and even negatives; but if a third argument is present, b cannot be negative.
Note Python has a module math, which has its own pow() but it takes two arguments and returns a float. Frankly speaking, we will never use math.pow()