return boolean from functions

Preston Landers prestonlanders at my-deja.com
Thu Nov 4 22:56:33 CET 1999


Is this not what you want?

def foo(bar):
   if bar == "spam":
      return 1
   else:
      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:

TRUE=1
FALSE=0

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

hope this helps,

---Preston

In article <7vrq9b$hmr$1 at nnrp1.deja.com>,
  a_olme at my-deja.com 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 Deja.com http://www.deja.com/
> Before you buy.
>

--
|| Preston Landers <prestonlanders at my-deja.com> ||


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list