What will be the output of the following Python code? [code]a = re.compile('0-9') a.findall('3 trees')[/code]

Giang Phạm

New member
What will be the output of the following Python code?
Code:
a = re.compile('0-9')
a.findall('3 trees')
A. []
B. [‘3’]
C. Error
D. [‘trees’]
 
Answer: c
Explanation: The output of the code shown above is an empty list. This is due to the way the arguments have been passed to the function re.compile. Carefully read the code shown below in order to understand the correct syntax:
>>> a = re.compile(‘[0-9]’)
>>> a.findall(‘3 trees’)
[‘3’].
 

Tìm kiếm

Back
Top