+ 1

Urgent: When exactly does return end a function? (Python).

Please take a look at Module 5 Quiz Question 2 & 5 and kindly explain the difference between their use of 'return'.

7th Mar 2018, 2:28 PM
Msizi
5 Answers
+ 1
Module 5 in which course? Generally return has two uses: 1) premature termination. 2) passing data back to the calling function. If return is used to terminate a functions execution, no code following the return statement within the function will be executed. Example 1 permiture termination : { print( 1) ; return; print (2); } Output // 1 The second print is not executed. Example 2 returning data: func f(a) { return a+a; } f(4); //Output 8 passed a+a to the calling function.
7th Mar 2018, 2:31 PM
josh mizzi
josh mizzi - avatar
7th Mar 2018, 2:32 PM
Msizi
0
@Alexandra, please give links of your module questions. 1st example - Certain functions, such as int or str, return a value that can be used later. To do this for your defined functions, you can use the return statement. Example: def Max(x,y): if x>=y return x else: return y In the above function if x is x>y or x=y then it returns the value of x , otherwise it will return the value of y. This part is the conditional part of the Function. Now values put as print (Max(4,7)) z = Max(8,5) print (z) In print Max(4,7), x>y or x=y condition is not fulfilled (here x = 4, y = 7) so it returns y, that is 7. In second case, x = 8 and y = 5 and it fulfilled return condition of the Function,that is x > y , so it returns the value of x (x = 8). https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2287/
7th Mar 2018, 2:49 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
0
i am From brazil
7th Mar 2018, 3:35 PM
fabiano haupczinski
fabiano haupczinski - avatar
0
thank you
7th Mar 2018, 3:35 PM
fabiano haupczinski
fabiano haupczinski - avatar