Proposed PEP for a Conditional Expression

thp at thp at
Fri Sep 14 19:39:14 CEST 2001

Pete Shinners <pete at> 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()


   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