help()
?
?? 獲取源代碼
Tab鍵自動(dòng)探索代碼,快速補(bǔ)全
- 以%開始的函數(shù),成為魔法函數(shù),例如加了%的run可以運(yùn)行外部函數(shù)
#在外部新建一個(gè)test.py文件,寫入函數(shù)
def square(x):
return x ** 2
#運(yùn)行外部函數(shù)
%run test.py
調(diào)用外部函數(shù)
square(2)
out: 4
- timeit 用來測(cè)試一行Python語句的執(zhí)行時(shí)間
%timeit L = [n ** 2 for n in range(100)]
out:
22.5 μs ± 586 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
#%%timeit 用來測(cè)試多行Python語句的執(zhí)行時(shí)間
%%timeit
L = []
for n in range(100):
L.append(n ** 2)
out:
35 μs ± 690 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
# %debug 用來在交互環(huán)境中調(diào)試程序,運(yùn)行報(bào)錯(cuò)后開啟,打印一些參數(shù),可以快速找到錯(cuò)誤
%debug
# 查看所有魔法函數(shù)
%lsmagic
out:
Available line magics:
%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %conda
%config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist
%history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop
%ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile
%pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole
%quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc
%set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
Available cell magics:
%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl
%%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit
%%writefile
Automagic is ON, % prefix IS NOT needed for line magics.
!cd
out:D:\python-project\data_analysis\Jupyter_learning
- 異??刂?%xmode:可以在軌跡追溯中找到錯(cuò)誤的原因
# %xmode Plain 以緊湊的方式顯示異常信息
# %xmode Verbose 會(huì)自動(dòng)加入執(zhí)行過程中的額外參數(shù)信息,錯(cuò)誤信息更詳細(xì)
# 默認(rèn) xmode Content
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。