Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么返回一个空的元组?_Python_Regex - Fatal编程技术网

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')

天啊,我完全误解了这一点。我现在明白了。谢谢,天啊,我完全误解了。我现在明白了。谢谢