Top 1000+ Solved Problem Solving and Python Programming MCQ Questions Answer
Q. 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”}
Q. 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
Q. Which of the statements about dictionary values if false?
a. more than one key can have the same value
b. the values of the dictionary can be accessed as dict[key]
c. values of a dictionary must be unique
d. values of a dictionary can be a mixture of letters and numbers
Q. If a is a dictionary with some key-value pairs, what does a.popitem() do?
a. removes an arbitrary element
b. removes all the key-value pairs
c. removes the key-value pair for the key given as an argument
d. invalid method for dictionary
Q. ,2,3],"check")
a. syntax error
b. {1:”check”,2:”check”,3:”check”}
c. “check”
d. {1:none,2:none,3:none}
Q. If b is a dictionary, what does any(b) do?
a. returns true if any key of the dictionary is true
b. returns false if dictionary is empty
c. returns true if all keys of the dictionary are true
d. method any() doesn’t exist for dictionary
Q. To open a file c:\scores.txt for reading, we use
a. infile = open(“c:\\scores.txt”, “r”)
b. infile = open(“c:\\scores.txt”, “r”)
c. infile = open(file = “c:\\scores.txt”, “r”)
d. infile = open(file = “c:\\scores.txt”, “r”)
Q. To open a file c:\scores.txt for writing, we use
a. outfile = open(“c:\\scores.txt”, “w”)
b. outfile = open(“c:\\scores.txt”, “w”)
c. outfile = open(file = “c:\\scores.txt”, “w”)
d. outfile = open(file = “c:\\scores.txt”, “w”)