empty clause of for loops

Random832 random832 at fastmail.com
Wed Mar 16 12:37:34 EDT 2016


On Wed, Mar 16, 2016, at 11:17, Sven R. Kunze wrote:
> I can imagine that. Could you describe the general use-case? From what I 
> know, "else" is executed when you don't "break" the loop. When is this 
> useful?


for item in collection:
   if good(item):
      thing = item
      break
else:
   thing = default # or raise an exception, etc



More information about the Python-list mailing list