Writing code in a Jupyter Notebook
Jupyter notebook is used for writing
and running Python code.
Creating and saving a Jupyter notebook
Use the following steps:
- ·
Open
Anaconda and launch Jupyter Notebooks.
- ·
On
the first page create a folder for Jupyter.
- ·
Navigate
to the Jupyter Notebooks folder.
- ·
Click
New and choose Python 3.
- · Opened click Untitled, type in the new name 01 Notebook, and click Rename.
- The notebook is created and saved in your AIO Python folder
· Typing Python code into any Code cell and text into any Markdown cell and running code in a notebook:-
·
Use the following steps:-
- Click in
the Code cell (to the right of In [ ]: and type print(“Hello World”) and don’t forget to use lowercase letters for the word print.
- To run the code, hold down the Alt key (in
Windows) or the Option key (on a Mac) and press Enter, or click the Play
triangle to the left of the word In.
- (To run a piece of
code, click on the cell to select it, then press
SHIFT+ENTER
or press the play button in the toolbar above. Additionally, the Cell dropdown menu has several options to run cells, including running one cell at a time or running all cells at once.)
·
After running a cell, the output of the cell’s code will appear in
the space below.
·
To stop running a piece of code, press the stop button.
Adding some Markdown text
- ·
We can add text (and actually
pictures and video) to Jupyter notebooks.
For formatting or adding pictures and
videos:-
- ·
Use Markdown from the dropdown menu
in the toolbar.
- ·
Markdown is a popular markup
language, (simplified HTML).
- ·
Type up the Markdown content in VS
Code and then copy/paste it over into a Markdown cell than it is to type
directly in the Markdown cell in Jupyter.
·
To create new cells, use the
plus (+) button in the toolbar or hit SHIFT+ENTER
on the last cell in the Notebook.
·
To cut, copy, delete or just
generally edit cells - select the cell to modify and go to the Edit button
in the navigation bar.
·
Also include text-only cells
that use Markdown to format and organize notebooks.
·
To create a cell that uses
markdown, click on the Cell menu from the
navigation bar, scroll down to Cell Type and choose
Markdown.
·
For restart the kernel. Select
the Kernel dropdown and
hit Restart.
·
To shut down a kernel, click on
Shutdown.
·
In the Help dropdown,
find useful information such as keyboard shortcuts, links to different
documentation for modules such as Numpy, scipy, and Matplotlib.
·
The toolbar has
several shortcut buttons for popular actions.
·
From left to right: save, add a
new cell, cut selected cells, copy selected cells, paste cells below, move
selected cells up, move selected cells down, run, interrupt the kernel, restart
the kernel, a dropdown that allows you to change the cell type, and a shortcut
to open the command palette.
·
Jupyter Notebook files are saved
as we go.
·
They will exist in our directory
as a JSON file with the extension .ipynb
.
·
For the export of Jupyter Notebooks
in other formats, such as HTML. Go to the File menu, scroll down to Download
as, and select the type of file looking for.
·
A popup will appear asking where
would like this new file to download.
·
Navigated to the appropriate
directory, click Save and Checkpoint.
===================================
0 Comments