[ANSWERED] return call in decoration | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[ANSWERED] return call in decoration

Passing the Python 3 tutorial, I found this code and discovered that there is a return statement for a function. I got used to think that if we return something,it must be a value that can be assigned to a variable. Thus I remade the code in a way I like. What do we need to return a function for and how does it work exactly? https://code.sololearn.com/caayOMjfxPi4/#py https://code.sololearn.com/ciPxTQX5d5qG/#py

25th Sep 2017, 3:36 PM
Alex Snaidars
Alex Snaidars - avatar
1 Answer
+ 7
First of all, no, a defined function does not *have to* return anything. If it does, though, it kind of passes on the effect of its own execution to the rest of the code. In general, you define functions mostly for code optimization (Do Not Repeat Yourself). So if you plan to use it often in the code chances are high that you do some computations with it. And so, you probably do not want to retain the effect of this computation inside the function, but pass it on to a variable or make the behavior of the program dependent on the function evaluation. This is why in most cases functions return values :)
25th Sep 2017, 3:28 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar