Introduction

Welcome to Chapter 2! We consider two powerful tools in this section of the course: lists and loops. Lists are our first dive in to data structures that store more than one piece of information. Our goal is to ultimately hold lots ofdata in one variable (e.g all stock returns for the S&P 500 over the last ten years), and lists will take one baby step in that direction. While not the most powerful data structure in Python, lists will always be useful because they are the most convenient way to record a set of data points of interest. For example, a list of ticker symbols is a great way to instruct Python to perform some analysis on multiple companies. We’ll also learn about loops, a logical structure in Python that allows us to dramatically simplify redundant tasks. Of all of the benefits that learning to program offers, perhaps none is more commonly used than the ability to simplify redundant jobs. With the ability to use loops, analyzing the financial statements of 1,000 companies is no more difficult than analyzing the financial statements of 2 companies.

At the end of this chapter, you’ll be able to:

  1. Write for and while loops to control Python logic

  2. Utilize list variables to compactly store data

  3. Model a simple savings/investment decision in Python

  4. Create the beginnings of a robo-advisor to give automated investment advice with a function that is robust to user error

bulldog