** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
else
count = 0
while count < 5:
print(count)
count += 1
else:
print('done')
result
0
1
2
3
4
done
If the conditions specified by while are not met,
What is described in ʻelse` is executed.
break and ʻelse`break_else
count = 0
while count < 5:
if count == 1:
break
print(count)
count += 1
else:
print('done')
result
0
If you break the loop with break, what is written in ʻelse is not executed. Conversely, ʻelse is executed if while is exited rather than by break.
Recommended Posts