使用循环遍历字符串,在循环中使用isalpha()方法判断字符是否为字母,若为字母就替换为空格,然后将其中空格去除,最后通过判断长度来判断是否为纯字母。
<a href="https://www.gaodaima.com/tag/info" title="查看更多关于info的文章" target="_blank">info</a> = "gfhajsh136ju879kdi" for i in info: if i.isalpha(): info = info.replace(i," ")#若为字母,使用空格代替 l = info.split() if len(l)>0: print('不是纯字母') else: print('是纯字母')
www#gaodaima.com来源gao!%daima.com搞$代*!码网搞代码
输出如下:
不是纯字母
更多Python知识请关注搞代码网。
来源:搞代码网:原文地址:https://www.gaodaima.com