Last active
April 4, 2021 06:52
-
-
Save CharudattaManwatkar/cdb81c1d8e4d856455e90099482eb209 to your computer and use it in GitHub Desktop.
An example of else clause with for loop in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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