核心Python数值类型的基本原理 [英] Rationale for core Python numeric types

查看:54
本文介绍了核心Python数值类型的基本原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好 -


我是Python的新手,有点吃惊地发现

核心语言缺少一些基本的数字类型(例如,单精度

浮点数,短整数)。我意识到有些扩展可以添加这些类型 - 但是,将它们排除在外的理由是什么?我有没有
徘徊在空间/时间连续区的区域,人们永远不会想要读取二进制数据文件?


Matt Feinstein


-

相信可以证明是真实的东西是没有道理的。

Hi all--

I''m new to Python, and was somewhat taken aback to discover that the
core language lacks some basic numerical types (e.g., single-precision
float, short integers). I realize that there are extensions that add
these types-- But what''s the rationale for leaving them out? Have I
wandered into a zone in the space/time continuum where people never
have to read binary data files?

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.

推荐答案

Matt Feinstein写道:
Matt Feinstein wrote:
我是Python的新手,有点吃惊地发现核心语言缺乏一些基本的数值类型(例如,单精度浮点数,短整数)。我意识到有一些扩展可以添加这些类型 - 但是将它们排除在外的理由是什么?我是否已经进入空间/时间连续区域,人们永远不必阅读二进制数据文件?
I''m new to Python, and was somewhat taken aback to discover that the
core language lacks some basic numerical types (e.g., single-precision
float, short integers). I realize that there are extensions that add
these types-- But what''s the rationale for leaving them out? Have I
wandered into a zone in the space/time continuum where people never
have to read binary data files?




查看文档结构模块:
http://docs.python。 org / lib / module-struct.html


也开始抛弃你的C背景,因为它将以许多其他方式限制

当你学习Python时。 :-)


-Peter



Check the docs for the struct module:
http://docs.python.org/lib/module-struct.html

Also start leaving your C background behind, since it will limit
you in many other ways as you learn Python. :-)

-Peter


文章< d0 ************* *******************@4ax.com>,

Matt Feinstein< no **** @ here.com>写道:
In article <d0********************************@4ax.com>,
Matt Feinstein <no****@here.com> wrote:

我是Python的新手,并且有点吃惊地发现
核心语言缺少一些基本的数字类型(例如,单精度
float,short integers)。我意识到有一些扩展可以添加这些类型 - 但是将它们排除在外的理由是什么?我是否已经徘徊在空间/时间连续区域,人们永远不必读取二进制数据文件?

I''m new to Python, and was somewhat taken aback to discover that the
core language lacks some basic numerical types (e.g., single-precision
float, short integers). I realize that there are extensions that add
these types-- But what''s the rationale for leaving them out? Have I
wandered into a zone in the space/time continuum where people never
have to read binary data files?




正如彼得所说,使用struct模块获取特定的

二进制格式的数据。除此之外,你需要那些数据类型?


理由是大多数Python程序不需要这些功能,

和它'坚持使用一些基本类型可以提高

的最大功能范围。 Python 3.0甚至不提供固定大小的

整数类型 - 它将全部是无界的Python长类型(大多数 -

将会有可能是一些内部优化,但是没有什么可以用来检测Python用户。

-

Aahz(aa ** @ pythoncraft.com)< *> http://www.pythoncraft.com/


打字很便宜。思考很昂贵。 --Roy Smith,c.l.py



As Peter said, use the struct module to get data in/out of specific
binary formats. Other than that, what do you need those datatypes for?

The rationale is that most Python programs don''t need that functionality,
and it''s much more productive to stick with a few basic types that give
maximum range of functionality. Python 3.0 won''t even offer a fixed-size
integer type -- it''ll all be the unbounded Python long type (mostly --
there will be some internal optimizations, probably, but nothing that the
Python user will be able to detect).
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"Typing is cheap. Thinking is expensive." --Roy Smith, c.l.py




" Matt Feinstein" <无**** @ here.com>在消息中写道

news:d0 ******************************** @ 4ax.com ...

"Matt Feinstein" <no****@here.com> wrote in message
news:d0********************************@4ax.com...
大家好 -

我是Python的新手,并且有点吃惊地发现
核心语言缺少一些基本的数字类型(例如,单精度浮点数,短整数)。我意识到有一些扩展可以添加这些类型 - 但是将它们排除在外的理由是什么?我是否已经进入空间/时间连续区域,人们永远不必读取二进制数据文件?
Hi all--

I''m new to Python, and was somewhat taken aback to discover that the
core language lacks some basic numerical types (e.g., single-precision
float, short integers). I realize that there are extensions that add
these types-- But what''s the rationale for leaving them out? Have I
wandered into a zone in the space/time continuum where people never
have to read binary data files?




按设计,Python与机器可读的线性ram计算机编程语言一样多或多是人类可读的算法语言。从

算法/数学观点来看,数字类型是计数,整数,
有理数,实数,复数等。从这个角度来看,字节长度是

机器实现细节,而不是数字类型。所以是的,他们是

降级为可选的扩展程序,以满足那些需要它们的人。请注意,

计算器不会(通常至少)具有单独的积分和

理性/真实类型。


Terry J 。芦苇




By design, Python is as much or more a human-readable algorithm language as
a machine-readable linear-ram computer programming language. From an
algorithmic/mathematical viewpoint, the number types are counts, integers,
rationals, reals, complexes, etc. From this viewpoint, byte-lengths are
machine-implementation details, not number types. So yes, they are
relegated to optional extensions for those who need them. Note that
calculators do not (typically at least) even have separate integral and
rational/real types.

Terry J. Reedy



这篇关于核心Python数值类型的基本原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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