Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
What is a regular expression in Python?
A
A method to change strings in Python.
B
A sequence of characters that define a search pattern.
C
A built-in Python library for manipulating dates.
D
A type of Python syntax error.
Which function in the re module is used to search for a pattern in a string?
A
re.findall()
B
re.match()
C
re.search()
D
re.split()
What will the following Python code using regular expressions output?
import re
pattern = r"\bfo"
text = "football is a sport and a football game"
print(re.findall(pattern, text))
A
['fo', 'fo']
B
['football', 'football']
C
['foot', 'foot']
D
[]
Using re.sub(), how can you replace all digits in the string 'abc123def' with '#'?
Choose all correct options
re.sub(r'\d', '#', 'abc123def')
re.sub(r'\d+', '#', 'abc123def')
re.sub(r'[0-9]', '#', 'abc123def')
All of the above
What does the ^ symbol represent in regular expressions when used outside of a character class?
A
It matches the end of a string.
B
It negates the character class.
C
It matches the start of a string.
D
It is a syntax error unless inside a character class.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next