Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63220

Postfix conditionals

Date 2014-01-05 22:24 +0200
From Göktuğ Kayaalp <self@gkayaalp.com>
Subject Postfix conditionals
Newsgroups comp.lang.python
Message-ID <mailman.4966.1388953508.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:24 +0200
  Re: Postfix conditionals Roy Smith <roy@panix.com> - 2014-01-05 15:41 -0500
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:54 +0200
    Re: Postfix conditionals Dan Stromberg <drsalists@gmail.com> - 2014-01-05 13:08 -0800
  Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-06 01:40 +0000
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-06 09:51 +0200
      Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-07 00:48 +0000
  Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-03 23:43 +0000
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-02-04 07:16 +0200
      Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-04 10:00 +0000
    Re: Postfix conditionals Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:23 +1100

csiph-web