[Tutor] Prime Numbers
Andreas Perstinger
andipersti at gmail.com
Mon Dec 16 11:07:28 CET 2013
On 16.12.2013 09:49, Rafael Knuth wrote:
> That's the tiny little detail I am confused about: What does return
> exactly do? Does it return only the first value within a loop or does
> it iterate through all values within a loop? (unless a given condition
> is met)
The return statement has nothing to do with loops. Whenever the Python
interpreter gets to a return statement during the program execution it
will immediately leave the current function and return to the caller.
"return" outside of a function doesn't work:
>>> for i in range(10):
... return i
...
File "<stdin>", line 2
SyntaxError: 'return' outside function
Bye, Andreas
More information about the Tutor
mailing list