why it is invalid syntax?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Nov 22 01:47:33 EST 2007
On Thu, 22 Nov 2007 00:00:16 -0600, alf wrote:
> I wonder why it is an invalid syntax:
>
>
> >>> if 1: if 1: if 1: print 1
> File "<stdin>", line 1
> if 1: if 1: if 1: print 1
>
> or
>
> >>> if 1: for i in range(10): print i
> File "<stdin>", line 1
> if 1: for i in range(10): print i
>
> I would expect one could nest :
It's quite unreadable and if this would be allowed you would have to
introduce a special rule to forbid ``else``, ``except`` and ``finally``
because it can lead to ambiguities. To which ``if`` does the ``else``
belong to here? ::
if 1: print 1 if: 1 print 1 else: print 1
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list