+ 3
What return do?
When it is inside a loop in a function https://code.sololearn.com/c568T2kSuF6X/?ref=app
14 Antworten
+ 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
+ 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.
+ 5
Remove two spaces before the return and run the program again. It should give other results.
+ 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.
+ 4
Ok
+ 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
+ 2
Paul yes it gives 😊
As it is inside a function rather than inside a loop
thanku all now I am cristal clear
+ 2
Because the return return None, so, the print() print None, so, put the name of the function only.
I hope you understand me
+ 1
Fayzulloh فايز الله
This is not a right place for advertisement or wishes.
+ 1
ىرؤ
+ 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?
+ 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.
+ 1
Return keyword return the value to the function where it is being called. it also stops the program execution
+ 1
Please how would I type the inputs into the computer when using the Cin >> operator.