A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-September/056547.html below:

[Python-Dev] "and" and "or" operators in Py3.0

[Python-Dev] "and" and "or" operators in Py3.0 [Python-Dev] "and" and "or" operators in Py3.0Skip Montanaro skip at pobox.com
Tue Sep 20 18:07:21 CEST 2005
Greg Ewing <greg.ewing <at> canterbury.ac.nz> writes:

> 
> Raymond Hettinger wrote:
> > I propose that in Py3.0, the "and" and "or" operators be simplified to
> > always return a Boolean value instead of returning the last evaluated
> > argument.
> 
> But then I would no longer be able to write
> 
>    foo = something or default_value
> 
> which is one of my favourite Pythonisms!

Same here.  I use this frequently.  In fact, I sometimes use it in preference
to a default param in {}.get():

    foo = somedict.get("blarg") or expensive_default()

That way the expensive default isn't calculated unless you need it.  (Of
course, the dict has to only store values that evaluate to non-False, which
might not be possible in all situations.)

Skip


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4