Python-AttributeError: 'NoneType' object has no attribute 'groups'

源代码

源代码如下,报错:

>>>import re
>>>re_telephone = re.compile(r'^(\d{3})-(\d{3,8})$')
>>>re_telephone.match('010-12345').groups()
>>>('010', '12345')
>>>re_telephone.match('01-12').groups()
Traceback (most recent call last):
 File "<input>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groups'

原因

如果没有匹配到任何group,那么就会返回这个错误。并不是语句写错了。

猜你喜欢

转载自blog.csdn.net/lonesome_zxq/article/details/84928873