Intro to Programming and Data Analytics with Python


So! We've run our first file. However, what we're going to do is use a different piece of software bundled with Anaconda to run our Python : iPython Notebook (often just "iPython" for short, though iPython is actually the interpreter (kinda), and notebook itself is now formally part of a larger system called Jupyter).

iPython is a "REPL" (read–eval–print loop) system: basically a command prompt that interprets one or more lines of Python when you type them and push enter (or, in iPython's case SHIFT and ENTER) together. In the case of iPython, this command line is built into a document system which allows you to embed multiple command prompts into a document, interspersed with text and other elements.

You can run Python code inside the notebooks to load data and run analyses, also making dynamic documents that people can adjust using sliders, buttons, and other Graphical User Interface (GUI; "goo-ee") elements.

iPython is increasingly being adopted as a format for supplementary information for academic papers; it also generates a variety of output formats. The notebooks appear, by default, as webpages and can be saved in a format for uploading to the web ("HTML").


Follow the instructions below to open your first Notebook.

To open iPython, type the following at the command prompt/terminal:

ipython notebook

You should find a web browser opens showing a directory structure.

Find the New drop down list at the top of the page, and choose Python 3 (the difference between the old iPython and Jupyter is that Jupyter can now add other REPL-enabled languages). This will open up a Notebook.

You'll see that the webpage starts with a box to type in. Type the "Hello World" program into this box, then press SHIFT and ENTER together. This will run the line.

Screenshot: iPython HelloWorld


Screenshot: iPython HelloWorld

You can type a set of lines (indeed, a whole program) into one box, going back and adding extra lines to a pre-existing box.

Alternatively, you can use the insert menu to add new boxes above or below the current one.

If you need to rerun the code in a box (because it has an error or because you want to refresh the results) just click in it and SHIFT ENTER.

If you have multiple boxes, and they rely on each other, you only have to re-run those that are lower down after you change something -- the results of the boxes above don't need re-running.


As for what goes in the boxes, these are usually two things: either Python code, or a simple text formating language called "Markdown".

To see some markdown, make a fresh box and click in it. Go to the dropdown menu that says Code and change it to Markdown and then type the following markdown in an empty box:

# My notebook

SHIFT ENTER to translate/compile it from markdown to HTML, the language displayed in webpages.

You'll see it appears as a header. To re-edit the markdown, double click the new text.

There's a cheat sheet for markdown here.

Screenshot: iPython HelloWorld


Now we're familiar with iPython, let's do some coding!

  1. Start
  2. Get the software
  3. Writing our first program
  4. Debugging
  5. iPython Notebook
  6. Data Analysis <-- next