syntax question - if 1:print 'a';else:print 'b'

Fredrik Lundh fredrik at pythonware.com
Wed Oct 26 18:24:01 EDT 2005


Gregory Piñero wrote:

> Any idea why I can't say:
>
> if 1:print 'a';else:print 'b'
>
> all in one line like that?

because ";" can only be used to separate simple statements, not
the different parts in a compound statement.

see the grammar for details:

    http://docs.python.org/ref/grammar.txt

(look for "compound_stmt", "suite", "statement", etc)

</F>






More information about the Python-list mailing list