Let's talk about breaking out of loops in Python.
return
Here's a function that uses a for
loop to loop over an iterable of strings, and returns a value from within that loop if it finds a string that contains a given substring.
If it doesn't find a match, it returns None
:
...
This is a premium screencast available only to active Python Morsels subscribers.
Feel free to watch some of the free screencasts in the Looping series.
Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that.