Does a function always have to use a variable for the return?


#1

Question

In this exercise, the variable fourth is used only for the return statement. Does return require a variable?

Answer

NO. The return does not require a variable. The computation done and assigned to the variable fourth could have just been done on the return line since it is not used for a print() statement in the function. If the results were used for more than the return, then assigning the result to a variable is helpful.


#2
>>> def foo():
	pass

>>> print (foo())
None
>>> def foo():
	return

>>> print (foo())
None
>>> print (print(''))

None
>>> 

In all the above the return value is not defined, hence, None. This is not a return value, but what the caller sees. The console on occasion will echo that response when print is that last instruction/command.