Programming with Python

The best way to learn how to program is to do something useful, so this introduction to Python is built around a common scientific task: data analysis.

Our real goal isn’t to teach you Python, but to teach you the basic concepts that all programming depends on. We use Python in our lessons because:

  1. we have to use something for examples;
  2. it’s free, well-documented, and runs almost everywhere;
  3. it has a large (and growing) user base among scientists; and
  4. experience shows that it’s easier for novices to pick up than most other languages.

But the two most important things are to use whatever language your colleagues are using, so that you can share your work with them easily, and to use that language well.

Prerequisites

Learners need to understand the concepts of files and directories (including the working directory) and how to start a Python interpreter before tackling this lesson. This lesson references the Jupyter (IPython) Notebook although it can be taught through any Python interpreter. The commands in this this lesson pertain to Python 2.7.

Getting ready

You need to download some files to follow this lesson:

  1. Save notebooks.zip to your desktop.
  2. If it’s not unzipped yet, double-click on it to unzip it. You should end up with a new folder called notebooks.
  3. You can access this folder from the Unix shell with:
$ cd && cd Desktop/notebooks
$ ipython notebook

After running the ipython notebook command above, a new tab should open in your browser!

Topics

  1. Python, IPython, IPython Notebooks
  2. Analyzing Mosquito Data
  3. Lists
  4. Making Choices
  5. Looping

Other Resources