To make it simple, you can think of it like that;
break
command in the for
loop, the else
part will not be called.break
command in the for
loop, the else
part will be called.numbers = [2, 4, 6, 8, 1] for number in numbers: if number % 2 == 1: print(number) break else: print("No odd numbers")
In other words, if for loop iteration is not "broken" with break
, the else
part will be called.
Comments
Add comment