Python Dictionary MCQ

This section focuses on the "Dictionary" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which of the following is correct with respect to above Python code?


A. a dictionary d is created.
B. a and b are the keys of dictionary d.
C. 3 and 7 are the values of dictionary d
D. All of the above.

View Answer

2. Which one of the following is correct?

A. In python, a dictionary can have two same keys with different values.
B. In python, a dictionary can have two same values with different keys
C. In python, a dictionary can have two same keys or same values but cannot have two same key-value pair
D. In python, a dictionary can neither have two same keys nor two same values.

View Answer

3. What will be the output of above Python code?


A. abc
B. 5
C. {"abc":5}
D. Error

View Answer

4. What will the above Python code do?


A. It will create new dictionary as dict={"Che":72,"Bio":80} and old dict will be deleted.
B. It will throw an error as dictionary cannot be updated.
C. It will simply update the dictionary as dict={"Phy":94,"Che":72,"Bio":80,"Eng":95}
D. It will not throw any error but it will not do any changes in dict

View Answer

5. What will be the result of above Python code?


A. {"Joey":1,"Rachel":2,"Phoebe":2}
B. {"Joey":1,"Rachel":2}
C. {"Joey":1,"Phoebe":2}
D. Error

View Answer

6. Which of the following is False regarding dictionary in Python?


A. Values of a dictionary can be string,integers or combination of both.
B. Keys of a dictionary can be string,integers or combination of both
C. The value of a dictionary can be accessed with the help of indices.
D. None of the above

View Answer

7. Which of the following will delete key_value pair for key="tiger" in dictionary?


A. del dic["tiger"]
B. dic["tiger"].delete()
C. delete(dic.["tiger"])
D. del(dic.["tiger"])

View Answer

8. Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

A. print(len(dict1))
B. print(dict1.get("b"))
C. dict1["a"]=5
D. None of these.

View Answer

9. Which of the following Python codes will give same output if
(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})


A. i, ii, iii
B. i, ii
C. i, iii
D. ii, iii

View Answer

10. What will be the following Python code?

for i in dict1:
    str1=str1+str(dict1[i])+" "

A. 3, 2
B. 3, 2, 10
C. 3, 2, 01
D. Error

View Answer


* You must be logged in to add comment.