frostime 2019-11-01
帮助
? ##Ipython的概述和简介
help(name) ##查询指定名称和帮助
obj? ##列出obj对象的详细信息
obj?? ##列出更详细的信息
特殊变量
_表示前一次输出
__表示前二次输出
___表示前三次输出
_oh 输出历史
_oh {4: 100, 5: 100, 6: 100, 10: [1, 2, 3, 4]} c=_ c [1, 2, 3, 4]
pwd 当前目录
_dh 目录历史
pwd ‘C:\\Users\\Administrator‘ cd c:c: _dh [‘C:\\Users\\Administrator‘, ‘c:\\‘]
shell命令
!command调用shell命令
!ls ‘ls‘ is not recognized as an internal or external command, operable program or batch file. !dir Volume in drive C has no label. Volume Serial Number is A494-4369 Directory of c: 2019/10/12 17:34 <DIR> FusionCloud6.1 2019/10/15 16:33 <DIR> installtool 2019/10/28 15:16 <DIR> Program Files 2019/10/31 18:02 <DIR> Program Files (x86) 2019/08/12 14:45 <DIR> Users 2019/10/31 17:55 <DIR> vms 2019/11/01 09:25 <DIR> Windows 0 File(s) 0 bytes 8 Dir(s) 29,517,729,792 bytes free
魔术方法
使用%百分号开头,IPython内置的特殊方法
%magic格式
%开头是line magic
%%开头是cell magic
%timeit statement
def primenumber(): n=9 row=[1]*n ##一次性开辟全部空间 for i in range(n): old=1 for j in range(i//2): va=old+row[j+1] old=row[j+1] ##row[j+1]将被覆盖,通过变量old先将row[j+1]保留 row[j+1]=va if i !=2*(j+1): row[i-(j+1)]=row[j+1] else: pass # print(‘***‘) # print(row[:i+1]) ##切片打印列表 %timeit primenumber() 16.7 µs ± 348 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%%timeit setup_code
%%timeit n=9 row=[1]*n ##一次性开辟全部空间 for i in range(n): old=1 for j in range(i//2): va=old+row[j+1] old=row[j+1] ##row[j+1]将被覆盖,通过变量old先将row[j+1]保留 row[j+1]=va if i !=2*(j+1): row[i-(j+1)]=row[j+1] else: pass # print(‘***‘) # print(row[:i+1]) ##切片打印列表 17.4 µs ± 1.69 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)