How can you merge two dictionaries in Python?

  • dict1.add(dict2)
  • dict1.concat(dict2)
  • dict1.extend(dict2)
  • dict1.update(dict2)
To merge two dictionaries in Python, you can use the update method. This method updates the first dictionary with the key-value pairs from the second dictionary. It is the recommended way to merge dictionaries in Python. The other options are not valid methods for merging dictionaries.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *