如何使用re.findall()
调用findall()方法时,若字符串匹配,则返回字符串
import re
a = re.findall('blue', 'blue')
print(a)
结果为:
D:\Python\python.exe
['blue']
Process finished with exit code 0
当findall()方法中字符串不匹配时,返回空组
import re
a = re.findall('blue', 'python')
print(a)
结果为:
D:\Python\python.exe
[]
Process finished with exit code 0
其次,当混合的字符串中包含了另外匹配的字符串,打印结果也会返回该字符串.
博客主要介绍了re.findall()方法的使用。调用该方法时,若字符串匹配则返回字符串;若不匹配则返回空组;当混合字符串中包含其他匹配字符串时,打印结果会返回该字符串。
4648

被折叠的 条评论
为什么被折叠?



