Implicit conversion to boolean in if and while statements

Chris Angelico rosuav at gmail.com
Mon Jul 16 04:58:40 CEST 2012


On Mon, Jul 16, 2012 at 12:41 PM, Ranting Rick
<rantingrickjohnson at gmail.com> wrote:
> On Jul 15, 9:13 pm, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
>
>> I have just written a bunch of code with about two dozen examples similar
>> to this:
>>
>> for item in (seq or []):
>>     do_something_with(item)
>
> Short circuitry is a powerful tool! But why the heck would your
> sequences ever be None? Are you using None as a default? And if so,
> why not use an empty sequence instead ([], {}, "")?

Function default arguments spring to mind, especially if the list will
be mutated afterwards.

ChrisA



More information about the Python-list mailing list