我基本上是通過使用update
方法合併兩個字典。問題是當我在python shell
合併它的作品,但在執行時不在文件中。爲什麼在更新字典時得到None?
v = {'customer_id': '9000', 'customer_name': 'Apple Inc'}
b = {"a": "b"}
print v.update(b)
的上述輸出是None
但其在外殼的工作。我愚蠢的錯誤是什麼? Thankyou
我基本上是通過使用update
方法合併兩個字典。問題是當我在python shell
合併它的作品,但在執行時不在文件中。爲什麼在更新字典時得到None?
v = {'customer_id': '9000', 'customer_name': 'Apple Inc'}
b = {"a": "b"}
print v.update(b)
的上述輸出是None
但其在外殼的工作。我愚蠢的錯誤是什麼? Thankyou
v.update(b)
正在更新b 到位。 v
確實已更新,但更新函數的結果是None
,正是打印出的內容。如果你這樣做
v.update(b)
print v
你會看到v
(更新)
的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
好吧,謝謝 –
你是什麼意思在shell_ _working?即使是輸出「無」。 – JRodDynamite
@JasonEstibeiro檢查圖像 –
這是因爲你打印了'v'的值。作爲'v.update(b)'的輸出什麼都沒有。 – JRodDynamite