可是我却得到这样的结果:
而不是我想象的17//4=4.25;(17/4)==(17//4)为假。>>> 17/4
4
>>> 17//4
4
>>> (17/4)==(17//4)
True
>>>
为什么,难道这个规则在python2.6中改变了?
而不是我想象的17//4=4.25;(17/4)==(17//4)为假。>>> 17/4
4
>>> 17//4
4
>>> (17/4)==(17//4)
True
>>>
代码: 全选
>>> 17/4
4
>>> 17//4
4
>>> 17.0/4
4.25
>>> 17.0//4
4.0
在2.7中,/是整数除法,//是做floor division,也就是和floor()函数一样。The / (division) and // (floor division) operators yield the quotient of their arguments.
可见,/和//的结果还是一样的?(整数的时候)Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>> 1//2
0
>>> -1/2
-1
>>> -1//2
-1
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import division
>>> 1/2
0.5
>>> 1//2
0
>>> -1/2
-0.5
>>> -1//2
-1