Python Multiple Choice Questions & Answers (MCQs) focuses on “Dictionary – 2”.

Q 1. Which of these about a dictionary is false?
A. The values of a dictionary can be accessed using keys
B. The keys of a dictionary can be accessed using values
C. Dictionaries aren’t ordered
D. Dictionaries are mutable

Show Answer Answer:-B. The keys of a dictionary can be accessed using values
Explanation The values of a dictionary can be accessed using keys but the keys of a dictionary can’t be accessed using values.


Q 2. Which of the following is not a declaration of the dictionary?
A. {1: ‘A’, 2: ‘B’}
B. dict([[1,”A”],[2,”B”]])
C. {1,”A”,2”B”}
D. { }

Show Answer Answer:-C. {1,”A”,2”B”}
Explanation Option c is a set, not a dictionary.


Q 3. What will be the output of the following Python code snippet?

a={1:”A”,2:”B”,3:”C”}
for i,j in a.items():
print(i,j,end=” “)
A. 1 A 2 B 3 C
B. 1 2 3
C. A B C
D. 1:”A” 2:”B” 3:”C”

Show Answer Answer:-A. 1 A 2 B 3 C
Explanation In the above code, variables i and j iterate over the keys and values of the dictionary respectively.

Q 4. What will be the output of the following Python code snippet?

a={1:”A”,2:”B”,3:”C”}
print(a.get(1,4))
A. 1
B. A
C. 4
D. Invalid syntax for get method

Show Answer Answer:-B. A
Explanation The get() method returns the value of the key if the key is present in the dictionary and the default value(second parameter) if the key isn’t present in the dictionary.


Q 5. What will be the output of the following Python code snippet?

a={1:”A”,2:”B”,3:”C”}
print(a.get(5,4))
A. 4
B. A
C. 5
D. Error, invalid syntax

Show Answer Answer:-A. 4
Explanation The get() method returns the default value(second parameter) if the key isn’t present in the dictionary.


Q 6. What will be the output of the following Python code snippet?

a={1:”A”,2:”B”,3:”C”}
print(a.setdefault(3))
A. {1: ‘A’, 2: ‘B’, 3: ‘C’}
B. C
C. {1: 3, 2: 3, 3: 3}
D. No method called setdefault() exists for dictionary

Show Answer Answer:-B. C
Explanation setdefault() is similar to get() but will set dict[key]=default if key is not already in the dictionary.


Q 7. What will be the output of the following Python code snippet?

a={1:”A”,2:”B”,3:”C”}
a.setdefault(4,”D”)
print(a)
A. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}
B. [1,3,6,10]
C. Error
D. None

Show Answer Answer:-A. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}
Explanation setdefault() will set dict[key]=default if key is not already in the dictionary.


Q 8. What will be the output of the following Python code?

a={1:”A”,2:”B”,3:”C”}
b={4:”D”,5:”E”}
a.update(b)
print(a)
A. {1: ‘A’, 2: ‘B’, 3: ‘C’}
B. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
C. {4: ‘D’, 5: ‘E’}
D. Method update() doesn’t exist for dictionaries

Show Answer Answer:-B. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
Explanation update() method adds dictionary b’s key-value pairs to dictionary a. Execute in python shell to verify.


Q 9. What will be the output of the following Python code?

a={1:”A”,2:”B”,3:”C”}
b=a.copy()
b[2]=”D”
print(a)
A. {1: ‘A’, 2: ‘B’, 3: ‘C’}
B . {1: ‘A’, 2: ‘D’, 3: ‘C’}
C. Error, copy() method doesn’t exist for dictionaries
D. “None” is printed

Show Answer Answer:-A. {1: ‘A’, 2: ‘B’, 3: ‘C’}
Explanation Changes made in the copy of the dictionary isn’t reflected in the original one.


Q 10. What will be the output of the following Python code?

a={1:”A”,2:”B”,3:”C”}
a.clear()
print(a)
A. { }
B. { None:None, None:None, None:None}
C. {1:None, 2:None, 3:None}
D. None

Show Answer Answer:-A. { }
Explanation The clear() method clears all the key-value pairs in the dictionary.


Q 11. Which of the following isn’t true about dictionary keys?
A. More than one key isn’t allowed
B. Keys must be immutable
C. Keys must be integers
D. When duplicate keys encountered, the last assignment wins

Show Answer Answer:-C. Keys must be integers
Explanation Keys of a dictionary may be any data type that is immutable.


Q 12. What will be the output of the following Python code?

a={1:5,2:3,3:4}
a.pop(3)
print(a)
A. {1: 5}
B. {1: 5, 2: 3}
C. {1: 5, 3: 4}
D. Error, syntax error for pop() method

Show Answer Answer:-B. {1: 5, 2: 3}
Explanation pop() method removes the key-value pair for the key mentioned in the pop() method.


Q 13. What will be the output of the following Python code?

a={1:5,2:3,3:4}
print(a.pop(4,9))
A. 3
B. 4
C. 9
D. Too many arguments for pop() method

Show Answer Answer:-C. 9
Explanation pop() method returns the value when the key is passed as an argument and otherwise returns the default value(second argument) if the key isn’t present in the dictionary.


Q 14. What will be the output of the following Python code?

a={1:”A”,2:”B”,3:”C”}
for i in a:
print(i,end=” “)
A. 1 2 3
B. ‘A’ ‘B’ ‘C’
C. 1 ‘A’ 2 ‘B’ 3 ‘C’
D. Error, it should be: for i in a.items():

Show Answer Answer:-A. 1 2 3
Explanation The variable i iterates over the keys of the dictionary and hence the keys are printed.


Q 15. What will be the output of the following Python code?

>>> a={1:”A”,2:”B”,3:”C”}
>>> a.items()
A. Syntax error
B. dict_items([(‘A’), (‘B’), (‘C’)])
C. dict_items([(1,2,3)])
D. dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

Show Answer Answer:-D. dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
Explanation The method items() returns list of tuples with each tuple having a key-value pair.

Leave a Reply

Your email address will not be published. Required fields are marked *

Author

quizsquestion@gmail.com

Related Posts

Top 100 UK GK Questions (Culture, Sport & Icons)

🎭 Culture (1–35) Q 1. What is the capital of the United Kingdom? Show Answer Answer:-London Q 2. What is the official...

Read out all

Current Affairs Quiz – May 2026

Q 1.Which state has been declared the country’s first paperless judiciary state? A. SikkimB. ManipurC. AssamD. Odisha Show Answer Answer:- A. Sikkim...

Read out all

Culture Sport & Icons Australia GK Question Top 100

Australia’s identity is a vibrant blend of the world’s oldest living culture, a deep-seated passion for sport, and a unique collection of...

Read out all

Current Affairs Quiz – March 2026

Q 1.Where was India–UK Conference on Green Hydrogen Standards and Safety Protocols held? A. New DelhiB. ChennaiC. HyderabadD. Bengaluru Show Answer Answer:-A....

Read out all

Python Questions and Answers – Exception Handling – 3

Python Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 3”. Q 1. What happens if the file is not...

Read out all

Important Events & History Canadian Multiple Choice Question

Q 1. In what year did Canadian Confederation take place? A. 1776 B. 1812 C. 1867 D. 1982 Show Answer Answer:-C. 1867...

Read out all

You cannot copy content of this page