Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38414
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-07 22:22 -0800 |
| References | (8 earlier) <5004ec84$0$11116$c3e8da3@news.astraweb.com> <mailman.2201.1342502395.4697.python-list@python.org> <50050f70$0$30002$c3e8da3$5496439d@news.astraweb.com> <mailman.2203.1342513414.4697.python-list@python.org> <21fcdb92-20e3-428b-b06b-057065a4ab25@oo8g2000pbc.googlegroups.com> |
| Message-ID | <70f6350c-556a-4329-a2aa-a568e91756da@googlegroups.com> (permalink) |
| Subject | Re: Implicit conversion to boolean in if and while statements |
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
On Tuesday, July 17, 2012 8:35:09 PM UTC-5, alex23 wrote:
> On Jul 17, 6:23 pm, Andrew Berg <bahamutzero8...@gmail.com> wrote:
>
> > On 7/17/2012 2:08 AM, Steven D'Aprano wrote:
>
> > > The default behaviour is that every object is something, hence true-like,
>
> > > unless explicitly coded to be treated as false-like. Since both loggers
>
> > > and functions are objects, they are true-like unless the default is
>
> > > overridden.
>
> >
>
> > I am aware of the default behavior, but the reason for it still eludes me.
>
>
>
> Because it makes it simple to distinguish between having an object and
>
> not having one without having to explicitly test for it each time.
>
>
>
> db = connect("my:db") # or None if the connection failed
>
> if db:
>
> <do something>
>
>
>
> I find that usage to be incredibly intuitive.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Implicit conversion to boolean in if and while statements Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-07 22:22 -0800
csiph-web