0

Can any one help me with understanding return operator

29th May 2017, 12:56 AM
MADRIDISTA 2133
MADRIDISTA 2133 - avatar
2 Answers
+ 2
return is what you get back. say you have a function def add(x,y): a=x+y return a if I call this function with add(4,5) It sets x to 4, y to 5.. Then it sets a to 4+5.. which is 9.. and it returns a. so, it returns 9. sum=add(4,2) This would set the variable sum to 6 because add(4,2) returns 6 Does this help?
29th May 2017, 1:04 AM
LordHill
LordHill - avatar
0
the return will return the value witch is next to it and end the function so if my function has return 5 that function will return the number 5 and end itself the return is more used to end the function if it does not need to continu running exemple def add(x,y,op): if op=='+': a=x+y return a if op=='-': a=x-y return a print('the answer is '+a) in this example if i call w=add(5,6,'+') then the function will return 11 and exit without continuing)the execution it will not print the answer is 11 becoze the return statement forced the function to calculate and return the value and then to exit without reaching)the bottom line witch is the print
29th May 2017, 1:36 AM
fouzai alaa
fouzai alaa - avatar