在python2.7中,兩個整數相除的結果默認會保留整數,能夠用from __future__ import division改變這種行爲。python
在python3中,默認行爲發生了變化,若是要使用整數除,可使用//python2.7
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32orm
Type "help", "copyright", "credits" or "license" for more information.it
>>> 7/3io
2form
>>> 7/3.0import
2.3333333333333335im
>>> from __future__ import divisiondi
>>> 7/3vi
2.3333333333333335
>>> 7//3
2
>>>