设置一个cell多个输出,不用print()也行。
jupyter notebook 的一个cell中,如果直接写多个对象,则只有最后一个对象会被输出,前面变量不会被输出:
![](https://img.haomeiwen.com/i14029140/da06250da2aed197.png)
虽然可以用print()打印出每个对象,但是“用print()”和“直接写对象”两者的输出效果可能不同,比如pandas对象,直接以变量的形式输出就是漂亮的表格形式,但是用print()函数输出就比较丑陋。
为了解决该问题,可以导入下面信息:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
![](https://img.haomeiwen.com/i14029140/b16be6baeda47956.png)
网友评论