how to stop a function execution like...

Dave Angel davea at ieee.org
Tue Jun 16 09:29:28 EDT 2009


Gaudha wrote:
> On Jun 16, 4:45 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>   
>> Gaudha wrote:
>>     
>>> Is there any built-in function to stop execution of a function similar
>>> to stop the program execution by sys.exit?
>>> In the example below, I want to skip statement 2... if the 'if'
>>> condition is satisfied.
>>> Don't advice me to put statement 2 in 'else' block. That's not my
>>> intention.
>>>       
>> Why not? It's from all you tell us perfectly the right thing to do.
>>
>>     
>>> May be this a simple task. Sorry to say I'm novice in Python,
>>> gentlemen...
>>>       
>>> def funct :
>>>     if (.....) : statement 1
>>>     statement 2
>>>       
>> def funct():
>>     if ...:
>>        statement 1
>>        return
>>     statement 2
>>
>> would also work. But it is not really "better" than using else.
>>
>> Diez
>>     
>
> I considered 'return' as meant only for returning any value. Thank you
> sir...
>
>   
return with no arguments will return a value of None, same as falling 
off the end of the function.  That can be important to know, as the 
caller can therefore test for None.




More information about the Python-list mailing list