[Tutor] No return statement

Alan Gauld alan.gauld at btinternet.com
Tue Apr 24 20:05:59 CEST 2007

"Cecilia Alm" <ebbaalm at uiuc.edu> wrote

> functions which lack a return statement ('procedures') actually 
> return "None".
> For such functions, I assume it's preferred to not catch "None" in a 
> variable.

You can catch it if you like, but since functions with no return
*always* return None there is little point. You know what the
value will be before you even call the function.

Where catching the value is more important is where the function
only has some return statements:

def f(x):
   if x: return 42

Now f() returns None if x is not True so it makers sense to
catch the reurn value and test for None.

But such a function style is very bad practice IMHO!

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list