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 doesn’t exist for 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}
- {‘b’: [2, 3, 4], ‘a’: 1}
- {‘b’: [2], ‘a’: [3]}
- Error
Output:
2. {‘b’: [2, 3, 4], ‘a’: 1}
Explanation: Mutable members can be used as the values of the dictionary but they cannot be used as the keys of the dictionary.
Recommended Posts:
- Output of Python Programs | (Dictionary)
- Output of Python programs | Set 9 (Dictionary)
- Output of Python Programs | Set 22 (Loops)
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Python Dictionary
- Python | Get key from value in Dictionary
- Python | Accessing Key-value in Dictionary
- Python Dictionary Comprehension
- Python | Key index in Dictionary
- Python Dictionary clear()
- Python | Get key with maximum value in Dictionary
- Python | Transcribing dictionary key
- Python | Add new keys to a dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



