Trade Off

supercalifragilisticexpialidocious

Else Clause in Python Loop

both in while and for loop, if in loop body, no break, no return, no exception is raised, statements in else block will be executed.

1
2
3
4
for x in []:
     print x
else:
     print ‘xxx’

this example will print ‘xxx’, even nothing in list and this loop is not executed.

Comments