ATIME

python2和python3除法区别

在Python2中,除法的取值结果取整数
如9/2=4
而在Python3中,除法/的结果包含小数,如果只想取整数需要使用//运算符
而如果直接计算9/2=4.5
需要计算 9//2=4
如果在python2中需要实现与python3相同功能的除法,需要导入模块
atime@atime:~$ python -V
Python 2.7.12 (default, Jan 19 2018, 16:48:10) 
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import division
>>> 9/2
4.5

 

atime@atime:~$ python -V
Python 3.6 (default, Jan 19 2018, 16:49:14) 
Type "help", "copyright", "credits" or "license" for more information.
 >>> 9/2 4.5




点赞