Why the colon?

Roger roger at efn.org
Sat Jun 29 01:58:12 CEST 2002


Around Fri,Jun 28 2002, at 07:33,  Erv Young, wrote:
> 
> 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
> 
> 
> 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....
> 

http://python.org/doc/current/tut/node5.html
section 3.2

essentially,

while  1:   # : indicates beginning of a block of code
   line a
   line b
   line c
line d

there is no 'end' statement.  Quit indenting when you want the block to
end.  lines a,b and c will be executed for the 'while' loop.


-- 
Roger
---------------------------------------------------------------------------





More information about the Python-list mailing list