The following exercises cover Dictionaries in Python.
Exercise 1
Complete the syntax to create a dictionary, myDictionary
.
myDictionary = 'name': 'Ram', 'age': 12
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 2
Print the value for key 'name'
in the dictionary.
myDictionary = { 'name': 'Ram', 'age': 12 } print(myDictionary[])
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 3
Update the value for key ‘age’ with a value of 13.
myDictionary = { 'name': 'Ram', 'age': 12 } myDictionary[] =
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 4
Add a new key-value pair to the dictionary where key is'place'
and value is 'India'
.
myDictionary = { 'name': 'Ram', 'age': 12 } myDictionary[] =
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 5
Remove the key-value pair from dictionary whose key is 'name'
. You may refer Delete key-value from Dictionary.
myDictionary = { 'name': 'Ram', 'age': 12 } myDictionary.()
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 6
Iterate over items in the dictionary using For loop.
myDictionary = { 'name': 'Ram', 'age': 12 } for key, value : print(key, value)
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.