Creating and working with a Jupyter Notebook in Jupyter Lab is quite straightforward. Here's a quick and simple guide to get you started:
Open Jupyter Lab
- After installing Jupyter Lab and activating your virtual environment (as described in the previous instructions), start Jupyter Lab by running `jupyter lab` in your command prompt or terminal. This will open Jupyter Lab in your default web browser.
Create a Jupyter Notebook
1. In the Jupyter Lab interface, look for the **Launcher** tab which opens by default when you start Jupyter Lab. If you can't see it, you can open a new launcher by clicking the **+** icon on the left sidebar.
2. Under the **Notebook** section in the Launcher, click on the Python version you want to use. This will create a new notebook.
Basic Operations in a Jupyter Notebook
Add a Cell
- A notebook is made up of cells. To add a new cell, you can click the **+** button in the notebook toolbar. By default, a new cell is a code cell.
Change Cell Type
- You can change a cell's type between Code and Markdown (for text) using the dropdown menu in the toolbar. Markdown allows you to add formatted text, images, and more.
Enter/Edit Mode
- **Edit mode** (indicated by a green cell border): You can type into the cell, like a normal text editor. Enter edit mode by clicking inside a cell or pressing `Enter` on a selected cell.
- **Command mode** (indicated by a blue cell border): You can perform notebook and cell actions with keyboard shortcuts. Enter command mode by pressing `Esc` on a selected cell.
Run a Cell
- To run a cell and advance to the next cell, press `Shift + Enter`. To run a cell and stay on that cell, press `Ctrl + Enter`. Running a Markdown cell will render the Markdown to formatted text.
Save the Notebook
- Click the floppy disk icon on the top left or press `Ctrl + S` to save your notebook.
Keyboard Shortcuts
Jupyter Notebooks support multiple keyboard shortcuts. Some useful ones include:
- `A`: Insert a new cell above the current cell (in command mode).
- `B`: Insert a new cell below the current cell (in command mode).
- `M`: Change the current cell to a Markdown cell (in command mode).
- `Y`: Change the current cell to a code cell (in command mode).
- `DD` (press D twice): Delete the current cell (in command mode).
Closing a Notebook
- To close a notebook, simply close the tab in your web browser. Make sure you've saved your work before closing.
This guide should help you get started with creating and using Jupyter Notebooks in Jupyter Lab, including performing basic operations like adding and running cells, changing cell types, and saving your work.