10

enter image description hereI 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

Nikhil Parmar
  • 876
  • 2
  • 11
  • 27

2 Answers2

16

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)

Mathias711
  • 6,568
  • 4
  • 41
  • 58
6

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
Saif Asif
  • 5,516
  • 3
  • 31
  • 48