为什么这会返回一个空元组?

tem*_*ame 0 python regex

s = "hello cats"
print(re.search(r"hello",s).groups())
Run Code Online (Sandbox Code Playgroud)

这打印().

根据文档,如果没有找到匹配项,groups()将返回一个空元组.那为什么不匹配呢?

eum*_*iro 6

groups返回匹配的.你没有定义任何:

s = "hello cats"
print(re.search(r"(he)l(lo)",s).groups())
Run Code Online (Sandbox Code Playgroud)

版画 ('he', 'lo')