PYTHON QUIZ
1 .
Which module in Python supports regular expressions?

Correct Answer : Option (A)

re
  Show Answer
2 .
Which of the following creates a pattern object?

Correct Answer : Option (C)

re.compile(str)
  Show Answer
3 .
What does the function re.match do?

Correct Answer : Option (A)

matches a pattern at the start of the string
  Show Answer
4 .
What will be the output of the following Python code?
 
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.groups())

Correct Answer : Option (B)

(‘we’, ‘are’, ‘humans’)
  Show Answer
5 .
What will be the output of the following Python code?
 
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.group(2))

Correct Answer : Option (D)

‘humans’
  Show Answer
6 .
What will be the output of the following Python code?
 
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groups())

Correct Answer : Option (B)

(‘horses’, ‘are’, ‘fast’)
  Show Answer
7 .
The expression a{5} will match _____________ characters with the previous regular expression.

Correct Answer : Option (B)

exactly 5
  Show Answer
8 .
What will be the output of the following Python code?
 
re.split('\W+', 'Hello, hello, hello.')

Correct Answer : Option (D)

[‘Hello’, ‘hello’, ‘hello’, ”]
  Show Answer
9 .
Which of the following functions results in case insensitive matching?

Correct Answer : Option (C)

re.I
  Show Answer
10 .
Which of the following functions creates a Python object?

Correct Answer : Option (A)

re.compile(str)
  Show Answer