Why aren't colons optional?

Edward K. Ream edream at tds.net
Sat Jan 19 18:18:40 EST 2002


Hi all,

Why are colons required after def, elif, else, except, finally, for, if,
try and while?  One would think the colon would be optional when the
colon is followed by a newline.

Obviously, colons are required in:

  if a == 1 : b = c
  elif a == 2 : b = d
  else : b = e

My question is: why isn't the following valid?

  if a == 1
  	b = c
  elif a == 2
  	b = d
  else
  	b = e
  	
Can anyone provide an example of similar code that Python can't parse
without colons?  My apologies if this is a perennial question.
  
Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list