return boolean from functions

Preston Landers prestonlanders at
Thu Nov 4 22:56:33 CET 1999

Is this not what you want?

def foo(bar):
   if bar == "spam":
      return 1
      return None

if foo("spam"):
   print "We have spam!"

As you can see, the return value of foo() is evaluated in a true-false
sense by the if statement.  So, return None or 0 when you mean false,
or return 1 or virtually anything else when you mean true.

Alternatively, you can do this:


def foo(bar):
  if bar == "spam":
     return TRUE
     return FALSE

hope this helps,


In article <7vrq9b$hmr$1 at>,
  a_olme at wrote:
> Hello.
> Is it possible to return booelan from functions other than return 1==1
> for true or return 1==2 for false?
> //Anders Olme
> Sent via
> Before you buy.

|| Preston Landers <prestonlanders at> ||

Sent via
Before you buy.

More information about the Python-list mailing list