我剛剛在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'>
你可以在你的口譯員試試這個;在這裏工作沒有任何竅門!
最後執行的行的結果是否分配給名爲_
的變量?
有人知道嗎?有沒有關於它的文檔?在哪種情況下可能有用?
我想大家都知道(和使用)這...... – JBernardo 2012-01-31 01:37:19
精確複製http://stackoverflow.com/questions/1538832/is-this-single-underscore-a-built-in-variable-in-python – 2012-01-31 01:38:12
我爲什麼被低估? – juliomalegria 2012-01-31 01:38:24