先执行:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
永久更改方法:
在修改默认目录时,cmd执行: jupyter notebook --generate-config 时,生成的文件夹 .ipython 中,
进入路径:C:\Users\Administrator\.ipython\profile_default ,新建文件:ipython_config.py
输入内容:
c = get_config()
c.InteractiveShell.ast_node_interactivity = "all"
保存,关闭文件。
重启 Jupyter notebook 后,即可直接多行结果输出。