Python测验 [英] Python Quiz

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

问题描述

理查德写道:

我不是专家,但你不会接受Python已经借用'FORTRAN'的固定格式语法。我只能想到Python和FORTRAN在我的头顶部,它使用空格作为语法的一部分。




绝对不是。如果没有解决Python的问题,那就是使用缩进来表示块结构,那么它显然不可能是
来自Fortran,因为Python做了什么Fortran做的事情

完全不同。


在Fortran中,特定列的起始行是有意义的(和其他的一样

特殊字符,特别是前导列)。在Python中,特别是

列没有意义。事实上,我冒昧地说它是b而不是重要的空白。在Python中...它是IndENTATION。

的区别非常重要,因为人类在阅读空白时很差(没有它的存在空白是肯定的,但是金额是多少?

我们不擅长阅读),但我们发现缩进是一种*非常*可读的

方式来标记块结构(实际上每种语言都没有$>
(像Fortran一样)禁止缩进,这是一个普遍遵守的公约




还有行的事实; (语句)由Python中的换行符定义

- 但我很少听到有关此问题的投诉,因为大多数程序员都会将代码精神化为行。无论如何。


当然,我并不是说在Python中空白是*毫无意义的*

在缩进之外...... Python很像C (以及许多其他人)在

方面。毕竟,在Cy = x + ++ z中,和y = x ++ + z相当不错的东西。不同的东西。并且在Python和C" x = abc"是合法的,但x = a bc

不是。


所以我会说MOST语言是否存在空格
重要...这是一个好主意,因为它有助于人类标记他们阅读的代码。 Python使用换行符来指示新的行

(语句)开始的位置......通常不是一个有争议的约定。最后,

大多数PROGRAMMERS使用缩进来表示块结构,但是Python

与大多数语言的不同之处在于Python解析器使用缩进

level作为块的语法,而大多数语言都不是。和Python

并不[1]关心AMOUNT的空白区域(独立于缩进

级别)这是一件好事,因为人类发现很难

阅读。


- Michael Chermside


[1]除非你混合标签和空格。不要那样做。如果你需要的话,请使用tabnanny。

解决方案

Michael Chermside< mc **** @ mcherm.com>写道:

richardc写道:

我不是专家,但你不会接受Python已经借用'FORTRAN'的固定格式语法。我只能想到Python和FORTRAN在我的头顶部,它使用空格作为语法的一部分。
绝对不是。如果没有解决Python的问题,那就是使用缩进来表示块结构的概念,它显然不可能来自Fortran,因为Python做了什么以及Fortran做了什么
完全不同。

在Fortran中,特定列的起始行是有意义的(特别是前导列中的其他特定字符)。在Python中,特定的
列没有任何意义。



当然,我并不是说在缩进之外的Python中空白是*毫无意义的。 ..在这方面,Python很像C(以及许多其他人)。毕竟,在Cy = x + ++ z中,和y = x ++ + z是相当不同的事情。并且在Python和C" x = abc"是合法的,但x = a bc
不是。




请注意Fortran(至少是历史性的Fortran - 不确定那些

upstart 9x variants)在很多很多其他人中不是*。一个人可以

写任何一个


DO 10我=某事物

DO10I =某事物

DO 1 0 I =


并将其交给编译器以确定您是否正在启动

DO循环或为其分配值变量DO10I。


[1993年2月签名。]


-

Mark Jackson - http://www.alumni.caltech.edu/~mjackson

一直用空格分隔单词成为公元十世纪的一般习俗

,并持续到1957年左右,当时FORTRAN放弃了这种做法。

FORTRAN放弃了这种做法。 >
- Sun FORTRAN参考手册


对不起,我不是故意建议Python使用缩进
(ws),是一个问题,或者在任何方面都是像FORTRAN那样的劳动。


Michael Chermside < MC **** @ mcherm.com>在留言中写道

新闻:ma ********************************** @ python .o rg ...

SNIP

绝对不是。如果没有解决Python的问题,那就是使用缩进来表示块结构的概念,它显然不可能来自Fortran,因为Python做了什么以及Fortran做了什么
完全不同。


非常正确,但要说FORTRAN和Python没有任何共同点,那么
也是不真实的。他们都使用ws来分隔合成元素,而不是相同的元素,但是以与大多数其他语言截然不同的方式使用它。


我承认Python问题没有得到FORTRAN的任何激励,任何

''相似性'都是巧合。

还有一个事实是行。 (语句)由Python中的换行符定义 - 但我很少听到有关此问题的投诉,因为大多数
程序员在精神上将代码分成行。无论如何。


那里没有投诉

当然,我并不是说在缩进之外,在Python中没有空格*没有意义......




应该希望不要


请不要把我的帖子误解为对Python的攻击,而我是一个老套的人/>
C ++程序员和我第一次看Pythno我以为... urggh,没有

括号那可怕。看了一会儿后,我喜欢它。像所有的一样

它有它的位置。


对不起,如果我让任何人感到不安......我知道FORTRAN很糟糕,但它并不坏...... 。

erm,实际上它是mabe?


至于OCCAM,我多年没有编程,这很有趣*在
中丢失
美好的回忆*


Rich


Mark Jackson写道:


Michael Chermside< mc **** @ mcherm.com>写道:

当然,我并不是建议在缩进之外的空格中没有*毫无意义* ... Python很像C(以及很多很多其他的)
那方面。



请注意,Fortran(至少是历史悠久的Fortran - 不确定那些
新贵的9x变种)在很多中不是*许多其他人。一个人可以写任何一个

DO 10我=某事
DO10I =某事
DO 1 0我=某事

并留下它编译器判断你是否正在启动一个DO循环或为变量DO10I赋值。




如果你这么说你把它留给编译器来决定如何解释上述三个语句中的任何一个,然后明确地说空白

*不是*毫无意义。它可能是编译器依赖的东西,

但没有任何意义。除非你在给定的FORTRAN

编译器上说这个,否则只能对上述所有三个语句

进行一种可能的解释。这将是令人惊讶的。


-Peter


richardc writes:

Im no expert but wouldnt you accept that Python has ''borrowed'' FORTRAN''s
fixed format syntax. I can only think of Python and FORTRAN off the top of
my head which use whitespace as part of the syntax.



Definitely NOT. Without addressing the question of HOW Python came by the
idea of using indentation to indicate block structure, it clearly couldn''t
have been from Fortran, because what Python does and what Fortran does
are COMPLETELY different.

In Fortran, starting lines in particular columns is meaningful (as are other
particular characters in particular leading columns). In Python, particular
columns have NO meaning. In fact, I would venture to say that it is
NOT whitespace that is "significant" in Python... it''s INDENTATION. The
distinction is significant, because humans are very poor at reading
whitespace (the presense or absence of it yes, but the amount is something
we''re not good at reading), but we find indentation to be a *very* readable
way to mark block structure (in practically every language which doesn''t
(like Fortran) prohibit indentation, it is a convention adhered to
universally ).

There''s also the fact that "lines" (statements) are defined by line breaks
in Python -- but I rarely hear complaints about this, since most programmers
mentally chunk up code into "lines" anyway.

Of course, I''m not suggesting that whitespace is *meaningless* in Python
outside of indentation... Python is much like C (and many, many others) in
that regard. After all, in C "y=x+ ++z" and "y=x++ +z" are quite
different things. And in both Python and C "x=abc" is legal, but "x=a bc"
is not.

So I would say MOST languages make the presence or absence of whitespace
significant... and that''s a good idea, since it helps humans "tokenize"
the code they read. Python uses newlines to indicate where new "lines"
(statements) begin... not usually a controversial convention. Finally,
most PROGRAMMERS use indentation to indicate block structure, but Python
differs from most languages in that the Python parser uses the indentation
level as syntax for blocks, while most languages don''t. And Python
doesn''t[1] care about the AMOUNT of white space (independent of indentation
level) which is a good thing, because humans find that difficult to
read.

-- Michael Chermside

[1] Unless you mix tabs and spaces. Don''t do that. Use tabnanny if you
need to.

解决方案

Michael Chermside <mc****@mcherm.com> writes:

richardc writes:

Im no expert but wouldnt you accept that Python has ''borrowed'' FORTRAN''s
fixed format syntax. I can only think of Python and FORTRAN off the top of
my head which use whitespace as part of the syntax.
Definitely NOT. Without addressing the question of HOW Python came by the
idea of using indentation to indicate block structure, it clearly couldn''t
have been from Fortran, because what Python does and what Fortran does
are COMPLETELY different.

In Fortran, starting lines in particular columns is meaningful (as are other
particular characters in particular leading columns). In Python, particular
columns have NO meaning.


Of course, I''m not suggesting that whitespace is *meaningless* in Python
outside of indentation... Python is much like C (and many, many others) in
that regard. After all, in C "y=x+ ++z" and "y=x++ +z" are quite
different things. And in both Python and C "x=abc" is legal, but "x=a bc"
is not.



Note that Fortran (at least historic Fortran - not sure about those
upstart 9x variants) is *not* among the "many, many others." One can
write any of

DO 10 I = something
DO10I = something
D O 1 0 I = something

and leave it to the compiler to figure out whether you''re starting a
DO-loop or assigning a value to the variable DO10I.

[Signature from February 1993.]

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Consistently separating words by spaces became a general custom
about the tenth century A.D., and lasted until about 1957, when
FORTRAN abandoned the practice.
- Sun FORTRAN Reference Manual


Sorry, I didnt mean to suggest for a second that Python''s use of indentation
(ws), is a problem or in any way a labour of love like FORTRAN''s.

"Michael Chermside" <mc****@mcherm.com> wrote in message
news:ma**********************************@python.o rg...
SNIP

Definitely NOT. Without addressing the question of HOW Python came by the
idea of using indentation to indicate block structure, it clearly couldn''t
have been from Fortran, because what Python does and what Fortran does
are COMPLETELY different.
Very true, but to say that FORTRAN and Python have nothing in common would
also be untrue. They both use ws to delimit syntatic elements, not the same
elements but use it in a very different way to most other languages.

I admit that Python probley gained no insiration from FORTRAN and any
''similarities'' are coincidental.
There''s also the fact that "lines" (statements) are defined by line breaks
in Python -- but I rarely hear complaints about this, since most programmers mentally chunk up code into "lines" anyway.
No complaints there
Of course, I''m not suggesting that whitespace is *meaningless* in Python
outside of indentation...



should hope not

Please dont misinterprit my post as an attack on Python, whilst Im a old-hat
C++ programmer and first time I looked at Pythno I thought... urggh, no
brackets thats horrid. After a bit better look, I love it. Like everything
it has its place.

Sorry if I upset anyone... I know FORTRAN''s bad, but its not that bad...
erm, actually mabe it is ?

As for OCCAM, I havent programmed in that for years, that was fun *lost in
fond memories*

Rich


Mark Jackson wrote:


Michael Chermside <mc****@mcherm.com> writes:

Of course, I''m not suggesting that whitespace is *meaningless* in Python
outside of indentation... Python is much like C (and many, many others) in
that regard.



Note that Fortran (at least historic Fortran - not sure about those
upstart 9x variants) is *not* among the "many, many others." One can
write any of

DO 10 I = something
DO10I = something
D O 1 0 I = something

and leave it to the compiler to figure out whether you''re starting a
DO-loop or assigning a value to the variable DO10I.



If you are saying that you leave it up to the compiler to decide how
to interpret any of the three above statements, then clearly whitespace
is *not* meaningless. It might be compiler-dependent or something,
but no meaningless. Unless you are saying that on a given FORTRAN
compiler, only one possible interpretation of all three statements
above is possible. That would be surprising.

-Peter


这篇关于Python测验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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