Python Practice › Dictionary Programs › Program 13
Add a key
Write a Python program to add a key to a dictionary.
Input
{1: "a", 2: "b"}Output
{1: 'a', 2: 'b', 3: 'c'}Approach
- Assign to the new key.
Solution
d = {1: "a", 2: "b"}d[3] = "c"print(d)Output
{1: 'a', 2: 'b', 3: 'c'}Learn the concept
New to this topic? Read the lesson, then come back.