What will be the output of the following Python code? [code]n = re.sub(r'\w+', 'Hello', 'Cats and dogs')[/code]

Tâm Tây

New member
What will be the output of the following Python code?
Code:
n = re.sub(r'\w+', 'Hello', 'Cats and dogs')
A.
Hello
Hello
Hello
B. ‘Hello Hello Hello’
C. [‘Hello’, ‘Hello’, ‘Hello’]
D. (‘Hello’, ‘Hello’, ‘Hello’)
 
Answer: b
Explanation: The code shown above demonstrates the function re.sub. Since the string given as an argument consists of three words. The output of the code is: ‘Hello Hello Hello’. Had the string consisted of 4 words, the output would be: ‘Hello Hello Hello Hello’
 

Tìm kiếm

Back
Top