Explore topic-wise MCQs in Technical Programming.

This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.

151.

Correct syntax of file.readlines() is?

A. fileObject.readlines( sizehint );
B. fileObject.readlines();
C. fileObject.readlines(sequence)
D. none of the mentioned
Answer» B. fileObject.readlines();
152.

Correct syntax of file.writelines() is?

A. file.writelines(sequence)
B. fileObject.writelines()
C. fileObject.writelines(sequence)
D. none of the mentioned
Answer» D. none of the mentioned
153.

What is the output of this program? fo = open("foo.txt", "wb") print "Name of the file: ", fo.name fo.flush() fo.close()

A. Compilation Error
B. Runtime Error
C. No Output
D. Flushes the file when closing them
Answer» E.
154.

What is the correct syntax of open() function?

A. file = open(file_name [, access_mode][, buffering])
B. file object = open(file_name [, access_mode][, buffering])
C. file object = open(file_name)
D. none of the mentioned
Answer» C. file object = open(file_name)
155.

What is unpickling?

A. It is used for object serialization
B. It is used for object deserialization
C. None of the mentioned
D. All of the mentioned
Answer» C. None of the mentioned
156.

What is the pickling?

A. It is used for object serialization
B. It is used for object deserialization
C. None of the mentioned
D. All of the mentioned
Answer» B. It is used for object deserialization
157.

Which of the following mode will refer to binary data?

A. r
B. w
C. +
D. b
Answer» E.
158.

What is the output of this program? import sys sys.stdout.write(' Hello\n') sys.stdout.write('Python\n')

A. Compilation Error
B. Runtime Error
C. Hello Python
D. Hello Python
Answer» E.
159.

Which is/are the basic I/O connections in file?

A. Standard Input
B. Standard Output
C. Standard Errors
D. All of the mentioned
Answer» E.
160.

What is the use of truncate() method in file?

A. truncates the file size
B. deletes the content of the file
C. deletes the file size
D. none of the mentioned
Answer» B. deletes the content of the file
161.

What is the use of seek() method in files?

A. sets the file’s current position at the offset
B. sets the file’s previous position at the offset
C. sets the file’s current position within the file
D. none of the mentioned
Answer» B. sets the file’s previous position at the offset
162.

What is the current syntax of remove() a file?

A. remove(file_name)
B. remove(new_file_name, current_file_name,)
C. remove(() , file_name))
D. none of the mentioned
Answer» B. remove(new_file_name, current_file_name,)
163.

What is the current syntax of rename() a file?

A. rename(current_file_name, new_file_name)
B. rename(new_file_name, current_file_name,)
C. rename(()(current_file_name, new_file_name))
D. none of the mentioned
Answer» B. rename(new_file_name, current_file_name,)
164.

What is the use of tell() method in python?

A. tells you the current position within the file
B. tells you the end position within the file
C. tells you the file is opened or not
D. none of the mentioned
Answer» B. tells you the end position within the file
165.

Which one of the following is not attributes of file

A. closed
B. softspace
C. rename
D. mode
Answer» D. mode
166.

What is the output of this program? str = input("Enter your input: "); print "Received input is : ", str

A. Enter your input: [x*5 for x in range(2,10,2)]. Received input is : [x*5 for x in range(2,10,2)].
B. Enter your input: [x*5 for x in range(2,10,2)]. Received input is : [10, 30, 20, 40].
C. Enter your input: [x*5 for x in range(2,10,2)]. Received input is : [10, 10, 30, 40].
D. None of the mentioned
Answer» B. Enter your input: [x*5 for x in range(2,10,2)]. Received input is : [10, 30, 20, 40].
167.

What is the output of this program? str = raw_input("Enter your input: "); print "Received input is : ", str

A. Enter your input: Hello Python Received input is : Hello Python
B. Enter your input: Hello Python Received input is : Hello
C. Enter your input: Hello Python Received input is : Python
D. None of the mentioned
Answer» B. Enter your input: Hello Python Received input is : Hello
168.

Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

A. Raw_input & Input
B. Input & Scan
C. Scan & Scanner
D. Scanner
Answer» B. Input & Scan
169.

The readlines() method returns

A. str
B. a list of lines
C. a list of single characters
D. a list of integers
Answer» C. a list of single characters
170.

To read the remaining lines of the file from a file object infile, we use

A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Answer» E.
171.

To read the next line of the file from a file object infile, we use

A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Answer» D. infile.readlines()
172.

What is the output? f = None for i in range (5): with open("data.txt", "w") as f: if i > 2: break print(f.closed)

A. True
B. False
C. None
D. Error
Answer» B. False
173.

To read the entire remaining contents of the file as a string from a file object infile, we use

A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Answer» C. infile.readline()
174.

To read two characters from a file object infile, we use

A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Answer» B. infile.read()
175.

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
Answer» E.
176.

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”)
Answer» B. outfile = open(“c:scores.txt”, “rw”)
177.

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”)
Answer» C. outfile = open(file = “c:scores.txt”, “w”)
178.

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”)
Answer» C. infile = open(file = “c:scores.txt”, “r”)
179.

What is the output of the function shown below? re.sub('Y', 'X', 'AAAAAA', count=2)

A. YXAAAA’
B. (‘YXAAAA’)
C. (‘AAAAAA’)
D. ‘AAAAAA’
Answer» E.
180.

What is the output of the code shown below? m = re.search('a', 'The blue umbrella') m.re.pattern

A. {}
B. ‘The blue umbrella’
C. ‘a’
D. No output
Answer» D. No output
181.

Which of the following lines of code will not show a match?

