What will be the output of the following Python code? [code]re.split(r'(a)(t)', 'Maths is a difficult subject')[/code]

Ẽm Thư

New member
What will be the output of the following Python code?
Code:
re.split(r'(a)(t)', 'Maths is a difficult subject')
A. [‘M a t h s i s a d i f f i c u l t s u b j e c t’]
B. [‘Maths’, ‘is’, ‘a’, ‘difficult’, ‘subject’]
C. ‘Maths is a difficult subject’
D. [‘M’, ‘a’, ‘t’, ‘hs is a difficult subject’]
 
Answer: d
Explanation: The code shown above demonstrates the use of the function re.match. The first argument of this function specifies the pattern. Since the pattern contains groups, those groups are incorporated in the resultant list as well. Hence the output of the code shown above is [‘M’, ‘a’, ‘t’, ‘hs is a difficult subject’].
 

Tìm kiếm

Back
Top