Introduction to Python and JupyterLab

Python programming
Python basics
JupyterLab
Anaconda

This lesson introduces Python and JupyterLab for beginners, covering how to install Anaconda, launch JupyterLab, create notebooks, and run your first Python code in an interactive environment.

Authors

Noor Sohail

Will Gammerdinger

Published

March 16, 2026

Keywords

Python tutorial, Beginner Python, JupyterLab notebooks, Install Anaconda, Python setup

Approximate time: XX minutes

Learning Objectives

In this lesson, we will:

  • Describe what Python and Jupter Lab are
  • Familiarize ourselves with the Jupyter Lab interface
  • Interact with Python within Jupyter Lab

Overview of lesson

This lesson is all about getting you to the point where you can actually run Python code on your own. We will use Anaconda and JupyterLab so that you can open a notebook, write code, and see results immediately. These same tools are widely used in research labs and data teams to explore datasets, document analyses, and share results with collaborators.

By the end, you will have a working Python environment that you can reuse for future projects, whether you are automating a simple task or starting a larger analysis.

What is Python?

Python is a programming language that allows us to write code to perform various tasks. It interprets code, written in a particular syntax, to execute tasks defined by the programmer. Due to its simplicity and readability, Python is a great language for beginners, but is also powerful enough to be used to answer complex, real world questions. Therefor many fields, such as data science, machine learning, bioinformatics, and more have adopted Python a tool for their work.

The Python environment combines:

  • Effective handling of big data
  • Collection of integrated tools
  • Graphical facilities
  • Simple and effective programming language

Why use Python?

Python has a large ecosystem of libraries that can be used for a wide range of applications, from data wrangling to bioinformatics analyses.

Among its many capabilities, Python is particularly well-suited due to:

  • Ease of data handling, wrangling, and storage
  • Capability to run statistical analyses with many graphical techniques
  • How it can be installed on any computer and (and it’s free!)
  • Its open source community

In addition, Python has a large and active community, which means there are many resources available for learning and troubleshooting.

Anaconda

Anaconda is a popular distribution of Python. When you install Anaconda, you get a Python environment as well as many useful libraries and tools for data science and scientific computing. It provides an easy way to manage Python environments and packages.

Installing Anaconda

Prior to today’s lesson, you should have installed Anaconda onto your computer.

By installing Anaconda, we have also installed Python.

Anaconda Navigator

We can get started by opening the application Anaconda Navigator, which was installed with the link above. This program allow us to interface with Python environment and applications.

When opening the application, the screen should look something like this:

Figure 2: Anaconda Navigator interface.

Jupyter Lab

One of the packages downloaded with Anaconda is Jupyter Lab. These are interactive environments that allow you to create and share your Python code and visualizations. Jupyter Lab are widely used for sharing results and running analyses.

Rather than creating scripts that are run in a terminal, Jupyter Lab allow you to write and execute code in a more interactive way. You can write code in cells, run those cells, and immediately see the output. This makes it easier to experiment and test your code as you go.

Let us open Jupyter Lab by clicking the “Launch” button under the Jupyter Lab application in Anaconda Navigator. This will open a new tab in your web browser with the Jupyter Lab interface.

Warning

TODO: Make our own screenshot, I have just taken this from the this other workshop for now since I have many conda environments when I open mine. It woul dbe nice to have a similarly labeled image.

Figure 4: Jupyter Lab interface.
Source: Python for Geographic Data Analysis

Even though Jupyter Lab opens your web browser, it is not actually accessing the internet. It is running on your local computer at the port http://localhost:8888 which is hosted on your computer and is not accessible to anyone else.

File Navigator

On the left-hand side of Jupyter Lab, we have access to the file navigator. This allows us to navigate through the files on our computer and open them in Jupyter Lab. To begin, let us make a new folder for this workshop in our Desktop folder. To create a new folder titled, “intro_python”, click the “New Folder” button in the file navigator.

Exercise 1

To organize your working directory for a particular analysis, you should separate the original data (raw data) from intermediate datasets. For instance, you may want to create:

  • data/: directory within your working directory that stores the raw data
  • scripts/: directory for your Python scripts and notebooks
  • results/: folder for intermediate results
  • figures/: directory for the plots you will generate.

For this exercise create each of these directories. When finished, your working directory should look like this:

Figure 5: File navigator in Jupyter Lab after creating directories.

Creating a Python Notebook

From the menu bar, create a new notebook with File -> New -> Notebook. This will open a notebook in a new tab.

You may be prompted to select a kernel. A kernel refers to the environment used to execute code in the notebook. This is in reference to the environments that can be managed in Anaconda Navigator. We will discuss environments in more detail later in the workshop, but for now we will be working with base as we become familiar with Python and Jupyter Lab. So select the Python [conda env: base] kernel from the dropdown menu.

A Jupyter Notebook is a document that contains both code and text inside cells. Cells are the building blocks of a Jupyter Notebook. They can contain code, text, or other types of content.

Figure 6: Freshly created Jupyter Notebook.

We can see in the File Navigator that we have a new file called Untitled.ipynb. The .ipynb extension stands for “interactive Python notebook”. We can rename this file by right-clicking on it in the File Navigator and selecting “Rename”. Let us rename this file to intro_python.ipynb.

Running Python Code

In the notebook, we can write Python code in the cells. To create a new cell, click the "+" button in the toolbar at the top of the notebook.

Now that we are all set up, let us try running some Python code in our notebook!

Let us start by evaluating what the sum of 3 and 5 is. We are also going to include comments in our code to describe what we are doing. This is best practice for writing code, as it allows others (and your future self) to understand what the code is doing. To write a comment in Python, we use the # symbol. Anything that follows the # symbol on a line is considered a comment and is not executed as code.

# Intro to Python Lesson
# March 2026
# Author: Harvard Chan Bioinformatics Core


# Add 3 and 5
3 + 5
8

To run a cell, you can click on the cell and then click the “Run” button in the toolbar at the top of the notebook. You can also use the keyboard shortcut Shift + Enter to run a cell.

Figure 7: Output of running 3 + 5 in Jupyter Lab.

What happens if we do that same command without the comment symbol #? Re-run the command after removing the # sign in the front:

Add 3 and 5
3 + 5
  Cell In[2], line 1
    Add 3 and 5
        ^
SyntaxError: invalid syntax

Now Python is trying to run that sentence as a command, and it doesn’t work. We get an error in the console. This means that the Python interpreter did not know what to do with that command. Reintroduce the # to re-comment the appropriate line.

This is a clear example of how Python has a specific syntax that must be followed for the code to run properly. We will continue to learn more about the proper format of Python code as we go through the workshop. It really is its own language just like English, but with its own grammar and rules.

The Importance of Comments

Before we move on to more complex concepts and getting familiar with the language, we emphasize the importance of commenting your code.

Use # signs to comment. Comment liberally in your Python scripts. This will help future you and other collaborators what your code was meant to do. Anything to the right of a# is ignored by Python. A shortcut to comment out entire chunks of code is to highlight several lines and hit Ctrl+/ (or Cmd+/ on a Mac).


Next Lesson >>

Back to Schedule

Reuse

CC-BY-4.0