1 python
在下面的代码中,
abc = (1,2,3)
a = abc[0]
b = abc[1]
c = abc[2]
print('%d, %d, %d' %(a,b,c)) # gives 1,2,3 as expected
a /= 3
b /= 3
c /= 3
print('%d, %d, %d' %(a,b,c)) # gives 0,0,1... which is NOT expected
Run Code Online (Sandbox Code Playgroud)
我想,但是,有a, b, c是0.333, 0.6666, 1分别.
即使我在以下情况下此问题仍然存在
即使我把所有东西都放到一个漂浮物中,如:
a = float(float(a)/float(3.0)) # still returns 0
Run Code Online (Sandbox Code Playgroud)我甚至使用python 3,所以int/int除法应该返回一个浮点数.
| 归档时间: |
|
| 查看次数: |
106 次 |
| 最近记录: |