Proposed PEP for a Conditional Expression

thp at cs.ucr.edu thp at cs.ucr.edu
Fri Sep 14 13:39:14 EDT 2001


Pete Shinners <pete at visionart.com> wrote:
:>> <condition> if <expression a> else <expression>
:> 
:> But that appears to NOT scan like English.
:> "one if by land two if by sea"

: num_rings = 1 if enemy.onland() else 2

: not the most graceful english, heh. and i suppose
: it works if they are nested..

: num_rings = 1 if onland() else 2 if onsea() else 3

To fully reflect the "one if by land, two if by sea" construct of
English, we need to adopt the implicit "else None" idea.  Then

   1 if by_land() else 2 if by_sea()

means

   1 if by_land() else 2 if by_sea() else None

which is what the corresponding english means.

Tom Payne



More information about the Python-list mailing list