How I use Jupyter Notebook

How I use Jupyter Notebook

I previously wrote about how I became a note-taker and in that post I mentioned my current method of taking notes is to use Jupyter Notebooks. This is going to be a detailed look at how exactly I use them.

What is a Jupyter Notebook?

Jupyter Notebook is an open source document format which includes the ability to write plain-text, Markup, and executable code all in one document. Notebook files end ".ipynb" (e.g. mynotebook.ipynb) and the default programming language of the notebooks is Python but you can install "kernels" which give you access to many more.

How do I install it?

Well, first of all, there are online "binders" which allow you to run Notebook in your browser. So, if you just want to fiddle around and see how it works that's probably your best bet.

If you definitely want to install on your computer there are a number of ways but in my opinion the most user-friendly (and the most consistent across different Operating Systems) is Anaconda.

Anaconda comes with Jupyter Notebook by default so once you've got Anaconda successfully installed you've also got Jupyter. You can access it by running Anaconda-Navigator from your Windows/Mac app menu or running `anaconda-navigator` from a Linux terminal.

Installing on Linux

The install process for Linux is slightly different as it's done via CLI (command line interface, or terminal). I've done this on Debian/Ubuntu-based and Arch-based systems without any issues.

  • Install the dependencies (select what version of linux you're on in the documentation to get the specifics). For my standard 64bit PC that'd be here.
  • Download the appropriate script (for a normal 64bit computer that'd be "64-Bit (x86) Installer")
  • Open a terminal (Super/Meta/Cmd/Win+t on many distros, Ctrl+Alt+t on others)
  • Navigate to the directory you downloaded it to using cd <directory>. For me that was my Downloads folder so the command was "cd Downloads"
  • It's recommended to validate the SHA-256 hash of the file (details here). For my 64bit PC that was simply running "sha256sum Anaconda3-2021.05-Linux-x86_64.sh" in terminal (after navigating to the Downloads folder) and validating the output against this page.
  • Assuming the hash matches you can then run "bash <file you downloaded>" in terminal (I've also used "zsh <file>" on a system where I was using ZShell and it executed perfectly). So, in my case the command was "bash Anaconda3-2021.05-Linux-x86_64.sh".
  • You'll first get some T&Cs to agree to. Hit spacebar until you see the "yes|no" prompt and type "yes".
  • Next it'll ask if the default directory it's selected is ok (if you're not sure just stick with the default).
  • Finally, it'll ask if you want it to run "conda init" for you (in most cases you'll want to type "yes").

How do I use it?

Upon first launch you should see something like this:

The default view when you launch Jupyter Notebook

The default folder is your computer's home folder and if you're happy to have your files live there you can just click "New" on the top right (beside "Upload"). Personally, I tend to create a folder in my Documents directory to keep all my notebooks in.

Once you've created a new notebook you'll see this (lets assume we're using Python for now):

The default empty notebook view when you create a new Python3 notebook

That little textbox with "In []:" before it is a cell. If you want to jump into coding straight away you can, as each cell is in Code-mode by default (what language will depend on the kernel you're using but Python is the default).

Close-up of notebook cell in Code mode.


You can change from code mode easily by either clicking the dropdown that says "Code" and selecting "Markdown" or by hitting "m" on your keyboard. When you've change a cell to Markdown-mode "In []:" disappears from in front of the cell:

Close-up of notebook cell in Markdown mode.

One of the wonderful things about these notebook is you can run whatever code you type in a cell without having to save the file or leave the notebook at all. In you're newly opened Python notebook lets import randint and print something out:

Jupyter Notebook cell with some simple Python code


Now you can either click "Run" from the menu or just hit Shift+Enter on your keyboard (this executes the current cell and creates a new blank cell below) and the output will appear just below the cell:

The same Jupyter cell with the output from the Python code displayed: "I just imported randint and here's a random integer: 6""


Ok, cool. What about Markdown?

If you've converted a cell to markdown-mode using either the menubar or keyboard shortcut ("m" when you have the cell selected but not entered, blue line=selected, green line=entered) you can start typing raw markdown:

A notebook cell with raw markdown

When you click "Run" in the toolbar (Shift+Enter on keyboard) the cell will swith to showing you the nicely formatted markdown:

A notebook cell with formatted markdown

Putting it together

Ok, that's the basics of using Jupyter Notebooks so how do I specifically use them? I pretty much just combine those two functions, markdown & code, and create tutorials for myself about whatever the topic I'm studying is. For example here's a snippet of my python3_lambda-functions notebook:

A notebook with a mixture of markdown and code cells showing lambda functions

Jupyter keyboard shortcuts: cheatsheet

My most used keyboard shortcuts are:

  • m - converts currently selected cell to markdown mode
  • y - converts currently selected cell to code mode
  • dd - deletes the currently selected cell
  • x - cut the currently selected cell
  • c - copy the currently selected cell
  • v - paste below
  • Shift+v - paste above
  • a - insert new blank cell above
  • b - insert new blank cell below
  • z - undo the last action
  • Ctrl+Enter - run the current cell
  • Shift+Enter - run the current cell and create a new cell below

Markdown basics: Cheatsheet

Below are my most used markdown items. For a more complete list see here.

  • # One hash symbol is Heading 1
  • ## Two hashes is Heading 2
  • ### Three hashes is Heading 3 and so on...
  • __bold text__ double-underscore before & after text makes the text bold
  • *italic* single asterisk before & after text makes text italic
  • [link](url) Square brackets around text makes the text a link and round brackets immediately after sets the destination URL
  • `code` backtick/grave (on my keyboard that's the same key as the weird little reversed sideways L and the pipe symbol "|") nicely formats the encased text like a code sample
  • - hyphens make list items
  • ~strikethrough~ tilda before & after text will give you a strikethrough

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics