CBSE Class 12 Computer Science Question 90 of 105

Python Revision Tour II — Question 17

Back to all questions
17
Question

Question 10

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())
Answer
Output
dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])
Explanation

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')].