命令:jupyter notebook
这个命令可以启动jupyter的交互服务器,并且把当前目录作为映射打开一个web界面,加载映射的目录结构
【注意】如果这个命令提示错误,检测环境变量还有anaconda是否安装完全(如果不完全:手动安装pip install jupyter)
In [ ]:
In [1]:
help(len)
In [2]:
help(list)
In [3]:
len?
In [4]:
list??
?显示这个函数的帮助文档,“??”显示帮助文档和源码(如果不开源则不显示)
In [5]:
def sqaure(a):
"求平方"
return a**2
In [6]:
sqaure??
In [7]:
import
pass
In [8]:
%run hello.py
In [9]:
hello()
In [10]:
a
Out[10]:
当魔法指令运行一个外部文件以后,该文件的函数就可以在cell会话中使用
%time python语句
查看程序运行的时间
In [11]:
%time print("hello")
In [12]:
def func1():
res = 0
for i in range(0,1000):
res += 1
for j in range(1000):
res -= 1
In [13]:
%time func1()
%timeit statement 用于计算statement的平均运行时间 %timeit 会多次运行statement,最后得到一个比较准确的运行时间
In [14]:
%timeit func1()
%%timeit 可以测试多行代码的平均运行时间 %%timeit statement1 statement2 ...
In [15]:
%%timeit
print("xxxx")
func1()
len([1,1,2,4,5])
%time 一般用于耗时比较长的代码段
%timeit 一般用于耗时比较短的代码段
In [ ]:
查看单签会话的所有变量与函数的详细信息 %whos
In [16]:
%whos
In [17]:
%who_ls
Out[17]:
In [18]:
!ipconfig
In [19]:
!cd ..
In [ ]:
列出所有的魔法指令 %lsmagic
In [20]:
%lsmagic
Out[20]:
In [21]:
%cd?
In [ ]:
1、命令模式
enter: 转入编辑模式
shift+enter:运行本行,并且选中下行
ctrl+enter: 运行本行,并且选中本行
alt+enter:运行本行,并且插入一个新的cell
Y:cell转入代码状态
M:cell转入Markdown状态
A: 在上方插入一个新的cell
B:在下方插入一个新的cell
编辑模式下:
tab(或shift+tab)键:提示
ctrl+a:全选当前cell
ctrl+z:撤销
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: