如何检索上一个命令的输出并将其保存在Python交互式shell中的变量中?

n00*_*hie 5 python python-interactive

假设我运行了一个昂贵的操作foo(),它返回一个大的列表,但我忘了将foo()的输出保存在变量中.

假设我再次运行foo(),我会得到一个不同的输出.

但是我第一次运行foo()时确实需要输出.

实际上,我问是否有一些缓冲区存储了最后一个命令的输出,我可以读取?

kha*_*hik 5

_ (单下划线)适用于我的python 3 for windows,也适用于其他版本:

>>> 1 + 1
2
>>> x = _
>>> x
2
Run Code Online (Sandbox Code Playgroud)