[FRPythoneers] Python documentation and default expression

Jason Songhurst Jason.Songhurst at valtech.com
Fri Mar 15 15:01:51 MST 2002


in the python language reference:
(http://www.python.org/doc/current/ref/lambda.html)

   In the context of Boolean operations, and also when expressions are
   used by control flow statements, the following values are interpreted
   as false: None, numeric zero of all types, empty sequences (strings,
   tuples and lists), and empty mappings (dictionaries). All other values
   are interpreted as true.

so, your len() returned 0, and was considered false.

you might try:

     if foo is not None: ...

if you just wish to test for the None object.


Rob Riggs wrote:
> Where do I find Pythons rules for the default tests on a variable? I.e., 
> when I have an expressions like:
> 
>    if foo: ...
> 
> what are the tests on "foo" that are performed? Is this documented in 
> the language reference anywhere?
> 
> Along the same lines, what are the thoughts on using this type of test 
> in code? The reason I ask is that I was just burned on a test like this 
> when I extended a class to include a __len__() member function. What I 
> really wanted to test was that the class wasn't "None", and using the 
> above idiom worked well for that. At least it did until I added __len__().
> 
> -Rob





More information about the FRPythoneers mailing list