0
Why do Def programs use return instead of print?
edit: Thank you for the answers! I understand after reading them and playing with it a while.
4 Antworten
+ 4
it use to send data to a new variable where you need that, and suppose you want to use some function that use to get some unique string from a file, and than want to store that string in MySQL.
If you don't use return value, than you have to write it again and again. Writing function for a particular job increase your programing performance.
0
Sometimes you need to use the answer of a def for something instead of printing. It is much more flexible. A very common way is to set it to a variable in instead of printing.
0
Err. Imagine having to type every single result for every single calculation, and compare it with the flexibility of functions. Not even close to being comfortable.
0
use return when you need to asign the result of the function to a variable
def max(a,b):
if a>b:
return a
return b
nMax=max(2,3)
print(nMax) #prints 3