[Python-Dev] extended if and while statements
python at rcn.com
Tue Jan 27 23:07:42 EST 2004
> if book_count() ..
> == 1: purchase_9_books()
> == 2: purchase_8_books()
> < 5: purchase_5_books()
When the action clause is listed on a separate line (as it should be)
as it must be for multi-line blocks, the result is not as pretty
and shows that an additional level of indentation is required with
almost no pay-off:
if book_count() ..
I don't see this as a win over the following equivalent:
> nBooks = book_count()
> if nBooks == 1:
> elif nBooks == 2:
> elif nBooks < 5:
I recommend teasing out the idea on comp.lang.python.
There will be no shortage of criticisms on every possible
variation. There have been many suggestions for a switch
statement and a couple of them were elegant and pythonic.
Here is one variant:
case < 5:
Here is a link to one of the many threads on ideas for
python switch-case statements:
More information about the Python-Dev