关于python2和python3除法的区别

在Python2中,除法的取值结果取整数

>>> 9/2
4

而在Python3中,除法/的结果包含小数,如果只想取整数需要使用//

>>> 9/2
4.5
>>> 9//2
4

如果在python2中需要实现与python3相同功能的除法,需要导入模块

xuhuance@xhcdream:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import division
>>> 9/2
4.5