python from __future__ import division
来源:互联网 发布:cf变枪软件 编辑:程序博客网 时间:2024/06/05 18:57
转自http://blog.csdn.net/feixingfei/article/details/7081446
from __future__ import division
导入python未来支持的语言特征division(精确除法),当我们没有在程序中导入该特征时,"/"操作符执行的是截断除法(Truncating Division),当我们导入精确除法之后,"/"执行的是精确除法,如下所示:
---------------------------------------------------------------------------------------------
>>> 3/40
>>> from __future__ import division
>>> 3/4
0.75
--------------------------------------------------------------------------------------------
导入精确除法后,若要执行截断除法,可以使用"//"操作符:
--------------------------------------------------------------------------------------------
>>> 3//4
0
>>>
>>> 3//4
0
>>>
--------------------------------------------------------------------------------------------
一些将来特征如下:
PEP:Python Enhancement Proposals
可以在这个地方找到很多PEP:http://www.python.org/dev/peps/ 里面还能看到许多提议的动机
比如有division:
The current division (/) operator has an ambiguous meaning for numerical arguments:
it returns the floor of the mathematical result of division if the arguments are ints or longs, but it returns a reasonable approximation of the division result if the arguments are floats or complex.
This makes expressions expecting float or complex results error-prone when integers are not expected but possible as inputs.
- 顶
- 0
- 踩
0 0
- python from __future__ import division
- python from __future__ import division
- python from __future__ import division
- Python from __future__ import division
- python中的python from __future__ import division
- from __future__ import division
- Python自然语言处理小问题之from __future__ import division
- Python_(__future__.py源代码) 可以引用from __future__ import division
- 关于python 中的__future__模块(from __future__ import ***)
- Python 基础 —— from __future__ import
- from __future__ import unicode_literals
- from __future__ import absolute_import
- from __future__ import absolute_import
- from __future__ import print_function
- from __future__ import 作用
- from __future__ import division 报错,不存在该模块。原因是。。。。
- Python基础之--from __future__ import unicode_literals作用
- python的import __future__作用
- C++初学者面向对象易犯错误模型
- thinkphp3.2中的上传文件根目录设置
- 态势“知”多少,点开就知道
- 我的第一篇~-~
- 我必须得告诉大家的MySQL优化原理
- python from __future__ import division
- 模板配置对话框的创建
- List循环移除元素
- 预留空间环形队列使用总结
- 几行代码实现AJAX延迟请求
- char类型和short,int类型之类的转换
- 03-树3 Tree Traversals Again (25分)
- 利用Boost.Python实现Python C/C++混合编程
- TensorFlow实战15:TensorBoard的使用(tensorflow的可视化工具)