What will be the output of the following Python function? [code]re.findall("hello world", "hello", 1)[/code]

What will be the output of the following Python function?
Code:
re.findall("hello world", "hello", 1)
A. [“hello”]
B. [ ]
C. hello
D. hello world
 
Answer: b
Explanation: The function findall returns the word matched if and only if both the pattern and the string match completely, that is, they are exactly the same. Observe the example shown below:
>>> re.findall(“hello”, “hello”, 1) The output is: [‘hello’] Hence the output of the code shown in this question is [].
 

Tìm kiếm

Back
Top