21. What will be the output of the following Python code?
re.compile(‘hello’, re.X)
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) re.compile(‘hello’, re.VERBOSE)
c) Error
d) Junk value
22. What will be the output of the following Python code?
re.split(‘[a-c]’, ‘0a3B6’, re.I)
a) Error
b) [‘a’, ‘B’]
c) [‘0’, ‘3B6’]
d) [‘a’]
23. What will be the output of the following Python code?
re.sub(‘morning’, ‘evening’, ‘good morning’)
a) ‘good evening’
b) ‘good’
c) ‘morning’
d) ‘evening’
24. The function re.error raises an exception if a particular string contains no match for the given pattern.
a) True
b) False
25. What will be the output of the following Python code?
re.escape(‘new**world’)
a) ‘new world’
b) ‘new\\*\\*world’
c) ‘**’
d) ‘new’, ‘*’, ‘*’, ‘world’
26. What will be the output of the following Python code?
re.fullmatch(‘hello’, ‘hello world’)
a) No output
b) []
c) <_sre.SRE_Match object; span=(0, 5), match=’hello’>
d) Error
27. 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
28. 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
29. What will be the output of the following Python code?
re.split(‘mum’, ‘mumbai*’, 1)
a) Error
b) [”, ‘bai*’]
c) [”, ‘bai’]
d) [‘bai*’]
30. What will be the output of the following Python code?
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’]Python Interview Questions (MCQs)
We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.