Re: any() and all() on empty list?
Ron Adam wrote:[color=blue]
> Carl Banks wrote:
>[color=green]
> > In Python, yes and no are the only possible answers. Probably the only
> > analogous thing you could do in Python would be for all() to raise
> > ValueError when passed an empty sequence.[/color]
>
> There is also 'None' which serves a similar purpose of indicating an
> invalid value when passing arguments.[/color]
If all() were to return None, then if would essentially be like
returning False, because an if-statement would treat False and None the
same (as would most anything else expecting a boolean value).
The only reasonable way to say "false assumption" in Python is to raise
an exception.
Carl Banks
Ron Adam wrote:[color=blue]
> Carl Banks wrote:
>[color=green]
> > In Python, yes and no are the only possible answers. Probably the only
> > analogous thing you could do in Python would be for all() to raise
> > ValueError when passed an empty sequence.[/color]
>
> There is also 'None' which serves a similar purpose of indicating an
> invalid value when passing arguments.[/color]
If all() were to return None, then if would essentially be like
returning False, because an if-statement would treat False and None the
same (as would most anything else expecting a boolean value).
The only reasonable way to say "false assumption" in Python is to raise
an exception.
Carl Banks
Comment