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

From 586 to 600 of 820

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. ] test[1] = 'D' del test[2] print(len(test))

a. 0

b. 2

c. error as the key-value pair of 1:’a’ is already deleted

d. 1

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

Q. To open a file c:\scores.txt for appending data, we use                          

a. outfile = open(“c:\\scores.txt”, “a”)

b. outfile = open(“c:\\scores.txt”, “rw”)

c. outfile = open(file = “c:\\scores.txt”, “w”)

d. outfile = open(file = “c:\\scores.txt”, “w”)

  • a. outfile = open(“c:\\scores.txt”, “a”)

Q. Which of the following statements are true?

a. when you open a file for reading, if the file does not exist, an error occurs

b. when you open a file for writing, if the file does not exist, a new file is created

c. when you open a file for writing, if the file exists, the existing file is overwritten with the new file

d. all of the mentioned

  • d. all of the mentioned

Q. 1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR

a. infile.read(2)

b. infile.read()

c. infile.readline()

d. infile.readlines()

  • a. infile.read(2)
Subscribe Now

Get All Updates & News