Add a key

EasyDictionary Programs · 13 of 94

Write a Python program to add a key to a dictionary.

Advertisement
Input
{1: "a", 2: "b"}
Output
{1: 'a', 2: 'b', 3: 'c'}

Approach

  1. Assign to the new key.

Solution

Python
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.

More dictionary programs

← All 94 Dictionary Programs

Leave a Comment