Noob: Loops and the 'else' construct

Thorsten Kampe thorsten at thorstenkampe.de
Sat Oct 20 04:13:49 EDT 2007


* Dustan (Fri, 19 Oct 2007 11:39:04 -0000)
> On Oct 19, 3:12 am, Thorsten Kampe <thors... at thorstenkampe.de> wrote:
> > So a for/else loop is exactly the same thing as a for loop with the
> > else clause outside the loop (except for "break")?
> 
> Am I missing something here? It sounds to me like you just described
> two identical constructs.

#
for i in range(10):
    print i
else:
    print 'the end!'
#

is the same else

#
for i in range(10):
    print i
print 'the end!'
#



More information about the Python-list mailing list