aKidsZone
Home
MCQs
Python — Quiz
Python Mcq Set 18
50 questions · Test your knowledge
Home
/
MCQs
/
Python Mcq Set 18
1
Which of the codes shown below results in a match?
A
re.match(‘George(?=Washington)’, ‘George Washington’)
B
re.match(‘George(?=Washington)’, ‘George’)
C
re.match(‘George(?=Washington)’, ‘GeorgeWashington’)
D
re.match(‘George(?=Washington)’, ‘Georgewashington’)
2
What will be the output of the following Python code? 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’]
3
What will be the output of the following Python code? import re s = 'abc123 xyz666 lmn-11 def77' re.sub(r'([a-z]+)(d+)', r'21:', 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’
4
What will be the output of the following Python code? re.subn('A', 'X', 'AAAAAA', count=4)
A
‘XXXXAA, 4’
B
‘AAAAAA’, 4)
C
(‘XXXXAA’, 4)
D
‘AAAAAA, 4’
5
What will be the output of the following Python 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’]
6
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
7
What will be the output of the following Python code? 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’
8
What will be the output of the following Python code? a=re.compile('[0-9]+') a.findall('7 apples and 3 mangoes')
A
[‘apples’ ‘and’ ‘mangoes’]
B
(7, 4)
C
[‘7’, ‘4’]
D
error
9
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
10
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’
11
Which of the following functions does not accept any argument?
A
re.purge
B
re.compile
C
re.findall
D
re.match
12
What will be the output of the following Python code? a = re.compile('0-9') a.findall('3 trees')
A
[]
B
[‘3’]
C
Error
D
[‘trees’]
13
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’)
14
What will be the output of the following Python code? m = re.search('a', 'The blue umbrella') m.re.pattern
A
{}
B
‘The blue umbrella’
C
‘a’
D
No output
15
What will be the output of the following Python code? re.sub('Y', 'X', 'AAAAAA', count=2)
A
'YXAAAA’
B
(‘YXAAAA’)
C
(‘AAAAAA’)
D
‘AAAAAA’
16
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â€)
17
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â€)
18
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â€)
19
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
20
To read two characters from a file object infile, we use _______
A
infile.read(2)
B
infile.read()
C
infile.readline()
D
infile.readlines()
21
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()
22
What will be the output of the following Python code? 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
23
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()
24
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()
25
The readlines() method returns _______
A
str
B
a list of lines
C
a list of single characters
D
a list of integers
26
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
27
What will be the output of the following Python code? 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
28
Which one of the following is not attributes of file?
A
closed
B
softspace
C
rename
D
Model
29
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
30
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
31
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
32
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
33
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
34
Which is/are the basic I/O connections in file?
A
Standard Input
B
Standard Output
C
Standard Errors
D
all of the mentioned
35
What will be the output of the following Python code? (If entered name is sanfoundry) import sys print 'Enter your name: ', name = '' while True: c = sys.stdin.read(1) if c == ' ': break name = name + c print 'Your name is:', name
A
sanfoundry
B
sanfoundry, sanfoundry
C
San
D
none of the mentioned
36
What will be the output of the following Python code? import sys sys.stdout.write(' Hello ') sys.stdout.write('Python ')
A
Compilation Error
B
Runtime Error
C
Hello Python
D
Hello Python
37
Which of the following mode will refer to binary data?
A
r
B
w
C
+
D
b
38
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
39
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
40
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
41
What will be the output of the following Python code? 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
42
Correct syntax of file.writelines() is?
A
file.writelines(sequence)
B
fileObject.writelines()
C
fileObject.writelines(sequence)
D
none of the mentioned
43
Correct syntax of file.readlines() is?
A
fileObject.readlines( sizehint );
B
fileObject.readlines();
C
fileObject.readlines(sequence)
D
none of the mentioned
44
In file handling, what does this terms means “r, a�
A
read, append
B
append, read
C
write, append
D
none of the mentioned
45
What is the use of “w†in file handling?
A
Read
B
Write
C
Append
D
none of the mentioned
46
What is the use of “a†in file handling?
A
Read
B
Write
C
Append
D
none of the mentioned
47
Which function is used to read all the characters?
A
Read()
B
Readcharacters()
C
Readall()
D
Readchar()
48
Which function is used to read single line from file?
A
Readline()
B
Readlines()
C
Readstatement()
D
Readfullline()
49
Which function is used to write all the characters?
A
write()
B
writecharacters()
C
writeall()
D
writechar()
50
Which function is used to write a list of string in a file?
A
writeline()
B
writelines()
C
writestatement()
D
writefullline()
Submit Quiz
Back to All Quizzes