What values are considered false?

Erik Max Francis max at alcyone.com
Wed Feb 20 22:09:56 EST 2002


Jason wrote:

> In my experimentation 0, None, "", [], and () all seem to be
> considered false.  Just to confound me none of them are == to each
> other.  Coming from a Scheme world this is confusing.  Are there any
> other values that are false?

Sure.  There's also 0l, 0.0, and any class which has had its __nonzero__
method overridden to return false at times.  Many languages (other than
Scheme) have a loose definition of truth and falsity, simply because at
times it's useful to be able to test any object for truth.  That's true
in Scheme too, except that in Scheme the only false value is #f*. 
That's the way Scheme works, but it's not universal.

> Why aren't () and "" the same thing?
> Don't both describe an immutable sequence of values (basically, why
> aren't strings either lists or tuples)?

Strings, lists, and tuples are sequences, but they're not the same
thing.  'abc' is distinct from ['a', 'b', 'c'], which is distinct from
('a', 'b', 'c').

. 

* And, of course, the empty list (), should you be running on a system
where #f and () are identical.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list