我學習Python和我通過一個示例腳本,其中包括一些變量定義看起來像閱讀:var,_ =在Python中的含義是什麼?字符串連接?
output,_ = call_command('git status')
output,_ = call_command('pwd')
def call_command(command):
process = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return process.communicate()
如果我打印輸出我得到所產生的外殼輸出串在一起,所以我知道這是串聯的變量。但是我無法在任何文檔中找到任何對_的約定。有人可以向我解釋這一點,以便我確切知道我正確使用它嗎?
「變量定義」?哪有這回事。他們只是賦值語句。 – 2012-01-30 20:51:00
假設'_'未被使用,一個更清晰的寫入語句的方法是'output = call_command('pwd')[0]' – gahooa 2012-01-30 21:00:18