Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code
by Zed A. Shaw
Exercise 32. Loops and Lists
You should now be able to do some programs that are much more interesting. If you have been keeping up, you should realize that now you can combine all the other things you have learned with if-statements and Boolean expressions to make your programs do smart things.
However, programs also need to do repetitive things very quickly. We are going to use a for-loop in this exercise to build and print various lists. When you do the exercise, you will start to figure out what they are. I won’t tell you right now. You have to figure it out.
Before you can use a for-loop, you need a way to store the results of loops somewhere. The best way to do this is with lists. A list is exactly what the name says: a container of things ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access