Python 3000 deat!?是真正的分裂吗? [英] Python 3000 deat !? Is true division ever coming ?

查看:65
本文介绍了Python 3000 deat!?是真正的分裂吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Python 3000是真的吗?已经死了?

老实说,我认为,例如将5/2改为2.5(而不是2)将会打破很多代码:-(

另一方面我用Python作为Matlab替换并且将

一般像5/2 == 2.5


因此,我正在考虑默认我的所有模块/脚本以

"来自__future__进口部门

但是如果它永远不会到来(在这十年中,那就是)那么这将是一个浪费时间的b / b
只是让每个人感到困惑!!


谢谢,

Sebastian Haase

Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I''m using Python as "Matlab replacement" and would
generally like 5/2 ==2.5

So, I was contemplating to default all my modules/scripts to start with
"from __future__ import division"
but if it is never coming (in this decade, that is) then it would be a
waste of time just confuse everybody !!

Thanks,
Sebastian Haase

推荐答案

se*******@gmail.com 写道:

是不是Python 3000已经死了?
老实说,我认为例如将5/2改为2.5(而不是2)将会打破很多代码:-(
另一方面,我使用Python作为Matlab替换,并且
通常喜欢5/2 == 2.5

...
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I''m using Python as "Matlab replacement" and would
generally like 5/2 ==2.5

...




这是比较。科学。 101,基于三年级算术,而不是Python。

5/2 = 2是整数除法,这是整数运算的工作方式。

5./2 。= 2.5是浮点数学,具有

合并的所有舍入误差。


如果Matlab假设浮点数,则那就是你的意思'支付

大笔钱。


柯蒂斯



It''s Comp. Sci. 101, based on third grade artithmetic, not Python.
5/2=2 is integer division, that''s the way integer arithmetic works.
5./2.=2.5 is floating point math, with all the round off errors that
incorporates.

If Matlab assumes floating point, then that''s what you''re paying the
big bucks for.

Curtis


开2006年2月14日06:44:02 -0800, ra ************ @ gmail.com
On 14 Feb 2006 06:44:02 -0800, ra************@gmail.com
5./2.=2.5是浮点数学,包含
包含的所有舍入错误。
5./2.=2.5 is floating point math, with all the round off errors that
incorporates.




谢谢Curtis,我从来不知道这个伎俩。我想变量确实有

真正的除法你必须让它们漂浮?例如

float(var1)/ float(var2)?或者你知道一个不那么打字的方法吗?

那个?


-

Gregory Pi?ero

首席创新官

混合技术

www.blendedtechnologies.com


Gregory Pi?ero写道:
Gregory Pi?ero wrote:
2006年2月14日06:44:02 - 0800, ra************@gmail.com

On 14 Feb 2006 06:44:02 -0800, ra************@gmail.com

5./2.=2.5是浮点数学,包含
包含的所有舍入错误。
5./2.=2.5 is floating point math, with all the round off errors that
incorporates.


float(var1)/ float(var2)?或者你知道一个较少打字的方法吗?



Thanks Curtis, I never knew that trick. I guess for variables do have
true division you have to make them floats? e.g.
float(var1)/float(var2)? Or do you know a less typing approach for
that?




Googlepython true division - >我很幸运:

http://www.python.org/doc/2.2.3/whatsnew/node7.html


来自网页:


"""

*通过在模块(*)中包含__future__导入部门,/

运算符将被更改返回真正除法的结果,所以1/2

是0.5。没有__future__声明,/仍然意味着经典的

除法。在Python 3.0之前,/的默认含义不会改变。

"""


*作为第一个非文档字符串/非注释行。


请注意,那是'模块 - 交互式解释器不会

以相同的方式响应来自__future__ import ;声明。



Google "python true division" -> I''m feeling lucky:

http://www.python.org/doc/2.2.3/whatsnew/node7.html

From the web page:

"""
* By including a from __future__ import division in a module(*), the /
operator will be changed to return the result of true division, so 1/2
is 0.5. Without the __future__ statement, / still means classic
division. The default meaning of / will not change until Python 3.0.
"""

*As the first non-docstring/non-comment line.

Note that that''s for a module -- the interactive interpreter won''t
respond the same way to the "from __future__ import" statement.


这篇关于Python 3000 deat!?是真正的分裂吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