• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
November 25, 2022 |2.1K Views
Python program to Add key:value pair to dictionary
  Share  3 Likes
Description
Discussion

In this video, we'll write a Python program to add a key:value pair into a dictionary. 

Approaches to Add Key:Value Pair into a Dictionary

1. Using dictionary subscript notation. 
2. Using dictionary update() method. 

Method 1: Using dictionary subscript notation: In this method, we can directly assign a value to any new key placed inside square brackets, to create a new key:value pair in the dictionary. 

Method 2: Using dictionary update method: In this method, we update a dictionary with another dictionary. dictionary update() function updates the dictionary inplace with the new key:value pairs from the dictionary passed as a parameter to the update function.

Python program to add key:value pair into a dictionary: https://www.geeksforgeeks.org/add-a-keyvalue-pair-to-dictionary-in-python/

Read More