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

What will be the output of the following Python code?
Code:
re.split('\W+', 'Hello, hello, hello.')
A. [‘Hello’, ‘hello’, ‘hello.’]
B. [‘Hello, ‘hello’, ‘hello’]
C. [‘Hello’, ‘hello’, ‘hello’, ‘.’]
D. [‘Hello’, ‘hello’, ‘hello’, ”]
 
Answer: d
Explanation: In the code shown above, the function split() splits the string based on the pattern given as an argument in the parenthesis. Note: split will never split a string on an empty pattern match. Hence the output of this code is: [‘Hello’, ‘hello’, ‘hello’, ”].
 

Tìm kiếm

Back
Top