[Edu-sig] Why colon?

Jeff Sandys sandysj@asme.org
Thu, 14 Mar 2002 15:54:31 -0800 (PST)


What is the use of the colon in def and if?
It only seems to signal, indent the next line,
but if the next line is indented anyway, 
what is the colon's purpose?

We have a semi-colon to put multiple statements 
on a line, why not use that for a single-line if,

if x > 0 ; print "positive"
else ; print "negative"

Then when we use multiple lines we still indent,

if x > 0
    print "positive"
else
    print "negative"

It is a common error of new Python programmers 
to leave out the colon after def, if and else,
and I can't explain why the colon is needed.

Thanks,
Jeff Sandys



__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/