isPrime works but UnBoundLocalError when mapping on list

Terry Reedy tjreedy at
Tue Jul 15 23:00:48 CEST 2008

Andreas Tawn wrote:

> I think a better explanation is that in your original function, x only
> existed while the for loop was running. As soon as execution hit the
> break statement, x ceased to exist.

Wrong.  For loop variables continue after the loop exits.  This is 
intentional.  Mensanator gave the correct explanation (loop never enters 
for nbr==1).

More information about the Python-list mailing list