This is due to a change in the semantics of the division between Python versions 2.X and 3.X.
In Python 2.X operations between integers always return an integer, so 6/10
is interpreted as the integer division - and therefore rounded to zero. It is necessary to convert one of the operands to float to do the floating-point division: 6.0/10
or 6/10.0
. This behavior has been "inherited" from C-like languages.
In Python 3.X, the division between integers can return a floating point. To make an integer division in this version it is necessary to use another operator: 6//10
. This behavior is more common in modern languages, especially dynamic typing.
The integer division operator also works on Python 2.X - and it returns an integer even when its operands are floats: 6.0 // 10.0
will give zero. Since the common division operator (called "true division") maintains the default behavior of its version for compatibility, but if you want to use the new semantics in Python 2.X simply do the following < in> import :
from __future__ import division
From there, the split will work as in 3.X (if this needs to be done in each source file or not, I'm not sure, I'd have to test or reference some reference).
Font