在python2.7中,两个整数相除的结果默认会保留整数,可以用from __future__ import division改变这种行为。
在python3中,默认行为发生了变化,如果要使用整数除,可以使用//
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 7/3
2
>>> 7/3.0
2.3333333333333335
>>> from __future__ import division
>>> 7/3
2.3333333333333335
>>> 7//3
2
>>>