导入python未来支持的语言特征division(精确除法),当我们没有在程序中导入该特征时,"/"操作符执行的是截断除法(Truncating Division),当我们导入精确除法之后,"/"执行的是精确除法,如下所示:
---------------------------------------------------------------------------------------------

>>> 3/4

0

>>> from __future__ import division

>>> 3/4

0.75

--------------------------------------------------------------------------------------------

导入精确除法后,若要执行截断除法,可以使用"//"操作符:
--------------------------------------------------------------------------------------------
>>> 3//4
0

--------------------------------------------------------------------------------------------
 
一些将来特征如下:
feature optional in mandatory in effect
nested_scopes 2.1.0b1 2.2 PEP 227Statically Nested Scopes
generators 2.2.0a1 2.3 PEP 255Simple Generators
division 2.2.0a2 3.0 PEP 238Changing the Division Operator
absolute_import 2.5.0a1 2.7 PEP 328Imports: Multi-Line and Absolute/Relative
with_statement 2.5.0a1 2.6 PEP 343The “with” Statement
print_function 2.6.0a2 3.0 PEP 3105Make print a function
unicode_literals 2.6.0a2 3.0 PEP 3112Bytes literals in Python 3000
PEP:Python Enhancement Proposals
可以在这个地方找到很多PEP:http://www.python.org/dev/peps/ 里面还能看到许多提议的动机
----------------------------------------------------------------------------
nested_scopes: 改变名空间的搜索过程
generators:使用生成器.能够产生能保存当前状态的函数.
division:精确的除法
absolute_import:包含绝对路径.方便include
with_statement:安全的打开文件
 

from __future__ import division的更多相关文章

  1. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  2. 【python】只执行普通除法:添加 from __future__ import division

    from __future__ import division 注意future前后是两个下划线

  3. python中from __future__ import division

    ppython2.7版本中整数相除得出的结果不显示小数 a = 9 / 2 print(a) 输出结果: 4 此时就需要调用from __future__ import division 1 from ...

  4. 精确除法:from __future__ import division

    在python中做除法运算,使用1/2运行结果为0,为取结果的整数部分 如果用1.0/2或1/2.0运行结果为0.5,按照浮点数的位数取结果 但是实际应用中我们需要取除法的精确结果,我们就可以在运行前 ...

  5. from __future__ import包的作用

    __future__是python2的概念,其实是为了使用python2时能够去调用一些在python3中实现的特性 1.absolute_import from __future__ import ...

  6. from __future__ import absolute_import

    from __future__ import absolute_import 这样以后:局部的包将不能覆盖全局的包, 本地的包必须使用相对引用了. 例: from celery import Cele ...

  7. from __future__ import print_function的作用

    阅读代码的时候会看到下面语句: from __future__ import print_function 该语句是python2的概念,那么python3对于python2就是future了,也就是 ...

  8. Python底层库的函数中from __future__ import absolute_import的作用

    在查看TensorFlow的底层优化器时候看到from __future__ import absolute_import 查找相关资料后发现 这个语句的意思是加入绝对引用的特征 直白的意思是,比如: ...

  9. from __future__ import

    读代码的过程中看到的,好奇搜索了一下,其实当在我们调试别人Python代码的过程中经常会遇到一些问题,比如版本不同,代码也会有所改变,比如print函数 Python 2.7版本为 print “ ” ...

随机推荐

  1. sql存储过程输出

    1.存储过程写法 create procedure [dbo].[Y_GetICBillNo] @IsSave smallint, @FBillType int, @BillID VARCHAR (5 ...

  2. 关于android webview 设置cookie的问题

    转自:http://blog.csdn.net/encienqi/article/details/7912733 我们在android中访问网络经常会用到Apache的HttpClient,用此类去访 ...

  3. bzoj 1390: [Ceoi2008]Fence

    Description 在一个大小为1000*1000的区域中,有n个固定点,m棵tree . 现在你要建一个围栏来保护tree,建它的费用为你选用的固定点的个数 *20和 你没有圈进围栏的tree* ...

  4. DevExpress 组件

    最近看到 伍华聪 的博客里, DevExpress 组件那个效果很好看,特别是 LookUpEdit GridLookUpEdit 这两个控件,完美改善了 WinForm 里的 ComboBox 今天 ...

  5. windows基础应用(word)

    自动编号-最后选择一下编号格式 TAB 进入子节 shift+TAB 回退到父节 取消邮箱/网址链接 ctrl+z word中输入不认识生僻字:输入偏旁部首王,选中插入中寻找 输入英文时,更改大小写/ ...

  6. 深入理解yield(二):yield与协程

    转自:http://blog.beginman.cn/blog/133/ 协程概念 1.并发编程的种类:多进程,多线程,异步,协程 2.进程,线程,协程的概念区别: 进程.线程和协程的理解 进程:拥有 ...

  7. Microsoft Dynamics CRM 2011 安装完全教程

    作者:卞功鑫,转载请保留.http://www.cnblogs.com/BinBinGo/p/4302612.html 环境介绍 WINDOWS 2008 R2 Datacenter Microsof ...

  8. Log4net详细说明(全)

    转自:http://www.cnblogs.com/zhangchenliang/p/4546352.htmlhttp://www.cnblogs.com/zhangchenliang/p/45463 ...

  9. RAC 11.2的新特性

    网格即插即用(GPnP) 网格即插即用帮助管理员来维护集群,以前增加或删除节点需要的一些手动操作的步骤现在可以由GPnP来自动实现. GPnP不是一个单独的概念,它依赖于以下特性:在一个XML配置文件 ...

  10. 学习MongoDB 七: MongoDB索引(索引基本操作)(一)

    一.简介 在MongoDB建立索引能提高查询效率,只需要扫描索引只存储的这个集合的一小部分,并只把这小部分加载到内存中,效率大大的提高,如果没有建立索引,在查询时,MongoDB必须执行全表扫描,在数 ...