Consider the following (ridiculous) Python function: def myfunc(): return 1 return 2 return 3 I can define the function, and then run it. What do I get back? >>> myfunc() 1 Not surprisingly, I get 1 back. That’s because Python reaches that first “return” statement and returns 1. There’s no need to continue onto the…
When you put a piece of Python data into a “for” loop, the loop doesn’t execute on the data itself. Rather, it executes on the data’s “iterator.” An iterator is an object that knows how to behave inside a loop. Let’s take that apart. First, let’s assume that I say: for letter in ‘abc’: …