From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

For

For

- [Instructor] I love the syntax of the for loop in Python. My list equals 1, 2, 3, 4. For item in myList, print item. For item in my list reads like plain English. It lets you declare a new variable to hold the value of each element as you loop through it in Python. It's short and to the point and I'm not alone in my love of Python's for loop. In fact, it's the most common loop you'll use and see others use as you program in Python. So like the for loop, I'm going to keep this video short and to the point. All the statements we covered in the video on while loops, you can use in the for loop as well. So if we want to write a stub for a for loop and maybe come back and fill it in later, we can use pass. for letter, animals. That's going to be our animal list, in animalLookup.items, pass. We can also skip the rest of the loop during each iteration if we want, using the continue statement. So if length of animals is greater than one, continue. Then outside of our if block, print Only…

Contents