Cheatsheet: Jupyter Lab
Jupyter Lab is a web-based interactive development environment used for data science, prototyping, and learning Python. It's best known for notebooks — where you can write code, run it live, and mix in rich text and visual output, all in one place.
What is Jupyter Lab?
Jupyter Lab is an upgraded interface for Jupyter Notebooks — a tool widely used in research, analytics, education, and early-stage software development.
Each file in Jupyter Lab is called a Notebook,
and has the extension .ipynb — which stands for
IPython Notebook, a name from its earlier days.
Notebooks are made up of cells — individual blocks that can contain either:
- Code cells (for Python and other supported languages)
- Markdown cells (for headings, formatted text, bullet points, etc.)
Jupyter Lab runs inside your browser but executes code locally or on a server kernel in the background.
- Data analysis and exploration
- Machine learning experiments
- Python learning environments
- Prototyping ideas quickly
Running Code in Jupyter Lab
The most important feature of Jupyter Lab is the ability to run code directly inside the notebook. This is done using code cells.
To run a code cell:
- Click inside the cell
- Press Shift + Return (or Shift + Enter)
This will execute the code and display the output just below the cell.
Example
print("Hello, Jupyter Lab!")
Progress Bar Example
You can use libraries like tqdm to visualize
progress in a loop:
import time
from tqdm import tqdm
spams = ["spam"] * 1000
for spam in tqdm(spams):
time.sleep(0.01)
Tip: Iftqdmis not installed, run!pip install tqdmin a code cell to install it.
Writing Markdown
Besides running Python code, Jupyter notebooks let you add formatted text using Markdown cells. This is helpful for notes, explanations, and headings in between code blocks.
How to Use
- Select a cell
- Click the dropdown at the top (usually shows "Code")
- Choose Markdown
- Type your text and press Shift + Return to render
Common Markdown Examples
# Heading 1
## Heading 2
**Bold text**
*Italic text*
- List item 1
- List item 2
Using Markdown from Python
You can also display Markdown output from Python using
IPython.display.Markdown:
from IPython.display import Markdown, display
display(Markdown("**Bold** and *italic* text"))
Tip: Markdown is not just for comments — use it to explain logic, show instructions, or format project documentation directly inside your notebook.
Navigating the Interface
Jupyter Lab has a multi-panel interface, designed to feel more like an IDE. Here's how to get around:
Main Components
- File Browser (Left Sidebar): Navigate folders, open notebooks, create new files.
- Launcher: Start new notebooks, terminals, markdown files, or consoles.
- Notebook Panel: Where your code and text cells live.
- Tabs: Jupyter Lab supports multiple open notebooks or consoles at once, just like a code editor.
Working with Files
- Right-click in the file browser to create, rename, delete, or duplicate files
- Click and drag to rearrange tabs
- Use Ctrl/Command + S to save changes
You can drag notebooks into side-by-side panels — useful when comparing notebooks or testing different versions of code.
Handy Shortcuts & Tips
Jupyter Lab supports useful keyboard shortcuts that speed up navigation and editing. Here are the ones you'll use most often:
Basic Cell Actions
- Shift + Return — Run current cell
- Control + Return — Run cell, stay in cell
- Esc + A — Add cell above
- Esc + B — Add cell below
- Esc + D D — Delete selected cell
- Esc + M — Convert cell to Markdown
- Esc + Y — Convert cell to Code
Editing Tips
- Double-click a Markdown cell to edit it
- Press Tab for autocomplete and suggestions
-
Use
?after a function to open inline help:pythonlen?
Magic Commands
Jupyter supports "magic" commands that begin with
% or %%. These are great for quick
utilities:
%time— Time a single line of code-
%%timeit— Run a cell multiple times and show average time -
%ls— List files in current directory (like Linuxls) -
%matplotlib inline— Display matplotlib plots directly in notebook
Press H in Command mode (Esc first) to bring up the full shortcut list anytime.
Summary & Next Steps
Jupyter Lab is one of the best environments for writing and experimenting with Python code. Whether you're analyzing data, learning programming, or testing logic, it helps you write code and see results instantly.
You now know how to:
- Run Python code in interactive cells
- Write formatted notes using Markdown
- Navigate the Jupyter interface and file system
- Use time-saving shortcuts and magic commands
- Create a new notebook and try combining code + markdown
-
Use
%%timeitto compare performance of two functions -
Install new libraries inside your notebook using
!pip install - Explore Jupyter extensions and themes via the settings menu
If you want to explore more advanced features, visit the official Jupyter Lab documentation. But even without that, you're now ready to start using it effectively.
Happy coding!