Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56549
| Date | 2013-10-09 23:46 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Python's and and Pythons or |
| References | <91180c35-413f-4b65-a224-917d8d68b7ec@googlegroups.com> <a471eecd-2e9f-4d32-8825-bdc088a0ecb0@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.926.1381388936.18130.python-list@python.org> (permalink) |
On 10/09/2013 11:12 PM, Peter Cacioppi wrote:
>
> I'm trying to think of a good example usage of echo-argument and. Maybe something like
>
> possible = foo and foo.allowsit()
> if (possible is None) :
> print "foo not provided"
> if (possible is False) :
> print "foo doesn't allow it"
>
> A bit awkward, echo-argument or is more naturally useful to me then echo-argument and.
It's used as a guard:
if some_list and some_list[0] == something_or_other:
do some_work()
Without the 'some_list and' portion when some_list was either empty or, say, None, the some_list[0] would fail with an
error (IndexError, TypeError, etc.).
--
~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 16:54 -0700
Re: Python's and and Pythons or Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-10 00:36 +0000
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 12:13 +1100
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:12 -0700
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 17:45 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-09 23:46 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 03:43 -0400
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 19:03 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 06:33 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 21:41 -0400
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 19:47 -0700
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:55 -0700
csiph-web