jupyter notebook基本用法

  • jupyter notebook介绍
  • 打开anaconda命令行
  • 创建文件
  • 用法及快捷键
  • 命令提示


jupyter notebook介绍

jupyter notebook(也叫IPython notebook)是一个交互式笔记本。
Jupyter Notebook 的本质是一个 Web 应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。
有很多集成库内包含jupyter notebook,例如sagemath,anaconda
本文使用anaconda自带的jupyter notebook。

打开anaconda命令行

jupython notebook在线 jupyter notebook_jupython notebook在线


在这里你可以调整目录,规定notebook打开的路径后输入jupyter notebook

jupython notebook在线 jupyter notebook_anaconda_02


按回车等待打开,会弹出web页面

jupython notebook在线 jupyter notebook_jupython notebook在线_03


因为路径是c盘,所以c盘文件都显示其中。

创建文件

jupython notebook在线 jupyter notebook_python_04


点击New键,选择python3(python3环境), 将会添加新文件

jupython notebook在线 jupyter notebook_tensorflow_05


一个新文件就如图,每一个单元格作为一个整体,运行代码时也是一个单元格一个单元格进行,极大的方便调试。

用法及快捷键

jupython notebook在线 jupyter notebook_python_06


可以在单元格中输入python代码,输入完一句或多句代码后 按SHIFT+ENTER键运行当前单元格代码并目标指向下一单元格,单元格前面的In [ ]指的是运行的次序。也可使用Alt+Enter单纯的运行本单元格。

notebook使用有些类似于vim,按ESC后进入非选定模式,可以按dd来删除光标所在单元格,A向光标所在单元格上方添加单元格,B向下添加,M使得单元格变成markdown状态

jupython notebook在线 jupyter notebook_tensorflow_07


当然如果不想使用快捷方式,可以使用按键。

jupython notebook在线 jupyter notebook_创建文件_08


这些功能都能实现。

另外运行单元格时可以使用CTRL+C打断运行,或者点击Kernel中的interrupt

jupython notebook在线 jupyter notebook_创建文件_09

命令提示

notebook中的命令提示非常方便,例如我输入numpy库中的方法,输入np.再按TAB键即可查看。

jupython notebook在线 jupyter notebook_创建文件_10


当函数参数不知道时,在括号中使用CTRL+TAB一次或多次查看提示的简略与详细

jupython notebook在线 jupyter notebook_jupython notebook在线_11

jupyter notebook 的基本用法就是这些,足够我们写代码使用啦。