Output of Python Programs | Set 24 (Dictionary)
Prerequisite : Python-Dictionary
1. What will be the output?
dictionary = {"geek":10, "for":45, "geeks": 90}print("geek" in dictionary) |
Options:
- 10
- False
- True
- Error
Output: 3. True
Explanation: in is used to check the key exist in dictionary or not.
2. What will be the output?
dictionary ={1:"geek", 2:"for", 3:"geeks"}del dictionary |
Options:
- del deletes the entire dictionary
- del doesn’t exist for the dictionary
- del deletes the keys in the dictionary
- del deletes the values in the dictionary
Output: 1. del deletes the entire dictionary
Explanation: del deletes the entire dictionary and any further attempt to access it will throw an error.
3. What will be the output?
a = {}a[1] = 1a['1'] = 2a[1]= a[1]+1count = 0for i in a: count += a[i]print(count) |
Options:
- 4
- 2
- 1
- Error
Output: 1. 4
Explanation: The above piece of code basically finds the sum of the values of keys.
4. What will be the output?
test = {1:'A', 2:'B', 3:'C'}del test[1]test[1] = 'D'del test[2]print(len(test)) |
Options:
- 2
- 1
- 0
- Error
Output: 1. 2
Explanation: After the key-value pair of 1:’A’ is deleted, the key-value pair of 1:’D’ is added.
5. What will be the output?
a ={}a['a']= 1a['b']=[2, 3, 4]print(a) |
Options:
- {‘b’: [2], ‘a’: 1}
- {‘a’: 1, ‘b’: [2, 3, 4]}
- {‘b’: [2], ‘a’: [3]}
- Error
Output:
2. {'a': 1, 'b': [2, 3, 4]}Explanation: Mutable members can be used as the values of the dictionary but they cannot be used as the keys of the dictionary.


