python中可以使用正则表达式[a-zA-Z]来匹配字符串中是否有字母。
import <a href="https://www.gaodaima.com/tag/re" title="查看更多关于re的文章" target="_blank">re</a> str0='123m123' str1='123123' print(bool(re.<a href="https://www.gaodaima.com/tag/search" title="查看更多关于search的文章" target="_blank">search</a>('[a-zA-Z]', str0))) print(bool(re.search('[a-zA-Z]', str1)))
www#gaodaima.com来源gaodai$ma#com搞$代*码网搞代码
输出结果:
True
False
re.search 扫描整个字符串并返回第一个成功的匹配。
函数语法:
re.search(pattern, string, flags=0)
更多Python知识请关注搞代码网。
来源:搞代码网:原文地址:https://www.gaodaima.com