+ 3

What return do?

When it is inside a loop in a function https://code.sololearn.com/c568T2kSuF6X/?ref=app

11th Dec 2021, 7:46 AM
Sameeksha Yadav
Sameeksha Yadav - avatar
14 Answers
+ 8
return keyword simply returns the value from the function to where that function is being called. ex- def fun(): return 5 print(fun()) # will result 5
11th Dec 2021, 7:58 AM
zexu knub
zexu knub - avatar
+ 8
Also, the return keyword stops the execution of the function so if it is inside the loop, the loop will be broken after the return statement run.
11th Dec 2021, 8:04 AM
zexu knub
zexu knub - avatar
+ 5
Remove two spaces before the return and run the program again. It should give other results.
11th Dec 2021, 8:37 AM
Paul
Paul - avatar
+ 5
Sameeksha Yadav Return is used in two different ways 1. When you want to return a value back to the function 2. When you want to stop further execution of the function. You have used return inside loop so after meeting first condition loop will be stop there and value will be return back to the function. Since there is no return value so it will give None when you print function.
11th Dec 2021, 8:45 AM
A͢J
A͢J - avatar
+ 4
Ok
12th Dec 2021, 3:03 AM
✓`•°`™AnOnimus™`°•`✓ فايز الله‎
✓`•°`™AnOnimus™`°•`✓   فايز الله‎ - avatar
+ 3
According to ur code ur not return anything, so it's not return anything there. Usually return will pass the data back to called one. u can use like return i to return I value
12th Dec 2021, 7:35 PM
Mallikarjunagoud A
Mallikarjunagoud A - avatar
+ 2
Paul yes it gives 😊 As it is inside a function rather than inside a loop thanku all now I am cristal clear
11th Dec 2021, 8:47 AM
Sameeksha Yadav
Sameeksha Yadav - avatar
+ 2
Because the return return None, so, the print() print None, so, put the name of the function only. I hope you understand me
12th Dec 2021, 7:44 PM
CGO!
CGO! - avatar
+ 1
Fayzulloh فايز الله‎ This is not a right place for advertisement or wishes.
11th Dec 2021, 7:46 PM
A͢J
A͢J - avatar
+ 1
ىرؤ
12th Dec 2021, 2:42 PM
YASSINE El
+ 1
With the way your range is set up, your input does nothing since it always start at 1 and stops at 2 no matter what your input is. And yes, the return stops the function, but is it really necessary?
12th Dec 2021, 5:09 PM
Bob_Li
Bob_Li - avatar
+ 1
The point is this: If your function is used to provide a value to other parts of your program, you might need to use a blank return statement, but perhaps not at all, since python functions with no return statement implicitly returns none. If your function is only meant to print something, you could omit the return statement as it is not needed. You could use the break statement instead of return in this case to make your function do the same thing and make it less ambiguous to other people reading your code.
13th Dec 2021, 1:17 AM
Bob_Li
Bob_Li - avatar
+ 1
Return keyword return the value to the function where it is being called. it also stops the program execution
13th Dec 2021, 6:34 AM
𝙺𝚊𝚛𝚝𝚑𝚒𝚔𝚎𝚢𝚊
𝙺𝚊𝚛𝚝𝚑𝚒𝚔𝚎𝚢𝚊 - avatar
+ 1
Please how would I type the inputs into the computer when using the Cin >> operator.
13th Dec 2021, 6:48 AM
Ja'afar Tj