Return function


In the first lesson of Taking Vacation, the example goes:

def bigger(first, second):
print max(first, second)
return True

When do I need the _return_function? Can I not just print out max from the second line?


return isn’t a function, it causes the current function to exit, optionally passing a value back to the caller

printing is often not very useful, for example, if you had a function which doubled a number, you might want to use it to quadruple too, by calling it twice:


which you can’t do if you’re printing the result (your program doesn’t read what it wrote) – or if it both prints and returns then you’ll have a bunch of spam in the output

so a function needs to return its result to be useful, and printing is probably not part of its purpose (unwanted side-effect)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.