Python Dictionary MCQs with answers
78 questions tagged Python Dictionary, each with the correct answer and an explanation. Page 1 of 4.
- How would you access the last inserted key-value pair in a dictionary?
- What will be the output of `sorted({'b': 2, 'a': 1})`?
- What will `max({1: 'a', 3: 'b', 2: 'c'})` return?
- Which method merges two dictionaries without modifying the originals (Python 3.9+)?
- Can a dictionary key be a tuple?
- What does `d.get('x', 'default')` return if 'x' is not a key?
- How would you check if a dictionary is empty?
- What is the best way to remove all keys from a dictionary without deleting the dictionary?
- How can you get a list of all values in a dictionary?
- Which of the following will cause a dictionary creation error?
- Which function converts a dictionary to a JSON string?
- What happens when you use `update()` with overlapping keys?
- What will `dict.fromkeys('abc', 0)` return?
- What does `d.popitem()` return?
- Can a dictionary contain another dictionary as a value?
- What does `dict.clear()` do?
- What will be the result of `mydict['missing']` if 'missing' is not a key?
- What is the output of `dict([(1, 2), (3, 4)])`?
- Which function is used to create a dictionary from two sequences?
- What does the `dict` constructor return when passed a list of two-item tuples?