A. >>> re.match(‘ab*’, ‘a’)
B. >>> re.match(‘ab*’, ‘ab’)
C. >>> re.match(‘ab*’, ‘abb’)
D. >>> re.match(‘ab*’, ‘ba’)
Answer» E.
182.

What is the output of the code shown below? a = re.compile('0-9') a.findall('3 trees')

A. []
B. [‘3’]
C. Error
D. [‘trees’]
Answer» D. [‘trees’]
183.

Which of the following functions does not accept any argument?

A. re.purge
B. re.compile
C. re.findall
D. re.match
Answer» B. re.compile
184.

Which of the following statements regarding the output of the function re.match is incorrect?

A. ‘pq*’ will match ‘pq’
B. ‘pq?’ matches ‘p’
C. p{4}, q’ does not match ‘pppq’
D. ‘pq+’ matches ‘p’
Answer» E.
185.

Which of the following functions returns a dictionary mapping group names to group numbers?

A. re.compile.group
B. re.compile.groupindex
C. re.compile.index
D. re.compile.indexgroup
Answer» C. re.compile.index
186.

What is the output of the code shown below? a=re.compile('[0-9]+') a.findall('7 apples and 3 mangoes')

A. [‘apples’ ‘and’ ‘mangoes’]
B. (7, 4)
C. [‘7’, ‘4’]
D. Error
Answer» D. Error
187.

What is the output of the code shown below? re.split(r'\s+', 'Chrome is better than explorer', maxspilt=3)

A. [‘Chrome’, ‘is’, ‘better’, ‘than’, ‘explorer’]
B. [‘Chrome’, ‘is’, ‘better’, ‘than explorer’]
C. (‘Chrome’, ‘is’, ‘better’, ‘than explorer’)
D. Chrome is better’ ‘than explorer’
Answer» C. (‘Chrome’, ‘is’, ‘better’, ‘than explorer’)
188.

In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to __________

A. Zero
B. None
C. One
D. Error
Answer» B. None
189.

What is the output of the following code? w = re.compile('[A-Za-z]+') w.findall('It will rain today')

A. It will rain today’
B. (‘It will rain today’)
C. [‘It will rain today’]
D. [‘It’, ‘will’, ‘rain’, ‘today’]
Answer» E.
190.

What is the output of the code shown below? n = re.sub(r'\w+', 'Hello', 'Cats and dogs')

A. Hello Hello
B. Hello Hello Hello’
C. [‘Hello’, ‘Hello’, ‘Hello’]
D. (‘Hello’, ‘Hello’, ‘Hello’)
Answer» C. [‘Hello’, ‘Hello’, ‘Hello’]
191.

What is the output of the code shown? re.subn('A', 'X', 'AAAAAA', count=4)

A. ‘XXXXAA, 4’
B. (‘AAAAAA’, 4)
C. (‘XXXXAA’, 4)
D. ‘AAAAAA, 4’
Answer» D. ‘AAAAAA, 4’
192.

What is the output of the code shown below? import re s = 'abc123 xyz666 lmn-11 def77' re.sub(r'\b([a-z]+)(\d+)', r'\2\1:', s)

A. ‘123abc: 666xyz: lmn-11 77def:’
B. ‘77def: lmn-11: 666xyz: 123abc’
C. abc123:’, ‘xyz666:’, ‘lmn-11:’, ‘def77:’
D. ‘abc123: xyz666: lmn-11: def77’
Answer» B. ‘77def: lmn-11: 666xyz: 123abc’
193.

What is the output of the code shown below? re.split(r'(a)(t)', 'Maths is a difficult subject')

A. [‘M a t h s i s a d i f f i c u l t s u b j e c t’]
B. [‘Maths’, ‘is’, ‘a’, ‘difficult’, ‘subject’]
C. [‘Maths’, ‘is’, ‘a’, ‘difficult’, ‘subject’]
D. [‘M’, ‘a’, ‘t’, ‘hs is a difficult subject’]
Answer» E.
194.

What is the output of the code shown below? re.findall('good', 'good is good') re.findall('good', 'bad is good')

A. ‘good’, ‘good’] [‘good’]
B. (‘good’, ‘good’) (good)
C. ‘good’) (‘good’)
D. [‘good’] [‘good’]
Answer» B. (‘good’, ‘good’) (good)
195.

The output of the code shown below is: re.split('mum', 'mumbai*', 1)

A. Error
B. [”, ‘bai*’]
C. [”, ‘bai’]
D. [”, ‘bai’]
Answer» C. [”, ‘bai’]
196.

The difference between the functions re.sub and re.subn is that re.sub returns a _______________ whereas re.subn returns a __________________

A. string, list
B. list, tuple
C. string, tuple
D. tuple, list
Answer» D. tuple, list
197.

Choose the option wherein the two choices do not refer to the same option.

A. re.I re.IGNORECASE
B. re.M re.MULTILINE
C. re.X re.VERBOSE
D. re.L re.LOWERCASE
Answer» E.
198.

What is the output of the code shown below? re.fullmatch('hello', 'hello world')

A. No output
B. []
C. <_sre.SRE_Match object; span=(0, 5), match=hello>
D. Error
Answer» B. []
199.

The output of the code shown below: re.escape('new**world')

A. ‘new world’
B. ‘new**world’
C. ‘**’
D. ‘new’, ‘*’, ‘*’, ‘world’
Answer» C. ‘**’
200.

What is the output of the code shown below? re.sub('morning', 'evening', 'good morning')

A. ‘good evening’
B. ‘good’
C. morning’
D. evening’
Answer» B. ‘good’