5 tips for using Jupyter Notebook

Hello, I am Xiao Wu 🧐

After learning Python and becoming proficient, people tend to choose a more specialized IDE (PyCharm, etc.). But if you are familiar with me, you will notice that The fifth daughter often uses a Jupyter Notebook.

This is because I find it to be an efficient tool for both Python programming and writing!

This article will introduce some interesting and useful tips for using Jupyter Notebook

Quickly open Jupyter

First tip, how do I quickly open Jupyter Notebook?

This is really easy, you can choose to double click the app icon, but then open the default path.

Alternatively, from the command line, type: jupyter notebook and press Enter.

To specify a path, run the CD command to go to the target path and then perform the preceding step to quickly open the Jupyter Notebook in the specified folder.

But still a little trouble, fortunately I sorted out a simpler way, click on the blue words below to see the skills.

How to quickly open jupyter Notebook in a specified folder

Go all the way to the bottom and double-click directly to open the.ipynb file

shortcuts

We all know the importance of shortcuts, and mastering them can greatly improve our productivity.

  • Press theEscKey to enter the command mode
  • Press theHKey to enter editing mode

Jupyter notebooks have two different keyboard input modes. Edit mode allows you to enter code or text into a cell and is represented by a green cell.

Command mode binds the keyboard to note-level commands and displays it through a gray cell border with a blue left border.

How do I see all the shortcuts?

Press Esc + H at the same time to bring up the shortcut keys as shown below.

Common Shortcut keys

Here are some of the most common shortcuts

When the cell is in command mode (the left box of the cell is blue), you can use the following shortcut keys.

  • According to theaKey to generate a new cell in front of the current cell
  • According to thebKey to generate a new cell after the current cell
  • According to thexKey to delete the current cell
  • According to thezKey to restore the cell you just deleted

Markdown

As mentioned earlier, Fifth regards Jupyter Notebook as an efficient tool for both Python programming and writing. The biggest reason is that it is perfectly compatible with Markdown, which makes it easy to add text annotations, mind maps, etc.

When the cell is in edit mode (that is, the left box of the cell is green), the default is code format.

If you want to use Markdown, you can manually select the format of the cell to be Markdown on the menu bar.

However, this method is not recommended, you can use the shortcut keys.

  • According to theyKey to switch to code format
  • According to themKey to switch to Markdown format

Edit multiple lines at once

The copied code or Text will have parts that need to be adjusted, and I used to prefer Sublime Text for this.

The Jupyter Notebook can also edit multiple lines at the same time by pressing Alt and then using the left mouse button.

Save time and effort.

Output multiple variables

Running Python code in Jupyter Notebook outputs only the result of the last variable by default.

If I print a lot of print, it’s not very elegant. Then I saw a way: set InteractiveShell. Astnodeinteractivity parameter to all.

from IPython.core.interactiveshell import InteractiveShell 
InteractiveShell.ast_node_interactivity = 'all'
Copy the code

This allows all variables or declarations to be displayed.

Ok, today I just introduced 5 tips for using the Jupyter Notebook. For more on magic commands and various useful plugins, we’ll continue in amway next

Don’t forget to give this article a thumbs up at 👍 if you have some tips to help you increase your productivity