Post

@Python_Dv Answer: A
Solution: Here the main trick is that...
`return` takes you out of the function.
Breaks out of every loop, conditional, whatever.
Straight back to where the function was called from.
Here func is called in the argument to print.
Inside func there is a loop over
+
English

@Python_Dv `elements` which is [10, 20]
What happens in the 1st iteration of the loop?
x gets the value 10.
And then we return x.
That's it. We saw return.
End of story for the function.
The loop is terminated, the function is terminated.
`return` directly takes 10 to print
+
English

@Python_Dv and `print` outputs
10
and that's the output.
`return` is like hitting the Stop button on a function.
Since the function got terminated from `return`,
there is no question of completing loop iteration.
That's it for this question, but here's an interesting fact.
Sometimes
+
English

@Python_Dv you don't want to hit the Stop button with a function.
But rather, you want to hit a Pause button, ie,
a kind of "return" that gives back a value,
but doesn't terminate the function,
only freezes it.
Then you can call it again, and it will start from the point you paused.
+
English

@Python_Dv Python does provide such functionality.
That's where the `yield` keyword comes in.
Instead of Stop button like `return`,
`yield` is the pause button.
A function that uses `yield` is called a Generator.
Good topics for a rabbit hole dive.
Thanks for reading!
English

