Python — Quiz

Python Mcq Set 18

50 questions · Test your knowledge

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