This chapter defines iteration and the concept of a suite of code in Python. The for statement is the primary way to loop through a collection of data or to loop a specific number of times.
Objectives
Upon completion of this chapter’s exercises, you should be able to:
- Use the for statement with a suite of code to loop through a list or tuple.
- Create ranges with a specific number of elements, with a specific starting and ending value, and with start, stop, and step values.
- Apply the range and the for statements to loop a specific number of times.
- Use the current loop value for calculations and display.
- Show the use of the for statement to iterate through a dictionary’s key values.
- Develop programs to analyze a list.