Multiple Choice Question For Dictionaries Class 11 Computer Science (CS), Informatics Practices (IP)
1. Dictionaries are set of elements.
(a) sorted
(b) ordered
(c) unordered
(d) random
2. Dictionaries are also called _____.
(a) mappings
(b) hashes
(c) associative arrays
(d) all of these
3. Dictionaries are _____ data types of Python.
(a) mutable
(b) immutable
(c) simple
(d) all of these
4. Which of the following functions will return the key, value pairs of a dictionary?
(a) keys()
(b) values()
(c) items()
(d) all of these
5. Which of the following can be used to delete item(s) from a dictionary?
(a) del statement
(b) get()
(c) getitem()
(d) all of these
6. Which of the following will raise an error if the given key is not found in the dictionary ?
(a) del statement
(b) pop()
(c) getitem()
(d) all of these
7. Which of the following is correct with respect to above Python code?
d = {"a":3,"b":7}
(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 these.
8. What would the following code print?
d = {'spring': 'autum', "autumn": "fall", "fall":"spring"}
print (d["autumn"])
(a) autumn
(b) fall
(c) spring
(d) Error
9. What is printed by the following statements?
D1 = {"cat":17, "dog":6, "elephant":23, "bear":20}
print ("dog" in D1)
(a) True
(b) False
(c) Error
(d) None
10. What is printed by the following statements ?
D1 = {"cat":17, "dog":6, "elephant":23, "bear":20}
print (25 in D1)
(a) True
(b) False
(c) Error
(d) None
11. What will be the result of the following code?
d1 = {"abc":5,"def":6, "ghi":7}
print (d1[0])
(a) abc
(b) 5
(c) (“abc” : 5)
(d) Error
12. What will the following code do ?
dict = {“Phy”:94, "Che": 70, "Bio":82, "Eng":95}
dict.update({"Che":72,"Bio":80})
(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.
13. What will be the result of the following code ?
dict = {"Jo" : 1, "Ra" : 2}
dict.update({"Phoebe":2})
print (dict)
(a) {"Jo":1,"Ra" :2, "Ph" : 2}
(b) {"Jo":1,"Ra":2}
(c) {"Jo":1,"Ph" :2}
(d) Error
14. Which of the following will delete key_value pair for key = "tiger" in dictionary?
di = {"loin" : "wild", "tiger" : "wild", "cat": "domestic" : "dog" : "domestic"}
(a) del di["tiger"]
(b) di[“tiger”].delete()
(c) delete(di.["tiger"])
(d) del(di.["tiger])
15. Which of the following will give error if d1 is as shown below?
d1 = ("a" : 1, "b":2,"c":3)
(a) print(len(d1))
(b) print(d1.get("b"))
(c) d1["a"] = 5
(d) None of these
16. What will be the output of the following Python code ?
d1 = {"a" : 10, "b" : 2, "c" : 3}
str1 = ""
for i in d1:
str1 = str1 + str(d1[i])+ ""
str2 = str1[:-1]
print(str2[::-1])
(a) 3, 2
(b) 3, 2, 10
(c) 3, 2, 01
(d) Error
17. Which of the following will add a key to the dictionary only if it does not already exist in the dictionary?
(a) fromkeys()
(b) update()
(c) setdefault()
(d) all of these
18. Which of the following will create a dictionary with given keys and a common value ?
(a) fromkeys()
(b) update()
(c) setdefault()
(d) all of these
19. Which value is assigned to keys, if no value is specified with the fromkeys() method ?
(a) 0
(b) 1
(c) None
(d) any of these
20. Which of the following will raise an error if the given dictionary is empty?
(a) del statement
(b) pop()
(c) popitem()
(d) all of these
21. A copy of the dictionary where only the copy of the keys is created for the new dictionary, is called _____ copy.
(a) key copy
(b) shallow copy
(c) deep copy
(d) partial copy
22. A copy of the dictionary where the copy of the keys as well as the values is created for the new dictionary, is called _____ copy.
(a) key copy
(b) shallow copy
(c) deep copy
(d) partial copy
23. Which of the following Python codes will give the same output if
dict = {"diary":1, "book":3, "novel":5}
(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)
24. What will be the output of following Python code ?
d1 = {"a":10, "b":2, "c":3}
str1=""
for i in d1:
str1=strl + str(d1[i]) + " "
str2 = str1[:-1]
print (str2[::-1])
(a) 3, 2
(b) 3, 2, 10
(c) 3, 2, 01
(d) Error
25. Running the code sorted(my_dictionary, reverse = True) on a dictionary named my_dictionary will return results sorted in what order ?
(a) Ascending order (A-Z), by key
(b) Ascending order (A-Z), by value
(c) Descending order (Z-A), by key
(d) Descending order (Z-A), by valu
PLS.......
ReplyDeleteTRY TO GIVE ALL THE MCQ POSSIBLE FROM 1 CHAPTER BY COVERING ALL THE TOPICS,IMPORTANT TERMS,NOTES,etc,...
Ok, I will try my best.
DeleteGive only the hard and important questions'
ReplyDeleteOk, I will try.
DeleteBro you have done great job....
ReplyDeleteThank you so much 🥰🥰
Deletenice man thanks a lot
ReplyDeleteWelcome : )
Delete8th one is correct or not because two cotes and one cotes are there?
ReplyDeleteCorrect, because in Python " " and ' ' both are string.
DeleteLoved reading tthis thanks
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )