replacing `else` with `then` in `for` and `try`

Ned Batchelder ned at nedbatchelder.com
Wed Nov 1 17:23:34 EDT 2017


On 11/1/17 5:12 PM, Alexey Muranov wrote:
> Hello,
>
> what do you think about the idea of replacing "`else`" with "`then`" 
> in the contexts of `for` and `try`?
>
> It seems clear that it should be rather "then" than "else." Compare 
> also "try ... then ... finally" with "try ... else ... finally".
>
> Currently, with "else", it is almost impossible to guess the meaning 
> without looking into the documentation.
>
> Off course, it should not be changed in Python 3, maybe in Python 4 or 
> 5, but in Python 3 `then` could be an alias of `else` in these contexts.
>
> Alexey.
>

Apart from the questions of backward compatibility etc (Python is 
unlikely to ever go through another shift like the 2/3 breakage), are 
you sure "then" is what you mean?  This won't print "end":

     for i in range(10):
         print(i)
     else:
         print(end)

--Ned.



More information about the Python-list mailing list