What is the ":" for in python?

I was asked why python required a ":" in its syntax and then saw Pete Shinners query on changing the parser to treat "def" to ":" as a unit. What is the purpose of the ":"? Why doesn't the parser work as Pete suggests already? Of course the same rules should be true of "if" and ":", "while" and ":" I've always wanted to be able to write: if x > 10 and x < 20: do_in_range() rather then if( x > 10 and x < 20 ): do_in_range() Barry

Barry Scott writes:
if x > 10 and x < 20: do_in_range()
rather then
if( x > 10 and x < 20 ): do_in_range()
You could write if x > 10 \ and x < 20: do_in_range() -- Tom Emerson Basis Technology Corp. Software Architect http://www.basistech.com "Beware the lollipop of mediocrity: lick it once and you suck forever"

At 27-02-2004 19:39, Tom Emerson wrote:
You could write
if x > 10 \ and x < 20: do_in_range()
I don't like using backslash line continuation. Too many ways to mess up, putting comments or white space after the \ may or may not work. And are the continuation rules the same of C and make or different? I cannot write: if x > 10 \ # check lower bound and x < 20: # check upper bound do_in_range() File "L:\Users\barry\a.py", line 2 if x > 10 \ # check lower bound ^ SyntaxError: invalid token Barry
participants (2)
-
Barry Scott
-
Tom Emerson