math - In Python 2, what is the difference between '/' and '//' when used for division? -
is there benefit using 1 on other? in python 2, both seem return same results:
>>> 6/3 2 >>> 6//3 2
in python 3.0, 5 / 2
return 2.5
, 5 // 2
return 2
. former floating point division, , latter floor division, called integer division.
in python 2.2 or later in 2.x line, there no difference integers unless perform from __future__ import division
, causes python 2.x adopt behavior of 3.0
regardless of future import, 5.0 // 2
return 2.0
since that's floor division result of operation.
you can find detailed description @ https://docs.python.org/whatsnew/2.2.html#pep-238-changing-the-division-operator
Comments
Post a Comment