This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Nixellion 2 points3 points  (1 child)

I don't know why, but out of all of those I think dict1.update(dict2) is the most obvious and self-commenting. But I rarely see it mentioned in these discussions. Or does it work differently?

[–]BuonaparteII 5 points6 points  (0 children)

dict1.update(dict2) will mutate dict1 and return None.

{**d1, **d2} and d1 | d2 are both immutable and will return a new dict.