On Sat, 20 Jun 2020 at 04:02, MRAB <[email protected]> wrote:
> On 2020-06-20 02:22, Robert DeLanghe wrote:
> > You can already do compact conditional returns with the current syntax:
> >
> > def foo(a, b):
> > return (a != b or None) and a * b
> >
> >
> > or even:
> >
> > foo = (lambda a, b: (a != b or None) and a * b)
> >
> > both return:
> >
> >
> > foo(2, 5) # 10
> > foo(1, 1) # None
> >
> >
> > ... but clarity would be better.
> >
> That can be written more clearly:
>
> def foo(a, b):
> return a * b if a != b else None
I find the non-compact version to be clearer:
def foo(a, b):
if a != b:
return a*b
return None
>
>
> >
> >
> > On Fri, Jun 19, 2020 at 4:20 AM Serhiy Storchaka <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> > 18.06.20 15:30, Daniel. пише:
> > > I love the do_stuff if cond syntax in Ruby and in perl. It's very
> > > natural to real, much more to follow than if cond: do_stuff
> > >
> > > But still I don't think that it is enough to demand a language
> > change.
> > >
> > > Something near this is to have a default of none for
> > >
> > > A if B else None
> > >
> > > So we can ommit the else None part, but this goes against the
> > explicit
> > > is better than implicit
> >
> > Only around 10% of "if" expressions have "else None" part. It is not
> > enough to justify a new syntax (even if ignore other objections).
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/J7TH3N76S6C7CITCYCJWI76Y2F6DHPGF/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/TG46SCE4VOG5E5QGNOAII27SDWC4EXT3/
Code of Conduct: http://python.org/psf/codeofconduct/