Jupyter 简明教程

Jupyter Notebook - Markdown Cells

Markdown 单元格显示可以使用 markdown 语言设置格式的文本。为了输入不应被笔记本服务器视为代码的文本,必须首先从单元格菜单中或在命令模式下使用键盘快捷键 M 将其转换为 markdown 单元格。单元格前的 In[] 提示会消失。

Markdown cell displays text which can be formatted using markdown language. In order to enter a text which should not be treated as code by Notebook server, it must be first converted as markdown cell either from cell menu or by using keyboard shortcut M while in command mode. The In[] prompt before cell disappears.

Header cell

markdown 单元格可以显示 6 种大小的标题文本,类似于 HTML 标题。通过 # 符号在 markdown 单元格中开始文本。使用与您想要标题的级别相对应的尽可能多的 # 符号。这意味着单个 # 将呈现最大的标题行,六个 # 符号呈现最小字体大小的标题。当您从单元格菜单或工具栏的运行按钮运行单元格时,将进行呈现。

A markdown cell can display header text of 6 sizes, similar to HTML headers. Start the text in markdown cell by # symbol. Use as many # symbols corresponding to level of header you want. It means single # will render biggest header line, and six # symbols renders header of smallest font size. The rendering will take place when you run the cell either from cell menu or run button of toolbar.

以下屏幕截图显示了带有三个不同级别的标题的编辑模式下的 markdown 单元格。

Following screenshot shows markdown cells in edit mode with headers of three different levels.

markdown cells three levels

当单元格运行时,输出如下 −

When cells are run, the output is as follows −

markdown cells output

请注意,Jupyter 笔记本标记语言不支持 WYSWYG 功能。只有在运行标记单元格后才会呈现格式化效果。

Note that Jupyter notebook markdown doesn’t support WYSWYG feature. The effect of formatting will be rendered only after the markdown cell is run.

Ordered Lists

若要按 HTML 的 <ol> 标签的原理呈现带序号的列表,列表中的第一项应编为 1。后续各项可以编为任意数字。运行标记单元格后,这些数字将按顺序呈现。若要显示缩进列表,请按 Tab 键,并以每个子列表中的 1 开头。

To render a numbered list as is done by <ol> tag of HTML, the First item in the list should be numbered as 1. Subsequent items may be given any number. It will be rendered serially when the markdown cell is run. To show an indented list, press tab key and start first item in each sublist with 1.

如果您为标记语言输入以下数据:

If you give the following data for markdown −

ordered lists

将显示以下列表:

It will display the following list −

ordered list output

Bullet lists

列表中的每一项都会显示一个实心圆圈,如果它以 – 符号开头,而如果列表以 * 符号开头,则会显示实心方块符号。以下示例解释了此功能 −

Each item in the list will display a solid circle if it starts with – symbol where as solid square symbol will be displayed if list starts with * symbol. The following example explains this feature −

bullet lists

呈现的降价以如下显示 −

The rendered markdown shows up as below −

bullet lists output

使用 http 或 https 开头的降价文本自动呈现超链接。若要将链接附加到文本上,请将文本放在方括号 [] 中并将其放在圆括号 () 中(可选地包括悬停文本)。以下屏幕截图对此进行了说明。

Markdown text starting with http or https automatically renders hyperlink. To attach link to text, place text in square brackets [] and link in parentheses () optionally including hovering text. Following screenshot will explain this.

including hyperlink

呈现的降价以如下显示 −

The rendered markdown appears as shown below −

hyperlink included

Bold and Italics

若要以粗体显示文本,请将其放在双下划线或两个星号之间。若要以斜体显示,请将其放在单下划线或单个星号之间。

To show a text in bold face, put it in between double underscores or two asterisks. To show in italics, put it between single underscores or single asterisks.

applying bold italics

结果以如下所示 −

The result is as shown below −

bold italics output

Images

若要在降价单元格中显示图片,请从编辑菜单中选择“插入图片”选项,然后浏览到需要的图片文件。降价单元格显示其语法如下 −

To display image in a markdown cell, choose ‘Insert image’ option from Edit menu and browse to desired image file. The markdown cell shows its syntax as follows −

logo attachment

图片将在笔记本上呈现如下所示 −

Image will be rendered on the notebook as shown below −

jupyter logo

Table

在降价单元格中,可以使用 |(管道符号)和 –(破折号)来构造表格,以标记列和行。请注意,在键入时符号不必完全对齐。它只需占据列边框和行边框的相应位置即可。笔记本将根据内容自动调整大小。表格构造如下所示 −

In a markdown cell, a table can be constructed using | (pipe symbol) and – (dash) to mark columns and rows. Note that the symbols need not be exactly aligned while typing. It should only take respective place of column borders and row border. Notebook will automatically resize according to content. A table is constructed as shown below −

table construction

输出表格将呈现如下所示 −

The output table will be rendered as shown below −

table output