在python2 中实现向python3兼容的division(精确除法)
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
#导入前
>>> 10/3
3
>>> 10//3
3
>>> 10/3.0
3.3333333333333335
#导入后
>>> from __future__ import division
>>> 10/3
3.3333333333333335
#导入后如果要去整数,加'//'
>>> 10//3
3
>>> 10/3.0
3.3333333333333335
在python3中已经支持了精确算法,不需要导入
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 10/3
3.3333333333333335
>>> 10//3
3
>>> 10/3.0
3.3333333333333335
>>> 10//3.0
3.0