Python — Learn

Python Mcq Set 18

Review each question and reveal answers to strengthen your understanding

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