当前位置: 首页 > 图灵资讯 > 行业资讯> python中findall()和finditer()的区别

python中findall()和finditer()的区别

发布时间:2024-06-24 13:44:09

1、findall()在输入字符串中查找所有匹配内容,如果匹配成功,返回match列表对象。

如果匹配失败,返回None。

2、finditer()在输入字符串中找到所有匹配内容,如果匹配成功,则返回可迭代对象。

每次都可以通过迭代对象返回一个match对象,如果匹配失败,则返回None。

实例

importre

p=r'[Jj]ava'
text='IlikeJavaandjava'

match_list=re.findall(p,text)①
print(match_list)

match_iter=re.finditer(p,text)②
forminmatch_iter:③
print(m.group())

以上就是python中findall()和finditer()的区别,希望对大家有所帮助。更多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09