[Tutor] Another assert() question
rdm at rcblue.com
Sun Jul 13 21:50:19 CEST 2008
At 12:40 PM 7/13/2008, Martin Walsh wrote:
>Dick Moores wrote:
> > At 11:44 AM 7/13/2008, Steve Willoughby wrote:
> >> Dick Moores wrote:
> >>> Yes! A rule, not logic. I'm not contradicting Kent, just helping
> >>> myself understand. First the rule, then logic in the application of
> >>> the rule. And I assume the rule is there in Python because it makes
> >>> things work better.
> >> Yes, so a statement like "if foo:" becomes an idiom for "if the
> >> collection foo has stuff in it:" which is handy whether foo is a text
> >> string or a list of objects.
> > Yes, I've been using that, a bit uneasily.
> > One question about the data I listed. Why is bool(set()) false,
> > whereas bool([]) is true?
>In the first example you're passing an empty list to the set
>constructor, and getting back an empty set object. In the second, you're
>providing a list with one element, which just so happens to be an empty
>list, but it doesn't matter -- since the outer list is not empty.
>Perhaps a better comparison would be bool(list()) => False.
My thanks to you and to Marcel Wunderlich, for helping me understand
why bool(set()) is false. You guys are good!
More information about the Tutor