Why does list have no 'get' method?
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Feb 7 13:33:18 CET 2008
bearophileHUGS at lycos.com a écrit :
> Steven D'Aprano:
>> With the greatest respect, I think that if you think the second example
>> "is more clear", you're completely bonkers. *grins*
> No one is completely normal, I presume :-)
> I'd like to know what others think about it, about this anti-feature.
> What I can say is that other computer languages too think that boolean
> operations must return boolean values only,
Not quite. In C and a couple other langages, int 0 is false, anything
else is true. In Lisp (and IIRC), an empty list is false, anything else
is true. I'm sure someone else could come with more than a couple other
non-cryptic langages that just don't have a proper boolean type.
Using "emptyness" as a false value in boolean expressions is not that
uncommon, and it has proven so far to be a working solution. Also,
returning the tested object instead of a bool just makes sens to me.
FWIW, booleans are a late addition to Python, and quite a couple persons
where worried that it would only lead to confusion.
More information about the Python-list