I am basically merging two dictionaries by using update
method. The problem is when I merge in python shell
it works but not in a file while executing.
v = {'customer_id': '9000', 'customer_name': 'Apple Inc'}
b = {"a": "b"}
print v.update(b)
output of above is None
but its working in shell. What's my silly mistake? Thankyou
v.update(b)
is updating b in place. v
is indeed updated, but the result of the update function is None
, exactly what is printed out. If you do something like
v.update(b)
print v
you'll see v
(updated)
The update
function returns None
. So
print v.update(b) # this is printing out the return value of the update function.
To print out the updated value of the dict, just print the dict again
print v # This will print the updated value of v
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With