Top 1000+ Solved Problem Solving and Python Programming MCQ Questions Answer

From 121 to 135 of 820

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”}

  • c. d) { }

Q. ,4))

a. 1

b. a

c. 4

d. invalid syntax for get method

Q. ,4))

a. error, invalid syntax

b. a

c. 5

d. 4

Q. ,"D") print(a)

a. {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}

b. none

c. error

d. [1,3,6,10]

  • a. {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}

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

  • c. keys must be integers

Q. ) print(a)

a. {1: 5}

b. {1: 5, 2: 3}

  • b. {1: 5, 2: 3}

Q. ,9))

a. 9

b. 3

c. too many arguments for pop() method

d. 4

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

  • c. values of a dictionary must be unique

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

  • a. removes an arbitrary element

Q. print(a)

a. true

b. false

  • b. false

Q. ][1])

a. [2,3,4]

b. 3

c. 2

d. an exception is thrown

Q. ,2,3],"check")

a. syntax error

b. {1:”check”,2:”check”,3:”check”}

c. “check”

d. {1:none,2:none,3:none}

  • b. {1:”check”,2:”check”,3:”check”}

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

  • a. returns true if any key of the dictionary is true

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”)

  • b. infile = open(“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”)

  • b. outfile = open(“c:\\scores.txt”, “w”)
Subscribe Now

Get All Updates & News