473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python Quiz

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.
Jul 18 '05 #1
11 6334
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

Jul 18 '05 #2
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

Jul 18 '05 #3
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
Jul 18 '05 #4
In article <3F***************@engcorp.com>, Peter Hansen wrote:
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.


IIRC (it's been a _long_ time) it's not up to the compiler. All
three of the above are required to be treated the same by the
compiler (a DO loop).
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.
I don't think it's "on a given FORTRAN compiler", I think it's
more like "according to the language definition for FORTRAN IV".
That would be surprising.


Yup. I found a lot of things in FORTRAN surprising. Python is
so much nicer in that respect. Though I was recently surprised
that the remove() method for lists uses "==" and not "is" to
determine what to remove. It's documented that it works that
way. But, it wasn't what I excpected, and it took me a while to
figure out that it was using my class's __cmp__ method rather
than the object ID.

--
Grant Edwards grante Yow! Go on, EMOTE! I
at was RAISED on thought
visi.com balloons!!
Jul 18 '05 #5
Grant Edwards wrote:

Though I was recently surprised
that the remove() method for lists uses "==" and not "is" to
determine what to remove. It's documented that it works that
way. But, it wasn't what I excpected, and it took me a while to
figure out that it was using my class's __cmp__ method rather
than the object ID.


Probably a very good thing, considering what would happen if
you were trying to remove strings from the list, rather than
simple things like integers...

-Peter
Jul 18 '05 #6
Peter Hansen <pe***@engcorp.com> writes:
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.


You misunderstand, probably because I didn't express myself clearly.
Again from the Sun Fortran Reference Manual, "Special characters used
for punctuation," after the graphic used in the manual for the space
character: "Ignored in statements, except as part of a character
constant."

Ignored means *ignored*, the three examples given will be parsed
identically and the meaning will be determined using other
information. I think in this case the nature of "something" should be
determinative, as the syntax for the range and stride of a DO-loop

start, stop [,stride]

doesn't match any legal expression (which is what would be required if
this were assignment to the variable DO10I.

But it's perfectly legal, if insane, to declare (or, with implicit
typing undefeated, just go ahead and use) a variable named DO10I and
write, say

DO 10 I = 1.10

because in Fortran whitespace is *not* considered to delimit tokens.

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
It is necessary to be slightly underemployed if you want to
do something significant. - James D. Watson
Jul 18 '05 #7
In article <3F***************@engcorp.com>, Peter Hansen wrote:
Though I was recently surprised that the remove() method for
lists uses "==" and not "is" to determine what to remove. It's
documented that it works that way. But, it wasn't what I
excpected, and it took me a while to figure out that it was
using my class's __cmp__ method rather than the object ID.


Probably a very good thing, considering what would happen if
you were trying to remove strings from the list, rather than
simple things like integers...


I didn't mean to imply that the way it's done isn't a good
idea, or that what I expected wasn't a bad idea. It's just
novel to be surprised by Python -- which wasn't the case with
FORTRAN.

--
Grant Edwards grante Yow! My nose feels like a
at bad Ronald Reagan movie...
visi.com
Jul 18 '05 #8
> I admit that Python probley gained no insiration from FORTRAN and any
'similarities' are coincidental.


Didn't FORTRAN popularise the idea of having
the language separate from tons of special purpose
libraries?
Raymond Hettinger
Jul 18 '05 #9

"Grant Edwards" <gr****@visi.com> wrote in message
news:3f*********************@newsreader.visi.com.. .
Yup. I found a lot of things in FORTRAN surprising. Python is
so much nicer in that respect. Though I was recently surprised
that the remove() method for lists uses "==" and not "is" to
determine what to remove. It's documented that it works that
way. But, it wasn't what I excpected, and it took me a while to
figure out that it was using my class's __cmp__ method rather
than the object ID.


Given ints = [9, 99, 999, 9999] would it not surprise you even more if
ints.remove(99) worked and ints.remove(999) did not, or even worse, if
the behavior of ints.remove(99) depended on the implementation?
(Similar examples apply to strings, where the implementation of
interning and hence behavior based on identity *has* changed!)

Terry
Jul 18 '05 #10
Michael Chermside fed this fish to the penguins on Wednesday 16 July
2003 05:47 am:
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.

When it comes to FORTRAN, other than the reserved columns for branch
label, continuation, and "sequence number", FORTRAN totally IGNORES
white-space...

D O 1 0I=1, 3 0, 2
and
DO 10 I = 1, 30, 2

are IDENTICAL to a FORTRAN compiler.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #11
Grant Edwards fed this fish to the penguins on Wednesday 16 July 2003
08:15 am:


IIRC (it's been a _long_ time) it's not up to the compiler. All
three of the above are required to be treated the same by the
compiler (a DO loop).
It depends on the "something"

DO10I=1.3 is an assignment
DO10I=1,3 is a DO loop. And the compiler can't tell
the difference until it reaches the . or , (and if it guessed wrong, it
has to backtrack to the beginning of the statement and reparse).

Spacing, however, is not signicant.

D O10 I = 1 . 3 is valid for the first one.
D O10 I = 1 , 3 is identical to the second above.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: stefanogaburri | last post by:
This is crossposted to comp.lang.python & comp.multimedia; if there is a better place to go please tell me :) I've been asked to build a quick-and-dirty prototype of a simple computer-based...
39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am...
4
by: Simon Brunning | last post by:
QOTW: "If you're sick of answering newbie questions, and don't think you can do so politely, for the sake of the community, DON'T! You're not that necessary." - Joal Heagney "Who controls the...
2
by: Sketcher | last post by:
Hi, I am trying to create a quiz, Code is as follows: <html> <head> <title>Quiz</title> </head> <BODY> <Center><TABLE cellSpacing=3 cellPadding=0 border=0>
5
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
2
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page...
0
NoPeasHear
by: NoPeasHear | last post by:
I don't know what I am doing wrong... I used this tutorial... http://www.permadi.com/tutorial/flashMXQuiz/index.html It works with their quiz.xml file, but when I add an option for multiple...
3
by: empiresolutions | last post by:
I am building a app that creates quizzes. This is how it goes - - Create Quiz - Provide up to 10 different types of Quiz Results - Give up to 50 Questions - Each Question has up to 10 possible...
19
by: John Salerno | last post by:
Hey all. Just thought I'd ask a general question for my own interest. Every time I think of something I might do in Python, it usually involves creating a GUI interface, so I was wondering what kind...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.