python清除字符串里非字母字符的方法,python字符串
python清除字符串里非字母字符的方法,python字符串
本文实例讲述了python清除字符串里非字母字符的方法。分享给大家供大家参考。具体如下:
s = "hello world! how are you? 0" # Short version print filter(lambda c: c.isalpha(), s) # Faster version for long ASCII strings: id_tab = "".join(map(chr, xrange(256))) tostrip = "".join(c for c in id_tab if c.isalpha()) print s.translate(id_tab, tostrip) # Using regular expressions print re.sub("[^A-Za-z]", "", s)
希望本文所述对大家的Python程序设计有所帮助。
相关内容
- Python中if __name__ == '__main__'作用解析,__name___main__
- Python实现把数字转换成中文,
- Python访问纯真IP数据库脚本分享,pythonip数据库脚本
- 编写Python CGI脚本的教程,编写pythoncgi脚本
- python实现的简单FTP上传下载文件实例,
- python实现线程池的方法,python线程池
- python实现在windows服务中新建进程的方法,pythonwindows
- python实现的系统实用log类实例,pythonlog类实例
- python实现DES加密解密方法实例详解,pythondes
- Python实现高效求解素数代码实例,python素数
评论关闭