Why the colon?
Erv Young
res04ft9 at gte.net
Fri Jun 28 19:33:31 EDT 2002
I've come a long way, baby! Four days ago, I posted an inquiry on a MS
Developer mailing list, to the following effect: "How do I get MS Visual
C++ 6.0 to act like good old non-visual, nonplussed (forgive me) plain old
C?" and got back a response to the effect that I should forget C and use
Perl. And now here I am, having read the entire thread "Python vs. Perl:
which one to learn?" and having identified the pieces of Python that I need
for the job at hand. I will omit several intermediate steps on the journey.
But I have a question. Let me set it in the context of the first code
snippet in section 4.7.1
(http://www.python.org/doc/current/tut/node6.html#SECTION006710000000000000000)
of the on-line tutorial
1. def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
2. while 1:
3. ok = raw_input(prompt)
4. if ok in ('y', 'ye', 'yes'): return 1
5. if ok in ('n', 'no', 'nop', 'nope'): return 0
6. retries = retries - 1
7. if retries < 0: raise IOError, 'refusenik user'
8. print complaint
where I have added line numbers for the sake of the discussion. I
understand the colons in the middle of lines 4, 5, and 7 as statement
separators. Makes perfect sense.
Then what am I to make of the colons at the end of lines 1 and
2? "Yoo-hoo, interpreter! I'm about to start indenting now!" Hmmm....
Maybe one of you can help me understand this syntactic convention a little
better. An invitation to continue RTFM would be quite in order, if it were
accompanied by a specific URL or section number. (An invitation to read
the whole thing like a novel would be a bit un-Python-like, as near as I
can tell.)
Thanks.
--erv
More information about the Python-list
mailing list