导入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. Django中更新多个对象数据与删除对象的方法

    更新多个对象 例如说我们现在想要将Apress Publisher的名称由原来的”Apress”更改为”Apress Publishing”.若使用save()方法,如: ? 1 2 3 >&g ...

  2. CentOS Linux解决Device eth0 does not seem to be present 但是没有发现eth1

    http://www.linuxidc.com/Linux/2012-12/76248.htm 此标题已经是有人写过的了.但是为什么拿来重写? 我复制完,没有发现有eth1这个网卡 为什么呢?需要选中 ...

  3. android 更新listview 其中一行的数据显示

    private void updateView(int index){ View v = yourListView.getChildAt(index - yourListView.getFirstVi ...

  4. 廖雪峰Java1-2Java程序基础-2变量和数据类型

    1.变量 变量是可以持有某个基本类型的数值,或者指向某个对象. 变量必须先定义后使用 定义: 变量类型 变量名 = 初始值; 2.java基本数据类型 整数类型:long int short byte ...

  5. kddcup2015

    kddcup2015,二分类,课程逃课预测.写了好久了,突然想起简单整理一下,以备后需. step1,预处理,利用numpy和pandas库,数值化特征,简单而优雅 #!/usr/bin/env py ...

  6. windows 网管常用命令

    Windows网络命令行程序 这部分包括: 使用 ipconfig /all 查看配置 使用 ipconfig /renew 刷新配置 使用 ipconfig 管理 DNS 和 DHCP 类别 ID ...

  7. [UE4]使机器人受伤

  8. mysql 字符集排查

    mysql 字符集排查 库级别 SELECT * FROM information_schema.schemata WHERE schema_name NOT IN ( 'information_sc ...

  9. FDD vs TDD

    双工方式 FDD vs TDD  频分双工(FDD) 收发信各占用一个频率. 优点是收.发信号同时进行,时延小,技术成熟,缺点是设备成本高.  时分双工(TDD) 收发信使用同一个频率,但使用不同 ...

  10. python 简单的单例模式日志模块

    # -*- coding: utf-8 -*-import logging def singleton(cls): instance = {} def _singleton(*args, **kw): ...