Introduction and simple use of jupyter notebook magic commands

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

image-20230903101736301

%quickref: Displays the IPython quick reference card.

%quickref

image-20230903101859681

?: View help for magic commands.

?

image-20230903102000595

%who: Display all variables in the interactive space.

%who

image-20230903102118388

%reset: Delete all variables in the interactive space.

image-20230903102218087

%xdel: Delete a variable in the interactive space.

image-20230903102328589

%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")

image-20230903101502860

%%timeit: Calculate the running time of a python statement.

%%timeit

print("Hello World")

image-20230903101619459

Guess you like

Origin blog.csdn.net/qq_63432403/article/details/132646144