-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
In the previous chapters, we’ve learned how to store data and make decisions in our code. But what happens when we need to perform the same action multiple times? Imagine I want to count and register all the birds outside the window, but there are too many to count and enter into my administration system manually. Repeating the same code over and over isn’t efficient or practical.
This is where loops come in! Loops make it possible to run a block of code multiple times without copying and pasting it. In this chapter, we’ll explore the magic of loops in Python. First, I’ll show you the challenges of repetitive code. After that, we’ll learn about while loops. Once we understand that construct, we’ll gradually build it up to for loops to iterate over collections, and we’ll see how we can work with for loops and range.
Let’s wait no longer, and let’s get looping!
