
A Tufts University Data Lab Workshop
Written by Uku-Kaspar Uustalu

Resources: go.tufts.edu/python
Slides: tufts.box.com/v/intro-python
Live offerings: go.tufts.edu/workshops
Contact: datalab-support@elist.tufts.edu
Table of Contents
Workshop Overview
This is a hands-on workshop designed to introduce you to the wonderful world of programming and get you acquainted with the popular and easy-to-use programming language Python. The first part of the workshop involves hands-on exercises using a command-line based Python interpreter and is intended to be completed at an instructor-guided session. The second part of the workshop is composed of an interactive Python notebook with built-in exercises and solutions. The notebook is suitable for self-guided study and covers the following:
- Basic arithmetic and string manipulation
- Working with lists, dictionaries, and tuples
- What are functions and how to write your own
- Using loops and list comprehensions
- Control flow with conditional statements
- The difference between copies and views
- Reading technical documentation
- Importing and using Python libraries
The notebook is designed to be run in a pre-configured cloud-computing environment either via Binder or Google Colab and does not require the installation of any software. Use of Binder is recommended as it provides a JupyterLab interface and allows for an experience similar to using a local installation. It is also possible to run the workshop notebook using a local installation of JupyterLab Desktop or Anaconda/Mambaforge. Instructions on how to install a suitable Python environment are available here: go.tufts.edu/installingPython
Part 1/2: Working with Python on the Command Line
Launching a Virtual Terminal Instance (Recommended)

- Click on the Launch Terminal button above.
- A Binder instance will launch in a new tab with the message Starting Repository.
- Wait patiently and do not close the Binder tab. After a few minutes, a Terminal instance will launch.
- To launch a Python interpreter, type
python
and press Enter or Return.
Launching a Conda-Enabled Console using a Local Anaconda or Mambaforge Installation
- If you have Anaconda or Mambaforge installed, you can launch a Conda-Enabled Terminal or Prompt as follows:
- Windows (Anaconda): Start > Anaconda3 > Anaconda Prompt
- Windows (Mambaforge): Start > Mambaforge > Mambaforge Prompt
- macOS: Applications > Utilities > Terminal
- Ensure the last line of text in the Terminal or Prompt begins with
(base)
.
- To launch a Python interpreter, type
python
and press Enter or Return.
Part 2/2: Using an Interactive Python Notebook Environment
Running the Notebook using a Virtual JupyterLab Instance (Recommended)

- Click on the Launch Binder button above.
- A Binder instance will launch in a new tab with the message Starting Repository.
- Wait patiently and do not close the Binder tab. After a few minutes, a JupyterLab instance will launch.
- If the workshop notebook does not automatically open, double-click on
intro-python.ipynb
in the file browser on the left.
Running the Notebook using Google Colab

- Click on the Open in Colab button above. The Google Colab interface will open in a new tab.
- If you are not already signed into your Google account, click on Sign In in the upper-right and sign in with your Google credentials. You must be signed in with a Google account to be able to run notebooks in Google Colab.
- Optional: To retain any changes you make to this notebook, save a copy of the notebook to your Google Drive by clicking the Copy to Drive button or selecting File > Save a copy in Drive. This will save the notebook to the
Colab Notebooks
directory in your Google Drive. Once the saved copy pops up, close the original notebook and use the copy going forward. Feel free to rename the copy if desired. Any changes made to your personal copy will be automatically saved.
You might also see a message warning you that this notebook was not authored by Google and hence might contain malicious code. You can trust Data Lab notebooks, so click Run Anyway. But when running other third-party notebooks, you should review the code beforehand.
Running the Notebook using a Local JupyterLab Desktop Installation

- Click on the Download Notebook button above to download the workshop notebook.
- Create a designated directory for this workshop and move the downloaded
intro-python.ipynb
notebook there.
- Open the directory containing
intro-python.ipynb
using File Explorer (Windows) or Finder (macOS).
- Right-click on the downloaded
intro-python.ipynb
file and select Open With > JupyterLab Desktop to launch the notebook.
Running the Notebook using a Local Anaconda Installation

- Click on the Download Notebook button above to download the workshop notebook.
- Create a designated directory for this workshop and move the downloaded
intro-python.ipynb
notebook there.
- Launch Anaconda Navigator via the Start Menu (Windows) or from Applications (macOS).
- Windows: Start > Anaconda3 > Anaconda Navigator
- macOS: Applications > Anaconda Navigator
- Launch JupyterLab using the corresponding Launch button.
- JupyterLab will launch in a web browser. (A new tab will be generated if a browser is already open.)
- Within the JupyterLab file explorer on the left, navigate to the directory containing the
intro-python.ipynb
notebook.
- Once you are in the correct directory, double-click on
intro-python.ipynb
in the file browser to open the workshop notebook.
Running the Notebook using a Local Mambaforge Installation

- Launch Terminal (macOS/Linux) or Mambaforge Prompt (Windows).
- Windows: Start > Mambaforge > Mambaforge Prompt
- macOS: Applications > Utilities > Terminal
- Run the following commands by typing or pasting the command into the console and then pressing Enter or Return.
- Download and extract the workshop materials:
curl -Lo - https://github.com/tuftsdatalab/intro-python/archive/workshop.tar.gz | tar -xzf -
- Navigate into the extracted directory:
- Create a new environment for the workshop:
mamba env create -f environment.yml
- Activate the workshop environment:
conda activate intro-python
- Open the workshop notebook in JupyterLab:
jupyter lab intro-python.ipynb
- JupyterLab will launch in a web browser. (A new tab will be generated if a browser is already open.)
- If the workshop notebook does not automatically open, double-click on
intro-python.ipynb
in the file browser on the left.
- Do not close the console! Closing the console will also terminate JupyterLab. Leave the console running in the background.
Additional Resources {resources}
Software Carpentry Lessons