0

Please can someone explain the return statement in function like am 5?

Function

29th Mar 2022, 1:09 PM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
14 Answers
+ 3
Okundaye Jesse Eghosasere , we are going to help you, if you can give us a clear description of your task, not to forget a link to your code. thanks!
29th Mar 2022, 1:21 PM
Lothar
Lothar - avatar
+ 2
You can re-read the lessons as often as you like. Modify the example codes to see how it affects the output. "return" means "give back". A function that returns a values, gives you the value it has calculated. Now you can use the returned value, e.g. store it to another variable or print it
29th Mar 2022, 1:36 PM
Lisa
Lisa - avatar
+ 1
Okay so basically you want to know about return statement right? Just assume one example: you go to shop you give shopkeeper some money in return he gives you something which you want.. so same is with coding you call one function with some parameters and expects something to get returned which you want... hence for any user-defined functions from where you want some kind of output you have to write return statement.. This is what basic return statement means.. if your query is yet not solve I'll request you to put it more clearly Thanks,
31st Mar 2022, 12:51 AM
Johnny Doe
+ 1
Think of a function as a part of an assembly line at a factory. Perhaps this machine on the assembly line takes a water bottle and puts a plastic label on it. This machine (function) is going to have some sort of input and some sort of output. The input for this machine would be both a water bottle and some sort of plastic label. The output would be a plastic bottle with a label on it. This output is what we put in the return statement. If we were to think of programming the factory machine, we would write something like this: function machine(bottle, label): labelled_bottle = bottle + label return labelled_bottle That return statement tells us exactly what is popping out the other side of the machine AND it tells us that the machine is done doing its job.
31st Mar 2022, 5:28 AM
Samuel Jackson
Samuel Jackson - avatar
0
Thank youLothar
30th Mar 2022, 11:29 AM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
0
Thank you Lisa
30th Mar 2022, 11:30 AM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
0
Thank youSlick
30th Mar 2022, 11:31 AM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
0
A function with a return statement returns a value which can be assigned to a variable(or manipulated in anyway you deem fit). A function without a return statement just does something (or nothing) depending on how you define the function.
30th Mar 2022, 1:31 PM
Kachi Emmanuel
Kachi Emmanuel - avatar
0
Kachi Emmanuel Can I use while or for loop with a return statement?
30th Mar 2022, 2:05 PM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
0
Kachi Emmanuel Thank you
30th Mar 2022, 2:05 PM
Okundaye Jesse Eghosasere
Okundaye Jesse Eghosasere - avatar
0
Okundaye Jesse Eghosasere return is used to mean "give back" some result. I think you are thinking it as return to mean "go to" somewhere, which is a wrong concept.
30th Mar 2022, 3:34 PM
Bob_Li
Bob_Li - avatar
0
Okundaye Jesse Eghosasere Study this instance: #this function returns a value which can be assigned to a variable def iAmNone(): return None #this function doesn't return anything; it just prints a text for each iteration of the for loop def printSomeNones(): for i in range(2): print("some Nones") var1 = iAmNone() #can do this since the function returns a value print(var1) printSomeNones() # can't assign this to a variable since it doesn't return anything Result... None some Nones some Nones
30th Mar 2022, 4:40 PM
Kachi Emmanuel
Kachi Emmanuel - avatar
0
See it as a function that gives you feedback of your instructions in a program. Now see the instructions as your code, telling the program to do a particular task and asking for a feedback via your return function.
31st Mar 2022, 1:01 PM
Roland Ogbue
Roland Ogbue - avatar