Python Grammar (was Re: A TYPICAL NEWBIE MISTAKE?)
Andrew Dalke
dalke at acm.org
Tue May 16 05:54:57 EDT 2000
Dirck:
>> Theoretically, a colon is only necessary in things like
>>
>> if yes: print "yes"
Moshe Zadka:
>Oddly enough, the parser doesn't really need the colon here either.
>It can manage to figure out where the if expression ends without it.
>
>The colon is almost entirely for readability purposes.
>(there are a couple of places where ambiguity occurs without it).
Oh, oh! I've got one!
Is "if 1 - 1 - 2" the same as
"if 1: -1 - 2" or
"if 1-1: -2" or
"if 1-1-2:"
?
Toss in some overflow exceptions past sys.maxint if you want to prove
that a good compiler won't optimize them away :)
Another is:
if "spam" " eggs" " viking"
which, because of string joining during parsing, becomes:
if "spam eggs viking"
instead of one of:
if "spam": " eggs viking"
if "spam eggs": " viking"
Andrew
dalke at acm.org
More information about the Python-list
mailing list