在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