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.
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.
Good that the above post came back around through the notification system so it can be corrected. At the time yours truly was fond of the argument that there is no return value. That changed somewhere along the way some months ago to a different and likely more correct stance on the None that the caller sees.
status return
* function has a return with a value => value
* function has a return with no value => None
* function has no explicit return => None
Consider the above in a conditional sense in which all cases result in a return value, whether real, or None.
Yes, and no. The result would be fleeting, and not usable by any part of the program. Only the user will see the outcome. The program will see nothing. With return the program would have access to the result for further use.
This isnât there in the lesson, but tried it anyways and got the result, in a different way (wrong according to the system of course).
def lots_of_math(a,b,c,d):
first= a + b
second= c - d
third= first * second
fourth= third % a
return first, second, third, fourth
As you can see, I returned all of the values, instead of just the fourth. Instead of the result being printed vertically, it got printed horizontally and that too in brackets. Like this-
Blockquote
(3, 1, 3, 0)
(2, 0, 0, 0)
Just how did that happen, when brackets didnât appear in the result when just fourth was returned.
why the code third = print(first * second) giving me a error âTypeError: unsupported operand type(s) for %: âNoneTypeâ and âintââ when i am doing third%a
The value assigned to third here is not the resolved value of the expression first * second. The value assigned is the return value of the print() function. Any guess what that might be? The answer is in your error message.