Interesting list Validity (True/False)

Rob Williscroft rtw at freenet.co.uk
Fri May 11 17:25:39 EDT 2007


 wrote in news:1178911704.529457.292280 at e51g2000hsg.googlegroups.com in 
comp.lang.python:

>     >>> [] == []
>     True
>     >>> ['-o'] == []
>     False
>     >>> ['-o'] == False
>     False
>     >>>

To test wether something is true use if.
To test wether something is false use if not.

The python values "True" and "False" are for when you need to 
*store* a boolean value (for later testing).

I you want to to see if an arbitry expression would test as true
or false at the interactive prompt use bool():

>>> bool([])
False
>>> bool(['-o'])
True
>>> 

There is *never* any need to write things like:

    	expression == True

or:
    	expression == False

Once you stop doing this things will become much simpler.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list