w3resource logo


Python Exercises

Python Exercise: Program to add key to a dictionary


Write a Python program to add key to a dictionary.

Sample Dictionary : {0: 10, 1: 20}
Expected Result : {0: 10, 1: 20, 2: 30}

Sample Solution :

Python Code :

d = {0:10, 1:20}
print(d)
d.update({2:30})
print(d)

Console :

Copy and paste the above code and press "Enter key" to execute :

Post your code through Disqus