Postfix conditionals

Göktuğ Kayaalp self at gkayaalp.com
Sun Jan 5 15:24:53 EST 2014


Hi,

AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition 
appended to a
statement, which determines whether the statement runs or not:

   py> for i in [False]:
   ...     break if not i

The above piece of code is equivalent to this in Python:

   py> for i in [False]:
   ...    if not i
   ...        break

I believe that the first example is superior to the second example when 
the two is compared
for readability and intuitiveness.  We already have a ternary statement 
that looks similar,

   py> print('hi') if True else None

so I reckon there would be no breakage in old code if this kind of 
syntax was added.  Ruby has
this, and AFAIK Perl also does.

I lack the knowledge of whether the community has opinions on this kind 
of notation, so I am
posting this here instead of the ideas list.  What are your thoughts on 
this?

         gk




More information about the Python-list mailing list