On Thu, 20 Jul 2023 at 17:09, Dom Grigonis <dom.grigo...@gmail.com> wrote:
>
> On 20 Jul 2023, at 09:48, anthony.flury <anthony.fl...@btinternet.com> wrote:
> In Python then a better way might be
>
> result = temp := bar() if temp else default
>
> This way only bar() and default are evaluated and invoked once.
>

I presume you want a more complicated expression than just "if temp",
since this is no better than "bar() or default". But if you DO want
some other condition, this would be how you'd write it:

result = temp if (temp := bar()) is None else default

Or, better:

result = bar()
if result is None: result = default

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FI376QAZ7FAA7ZFJPELG73LXR5VFIHBD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to