In Jupyter notebooks, "magic commands" are special commands that are not part of the Python language but can make your life easier. These commands are preceded by the % symbol.
Magic commands are useful and can be embedded directly into Python code and solve common problems, such as listing all files in the current directory or changing the current working directory.
%magic
: Shows all available magic commands.
%magic
%quickref
: Displays the IPython quick reference card.
%quickref
?
: View help for magic commands.
?
%who
: Display all variables in the interactive space.
%who
%reset
: Delete all variables in the interactive space.
%xdel
: Delete a variable in the interactive space.
%run
:Run the python script in the current kernel.
# 需要重新导入lab.py要使用的包和变量
%run lab.py
# 共享包,变量
%run -i lab.py
%time
: Calculate the running time of a line of Python statements.
%time
print("Hello World")
%%timeit
: Calculate the running time of a python statement.
%%timeit
print("Hello World")