Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Jupyter Notebook Usage

Jupyter Notebook Usage

In the previous chapter we finished installing Jupyter Notebook.

Once installation is complete, let us start it right away and see what this smart notebook looks like.

1. Starting Jupyter Notebook

First, in the command line, switch to the directory where you want to keep your future notebook project files. For example, if you want to work in the my_jupyter folder on your desktop:



# Windows example

cd C:\Users\你的用户名\Desktop\my_jupyter



# macOS/Linux example

cd ~/Desktop/my_jupyter

Then enter the startup command:



jupyter notebook

After pressing Enter, two things happen:

The command line window starts running a server (do not close this window).

Your default web browser (such as Chrome or Firefox) automatically opens a new page, usually at http://localhost:8888, and this is the Jupyter Notebook dashboard

Now you can click File -> New -> Notebook to create a notebook:

You can also use the following method.

2. Create your first notebook

In the browser page that opened (the dashboard):

3. Write and run your first piece of code

What you see now is a cell, the core of a Notebook.

You will immediately see the output below the cell Hello, Jupyter! I am from Runoob!, and the interface automatically creates a second empty cell for you.

When it finishes, a new cell is generated; paste the following code into it:

Example

This is a code cell

print

(

"Hello, Jupyter!"

)

print

(

"1 + 2 ="

,

1

2

)

Try running this cell (Shift+Enter) and see the result!

Expected output:

Hello, Jupyter!

1 + 2 = 3

4. Understanding cell types

Cells have two main modes (switch between them with the toolbar drop-down):

Try changing a new cell's type to Markdown, then enter ## 这是我的数据分析项目and run it to see the effect.

5. Saving and closing