变量分配给最后执行的行?

jul*_*ria 1 python interpreter

我刚刚在Python解释器中发现了一些奇怪的东西.让我演示给你看:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> 5 + 4
9
>>> _
9
>>> 'Hello world'
'Hello world'
>>> _
'Hello world'
>>> type(3.5)
<type 'float'>
>>> _
<type 'float'>
Run Code Online (Sandbox Code Playgroud)

你可以在翻译中试试这个; 这里没有招数!

最后执行的行的结果是否被赋值给名为_?的变量?

有人知道吗?有没有关于它的文件?在哪种情况下它可能有用吗?

Ran*_*Rag 6

看看这里保留标识符python.

特殊标识符_用于交互式解释器中以存储上次评估的结果; 它存储在 内置模块中.

这种行为也可以在haskell的交互式环境中找到ghci.在这里而不是_使用it.

Prelude> 2+2
4
Prelude> it
4
Run Code Online (Sandbox Code Playgroud)