先執行:
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 后,即可直接多行結果輸出。