python compile() 函数

"""
    compile(source, filename, mode[, flags[, dont_inherit]])
    各个参数的具体说明如下所示:
            参数 source:字符串或者抽象语法树对象。
            参数 filename:代码文件名称,如果不从文件读取代码,则传递一些可辨认的值。
            参数 mode:指定编译代码的种类,可以指定为 exec、eval 和 single。
            参数 flags 和 dont_inherit:可选参数,极少使用。
"""
#使用函数 re.compile() 将正则表达式的字符串形式编译为 Pattern 实例
import re
pattern = re.compile('[a-zA-Z]')
result = pattern.findall('1@$%66as3SiOPdj#@23awe')   # ['a', 's', 'S', 'i', 'O', 'P', 'd', 'j', 'a', 'w', 'e']
print(result)

 

posted @ 2022-03-18 11:36  大熊童鞋  阅读(189)  评论(0编辑  收藏  举报