Return Statement
Ethan Furman
ethan at stoneleaf.us
Thu Jan 27 18:11:49 EST 2011
mpnordland wrote:
> On 01/26/2011 03:26 PM, sl33k_ wrote:
>> How does "return True" and "return False" affect the execution of the
>> calling function?
>
> Basically it will affect it in whatever way you design it to for example:
> def lie_test(statement):
> if statement is True:
> return False
> else:
> return False
> Now, this is psuedo code somewhat.
> "if statement is True:" would always equate to "True" unless statement
> was an empty string, None, or 0.
Um, no.
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
--> if 'some stuff' is True:
... print 'True'
... else:
... print "it's a dang lie!"
...
it's a dang lie!
You need either < if bool(statement) is True: >, or
< if bool(statement): >, or, simplest,
< if statement: >
> As to return False if statement equals
> true, look at the function name. It is testing to see if it is a lie,
> and if it is true, then it's not a lie.
Your last statement, though, should be return True -- the way you have
it now the function always returns False.
~Ethan~
More information about the Python-list
mailing list