Python 为什么返回一个空的元组?
这将打印Python 为什么返回一个空的元组?,python,regex,Python,Regex,这将打印() 根据文档,如果没有找到匹配项,groups()将返回一个空元组。那么为什么不匹配呢?组返回匹配的组。您没有定义任何: s = "hello cats" print(re.search(r"hello",s).groups()) 打印('he','lo')组返回匹配的组。您没有定义任何: s = "hello cats" print(re.search(r"hello",s).groups()) 打印('he','lo')天啊,我完全误解了这一点。我现在明白了。谢谢,天啊,我完全
()
根据文档,如果没有找到匹配项,groups()将返回一个空元组。那么为什么不匹配呢?
组
返回匹配的组。您没有定义任何:
s = "hello cats"
print(re.search(r"hello",s).groups())
打印
('he','lo')
组
返回匹配的组。您没有定义任何:
s = "hello cats"
print(re.search(r"hello",s).groups())
打印
('he','lo')
天啊,我完全误解了这一点。我现在明白了。谢谢,天啊,我完全误解了。我现在明白了。谢谢