Question 11
Back to Exercise
What is the output of the following Python program?
import re
text = "one two\nthree four"
print(re.findall(r"^\w+", text), re.findall(r"^\w+", text, re.M), re.findall(r"\w+$", text, re.M))
- A ['one', 'three'] ['one', 'three'] ['four']
- B ['one'] ['one'] ['four']
- C ['one'] ['one', 'three'] ['two', 'four'] Correct
- D ['one'] ['one', 'three'] ['four']
Correct Answer: Option C
Without re.M, ^ matches only at the very start. With it, ^ and $ match at every line start and end.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!