Python天天美味(10) - 除法小技巧

Python中将两个整数相除,默认结果是为整数的。但我们可以通过下面的方法,使得两个整数相除的结果为小数。
from __future__ import division

print 7/3

输出结果:

2.3333333333


Python 天天美味系列(总)

Python 天天美味(8) - 字符串中的字符倒转

Python 天天美味(9) - translator  

Python 天天美味(10) - 除法小技巧  

Python 天天美味(11) - 可爱的大小写
Python 天天美味(12) - 条件判断的缩写

...

posted @ 2008-05-04 09:55  CoderZh  阅读(2667)  评论(9编辑  收藏  举报