使用快捷键

熟练使用快捷键能大幅提升开发效率

查看快捷键清单:

Help->Keyboard Shortcuts

The Jupyter Notebook has two different keyboard input modes. Edit mode allows you to type code/text into a cell and is indicated by a green cell border. Command mode binds the keyboard to notebook level actions and is indicated by a grey cell border with a blue left margin.

Jupyter 有两种模式,编辑模式和命令模式,以后可以在命令模式下直接按 H 来查看快捷键清单


学习Markdown

学会 Markdown 可以边学边记

下面看看 Markdown 能干些什么

用LaTeX写公式

$J(\theta_0,\theta_1)=\frac{1}{2m}$

显示代码

print('hello python')

显示HTML

A 星期二 星期三
李强 张明 王平

问号(?)

  • ? 显示文档
  • ??显示源码(如果有)
  • 用于搜索

In [1]:
print?
# 等同
# ?print

In [2]:
pwd??
# 等同
# ??pwd
# ??%pwd
# %pwd??

In [3]:
p*?
# 等同
# ?p*

叹号(!)

执行shell命令


In [4]:
!pwd


/Users/suconglin/Projects/GitHub/hello-python/jupter

百分号(%)

魔法命令 magic command

下面简单介绍一下

查看所有魔法命令


In [5]:
%magic

调试程序


In [6]:
def test():
    raise NotImplementedError()

test()


---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-6-5c39f7bbfc81> in <module>()
      2     raise NotImplementedError()
      3 
----> 4 test()

<ipython-input-6-5c39f7bbfc81> in test()
      1 def test():
----> 2     raise NotImplementedError()
      3 
      4 test()

NotImplementedError: 

In [7]:
%pdb on


Automatic pdb calling has been turned ON

In [8]:
test()


---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-8-ea594c21b25d> in <module>()
----> 1 test()

<ipython-input-6-5c39f7bbfc81> in test()
      1 def test():
----> 2     raise NotImplementedError()
      3 
      4 test()

NotImplementedError: 
> <ipython-input-6-5c39f7bbfc81>(2)test()
      1 def test():
----> 2     raise NotImplementedError()
      3 
      4 test()

ipdb> exit

In [9]:
%pdb off


Automatic pdb calling has been turned OFF

计时


In [10]:
%timeit pass


100000000 loops, best of 3: 11.5 ns per loop