Dremendo Tag Line

Change value of a key in a dictionary in Python

Dictionaries - Question 1

In this question, we will see how to change the value of a key in a dictionary in Python programming. To know more about dictionaries click on the dictionaries lesson.

A dictionary is given below as:

    a={'english':56, 'maths':84, 'physics':92, 'computer':76, 'history':87}

Q1) Write a program in Python to change the marks of the subject history to 59 in the dictionary a. The output should be:

   {'english':56, 'maths':84, 'physics':92, 'computer':76, 'history':59}

Program

a={'english':56, 'maths':84, 'physics':92, 'computer':76, 'history':87}
print('Dictionary a:')
print(a)
a['history']=59
print('\nDictionary after update')
print(a)

Output

Dictionary a:
{'english': 56, 'maths': 84, 'physics': 92, 'computer': 76, 'history': 87}

Dictionary after update
{'english': 56, 'maths': 84, 'physics': 92, 'computer': 76, 'history': 59}
video-poster