Skip to Main Content

Programming with Python

An introduction to programming with Python. Includes how to get started with Python, coding in Python with Jupyter Notebooks, and various links where you can learn more.

What are Jupyter Notebooks?

Working with Jupyter* Notebooks allows you to mix code, documentations (instructions, explanations, tutorials), visualizations, and equations all in the same document. For this reason, they are frequently used in instruction.

There are two basic units of a Jupyter Notebook: code cells and text cells.

In code cells, you can write and run a chunk of code and Jupyter will print any output or plots directly below the cell. This output includes plots and other visualizations.

Meanwhile, text cells - often also called markdown cells - are intended to be read by other humans. In these text cells, teachers can instruct their students how the following code works and explain what it does, researchers can document their workflow and thought processes for their collaborators, and anyone can record notes for themselves, explaining what they are trying to accomplish in the code cell that follows.

Text cell are also called markdown cells because they allow the user to edit the style of the text using a simplified syntax known as Markdown. Some example of Markdown syntax includes:

  • *italics*  (that is, all text between "*" are rendered as italics)
  • **bold**
  • # Header 1
  • ## Header 2

For more explanation, see the Jupyter Notebook documentation for Markdown Cells.

* Its name comes from the three core programming languages supported by Jupyter: Julia, Python and R. However, Jupyter now supports over 40 languages.

How to work with Jupyter Notebooks on Dartmouth's Jupyter Hub

Some workshops offered by Dartmouth's Reproducible Research team as well as some classes offered by Dartmouth instructors teach with Jupyter Notebooks stored on Dartmouth's Jupyter Hub.

JupyterHub is a platform for sharing and using Jupyter notebooks on a remote serve. Our version is only accessible to members of our community with a Dartmouth login.

For participants in Dartmouth workshops and classes or for members of our community who want to use our notebooks as standalone, self-guided instructional materials: you can access course notebooks on Dartmouth's Jupyter Hub by following instructions listed on our JHUB research guide.

Students of Python / programming from outside our community may still find and download many of our materials from our Gitlab repository.

Using Jupyter Notebooks: Tips & Tricks

Adding cells: ESC-A (to add above) or ESC-B (to add below)

Modifying cells: ESC-M (to switch cell to markdown), ESC-Y (to switch to code cell)

Deleting cells: ESC-D-D (hit D twice while holding down escape)

Markdown Syntax

Running Code: to run a cell, place your cursor in it and click the triangular "play" button or hit CTRL-ENTER

Magic Commands:

    %who - to output all variables stored in memory

    click here for a list of other magic commands