KnowledgeBoat Logo

Class - 12 CBSE Computer Science Important Output Questions 2025

Write the output of the code given below :

my_dict = {"name" : "Aman", "age" : 26} 
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())

Python

Python Dictionaries

4 Likes

Answer

dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])

Working

A dictionary my_dict with two key-value pairs, 'name': 'Aman' and 'age': 26 is initialized. Then updates the value associated with the key 'age' to 27. Then adds a new key-value pair 'address': 'Delhi' to the dictionary my_dict. The items() method returns all of the items in the dictionary as a sequence of (key, value) tuples. In this case, it will print [('name', 'Aman'), ('age', 27), ('address', 'Delhi')].

Answered By

3 Likes