Skip to content

Instantly share code, notes, and snippets.

@CharudattaManwatkar
Last active April 4, 2021 06:52
Show Gist options
  • Save CharudattaManwatkar/cdb81c1d8e4d856455e90099482eb209 to your computer and use it in GitHub Desktop.
Save CharudattaManwatkar/cdb81c1d8e4d856455e90099482eb209 to your computer and use it in GitHub Desktop.
An example of else clause with for loop in python
my_list = ['some', 'list', 'containing', 'five', 'elements']
min_len = 3
for element in my_list:
if len(element) < min_len:
print(f'Caught an element shorter than {min_len} letters')
break
else:
print(f'All elements at least {min_len} letters long')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment