Interesting list Validity (True/False)

Grant Edwards grante at visi.com
Fri May 11 16:32:00 EDT 2007


On Fri, May 11, 2007 at 01:20:44PM -0700, nufuhsus at gmail.com
wrote:
> On May 11, 3:55 pm, Grant Edwards <gra... at visi.com> wrote:
> > You got those results because that's what your program does.
> >
> > Were you intending it to do something else?  If so, you're
> > going to have to explain what you wanted, because we can't

> According to my output, it seems that arg is False even when I
> give an option of '-o' which according to the book should be
> True. No?

'-o' is not equal to True.  However, that does not mean it
evaluates to false when tested by an if or while statement.

> If arg == ['-o'] then shouldn't arg == True return True and
> skip the if?

No.  See the folloing link regarding the "truth value" of an
object:

http://docs.python.org/lib/truth.html

There are many objects other than True that evaluate to "true"
in the context of an if/while statement.  Just because an
objecty has a "true" truth-value doesn't mean that it is equal
to the True object.

-- 
Grant Edwards                   grante             Yow! Why don't you ever
                                  at               enter any CONTESTS,
                               visi.com            Marvin??  Don't you know
                                                   your own ZIPCODE?



More information about the Python-list mailing list