Python for else loop | Just enough Python

Published: 23 September 2019
on channel: Ajay Tech
27
1

This is a syntax that is kind of unique to Python. The syntax applies equally well with while statement as well. It is more of a convenience function, but newbies get confused with this syntax some times. It basically means that if nothing is found in the loop, do something in the else part. Typically, when searching for something in a loop, we want to do something when nothing has been found – How would we know if the loop ended because of a break statement or if the loop has completed all of its iterations ?

The else in for else is used to indicate a situation where the loop has been exhausted, not broken.

https://ajaytech.co/python-loops/#for...


On this page of the site you can watch the video online Python for else loop | Just enough Python with a duration of hours minute second in good quality, which was uploaded by the user Ajay Tech 23 September 2019, share the link with friends and acquaintances, this video has already been watched 27 times on youtube and it was liked by 1 viewers. Enjoy your viewing!