Test Series - python

Test Number 94/108

Q: The function of re.search is __________
A. Matches a pattern at the start of the string
B. Matches a pattern at the end of the string
C. Matches a pattern from any part of a string
D. Such a function does not exist
Solution: The re module of Python consists of a function re.search. It’s function is to match a pattern from anywhere in a string.
Q: Which of the following functions creates a Python object?
A. re.compile(str)
B. re.assemble(str)
C. re.regex(str)
D. re.create(str)
Solution: The function re.compile(srt) compiles a pattern of regular expression into an object of regular expression. Hence re.compile(str) is the only function from the above options which creates an object.
Q: Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression?
A. re.L
B. re.S
C. re.U
D. re.X
Solution: The modifier re.X allows whitespace and comments inside the regular expressions.
Q: The function of re.match is ____________
A. Error
B. Matches a pattern anywhere in the string
C. Matches a pattern at the end of the string
D. Matches a pattern at the start of the string
Solution: The function of re.match matches a pattern at the start of the string.
Q: The special character B matches the empty string, but only when it is _____________
A. at the beginning or end of a word
B. not at the beginning or end of a word
C. at the beginning of the word
D. at the end of the word
Solution: The special character B matches the empty string, but only when it is not at the beginning or end of a word.
Q: Which of the following special characters matches a pattern only at the end of the string?
A. B
B. X
C. 
D. A
Solution: B matches a pattern which is not at the beginning or end of a string. X refers to re.VERBOSE. A matches a pattern only at the start of a string.  matches a pattern only at the end of a string.

You Have Score    /6