2016-04-01 21 views
1

enter image description here我基本上是通過使用update方法合併兩個字典。問題是當我在python shell合併它的作品,但在執行時不在文件中。爲什麼在更新字典時得到None?

v = {'customer_id': '9000', 'customer_name': 'Apple Inc'} 
b = {"a": "b"} 

print v.update(b) 

的上述輸出是None

但其在外殼的工作。我愚蠢的錯誤是什麼? Thankyou

+1

你是什麼意思在shell_ _working?即使是輸出「無」。 – JRodDynamite

+0

@JasonEstibeiro檢查圖像 –

+0

這是因爲你打印了'v'的值。作爲'v.update(b)'的輸出什麼都沒有。 – JRodDynamite

回答

5

v.update(b)正在更新b 到位v確實已更新,但更新函數的結果是None,正是打印出的內容。如果你這樣做

v.update(b) 
print v 

你會看到v(更新)

3

update函數返回None。所以

print v.update(b) # this is printing out the return value of the update function. 

要打印出字典的更新值,只是打印的字典再次

print v # This will print the updated value of v 
+0

好吧,謝謝 –

相關問題