What else is for in loops
What's else in the for loops?
We'll cover the following...
The else statement in loops only executes if the loop completes successfully. The primary use of the else statement is for searching for items:
Press + to interact
my_list = [1, 2, 3, 4, 5]for i in my_list:if i == 3:print("Item found!")breakprint(i)else:print("Item not found!")
In this code, we break out of the loop when i ...