Review each question and reveal answers to strengthen your understanding
1Which of the codes shown below results in a match?
✅ Correct Answer: 3
2What will be the output of the following Python code?
re.split(r'(a)(t)', 'Maths is a difficult subject')
✅ Correct Answer: 4
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)
✅ Correct Answer: 1
4What will be the output of the following Python code?
re.subn('A', 'X', 'AAAAAA', count=4)
✅ Correct Answer: 3
5What will be the output of the following Python code?
w = re.compile('[A-Za-z]+')
w.findall('It will rain today')
✅ Correct Answer: 4
6In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to _____
✅ Correct Answer: 1
7What will be the output of the following Python code?
re.split(r's+', 'Chrome is better than explorer', maxspilt=3)
✅ Correct Answer: 2
8What will be the output of the following Python code?
a=re.compile('[0-9]+')
a.findall('7 apples and 3 mangoes')
✅ Correct Answer: 3
9Which of the following functions returns a dictionary mapping group names to group numbers?
✅ Correct Answer: 2
10Which of the following statements regarding the output of the function re.match is incorrect?
✅ Correct Answer: 4
11Which of the following functions does not accept any argument?
✅ Correct Answer: 1
12What will be the output of the following Python code?
a = re.compile('0-9')
a.findall('3 trees')
✅ Correct Answer: 3
13Which of the following lines of code will not show a match?
✅ Correct Answer: 4
14What will be the output of the following Python code?
m = re.search('a', 'The blue umbrella')
m.re.pattern
✅ Correct Answer: 3
15What will be the output of the following Python code?
re.sub('Y', 'X', 'AAAAAA', count=2)
✅ Correct Answer: 4
16To open a file c:scores.txt for reading, we use ______
✅ Correct Answer: 2
17 To open a file c:scores.txt for writing, we use ____
✅ Correct Answer: 2
18To open a file c:scores.txt for appending data, we use _______
✅ Correct Answer: 1
19Which of the following statements are true?
✅ Correct Answer: 4
20To read two characters from a file object infile, we use _______
✅ Correct Answer: 1
21To read the entire remaining contents of the file as a string from a file object infile, we use ____
✅ Correct Answer: 2
22What 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)
✅ Correct Answer: 3
23To read the next line of the file from a file object infile, we use ______
✅ Correct Answer: 3
24To read the remaining lines of the file from a file object infile, we use _______
✅ Correct Answer: 4
25The readlines() method returns _______
✅ Correct Answer: 2
26Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?
✅ Correct Answer: 1
27 What will be the output of the following Python code?
str = input("Enter your input: ");
print "Received input is : ", str
✅ Correct Answer: 1
28Which one of the following is not attributes of file?
✅ Correct Answer: 3
29What is the use of tell() method in python?
✅ Correct Answer: 1
30What is the current syntax of rename() a file?
✅ Correct Answer: 1
31What is the current syntax of remove() a file?
✅ Correct Answer: 1
32What is the use of seek() method in files?
✅ Correct Answer: 1
33What is the use of truncate() method in file?
✅ Correct Answer: 1
34Which is/are the basic I/O connections in file?
✅ Correct Answer: 4
35What 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
✅ Correct Answer: 1
36What will be the output of the following Python code?
import sys
sys.stdout.write(' Hello
')
sys.stdout.write('Python
')
✅ Correct Answer: 4
37Which of the following mode will refer to binary data?
✅ Correct Answer: 4
38 What is the pickling?
✅ Correct Answer: 1
39 What is unpickling?
✅ Correct Answer: 2
40 What is the correct syntax of open() function?
✅ Correct Answer: 2
41What 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()
✅ Correct Answer: 4
42Correct syntax of file.writelines() is?
✅ Correct Answer: 3
43Correct syntax of file.readlines() is?
✅ Correct Answer: 1
44In file handling, what does this terms means “r, a�
✅ Correct Answer: 1
45What is the use of “w†in file handling?
✅ Correct Answer: 2
46What is the use of “a†in file handling?
✅ Correct Answer: 3
47Which function is used to read all the characters?
✅ Correct Answer: 1
48Which function is used to read single line from file?
✅ Correct Answer: 2
49Which function is used to write all the characters?
✅ Correct Answer: 1
50Which function is used to write a list of string in a file?