python中from

it2026-05-14  1

python中from __future__ import division

ppython2.7版本中整数相除得出的结果不显示小数

a = 9 / 2 print(a)

输出结果:

4

此时就需要调用from __future__ import division

1 from __future__ import division 2 a = 9 / 2 3 print(a)

输出结果:

4.5

当然还有另一种方式:

1 a = 9.0 / 2 2 print a

我们将数字写成9.0,得出的结果就会显示小数了

PS:该问题在python3版本中则不需要使用

posted on 2019-04-09 10:30 恒笛 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/xwqhl/p/10675382.html

相关资源:数据结构—成绩单生成器
最新回复(0)