Site icon i2tutorials

Python-Regular-Expressions-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1. Which of the following creates a pattern object?
re.create(str)
re.regex(str)
re.compile(str)
re.assemble(str)

Correct!

Wrong!

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

Correct!

Wrong!

3. Choose the correct option from below that matches the start of the string and end of the string.
‘^’, ‘$’
‘$’, ‘^’
‘$’, ‘?’
‘?’, ‘^’

Correct!

Wrong!

4. What will be the output of the following Python code?
re.split('W+', 'Hello, hello, hello.')
[‘Hello’, ‘hello’, ‘hello.’]
[‘Hello, ‘hello’, ‘hello’]
[‘Hello’, ‘hello’, ‘hello’, ‘.’]
[‘Hello’, ‘hello’, ‘hello’, ' ']

Correct!

Wrong!

5. The function re.error raises an exception if a particular string contains no match for the given pattern.
True
False

Correct!

Wrong!

6. The special character B matches the empty string, but only when it is _____________
at the beginning or end of a word
not at the beginning or end of a word
at the beginning of the word
at the end of the word

Correct!

Wrong!

7. What will be the output of the following Python code?
re.subn('A', 'X', 'AAAAAA', count=4)
‘XXXXAA, 4’
(‘AAAAAA’, 4)
(‘XXXXAA’, 4)
‘AAAAAA, 4’

Correct!

Wrong!

8. What will be the output of the following Python code?
w = re.compile('[A-Za-z]+')
w.findall('It will rain today')
‘It will rain today’
(‘It will rain today’)
[‘It will rain today’]
[‘It’, ‘will’, ‘rain’, ‘today’]

Correct!

Wrong!

9. Which of the following functions does not accept any argument?
re.purge
re.compile
re.findall
re.match

Correct!

Wrong!

10. What will be the output of the following Python code?
a = re.compile('0-9')
a.findall('3 trees')
[ ]
[‘3’]
Error
[‘trees’]

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Regular-Expressions-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version