Before We Begin - return True


#1

In the first part of Taking a Vacation, Before We Begin, why does the example function return True?

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


#2

It’s likely that author wanted to demonstrate return. There is no practical reason other than that.

Try the code in your lesson space, calling it with a print statement…

print (bigger(42, 24))

#3

Thanks mtf. I put in the function into IDLE and printed the result of calling the function, and the result was:

42
True

I also tried removing the return part from the function and the result was:

42
None

So a function always needs to return some sort of value?


#4

Function calls are expressions and expressions evaluate to values, so yes, there has to be a result when calling a function. If you do not explicitly specify a value, None will be returned (representing lack of value)


#5

Thank you for clearing that up ionatan. Seems to be a fundamental concept. I will keep this in mind as I continue. Much appreciated.


#6

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