[Tutor] Usefulness of BIFs all() and any()?

Dave Angel d at davea.name
Tue Sep 25 14:33:22 CEST 2012


On 09/25/2012 07:55 AM, Richard D. Moores wrote:
> <snip>
>
> And why
>>>> all([])
> True
>>>> any([])
> False
>
>

Same problem as calling sum() with an empty list.  What value should it
have?  Clearly, it should return its 'start' parameter, which defaults
to zero.

Well the all() has a start value of True, and ands that with each
element of the iterable till one of them ends up with false.  Similarly,
the any() has a start value of False.



-- 

DaveA



More information about the Tutor mailing list