摘要: 1.创建和打开文件 (1)打开模式: r:以只读模式打开;r+:以读写模式打开;w:以只写模式打开(重写文件,不存在则创建) w+:以读/写模式打开;a:只写模式(只允许在末尾追加);a+以读/写模式打开 >>> fo=open('test.txt')>>> fo<open file 'test.t 阅读全文
posted @ 2019-10-02 23:45 lemon不酸 阅读(733) 评论(0) 推荐(0) 编辑
摘要: 1.编译正则表达式(re.compile()) >>>import re >>> r1=r"\d{3,4}-?\d{8}">>> p_tel=re.compile(r1)>>> p_tel<_sre.SRE_Pattern object at 0x00000000016A7C70> >>> p_te 阅读全文
posted @ 2019-10-02 19:08 lemon不酸 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 1.字符匹配 (1)普通字符 大多数字母和字符会和自身匹配 (2)元字符 . ^ $ * + ? {} \ | () 2.元字符理解 (1)[]用来指定字符集:[a-z],元字符在字符集中不起作用,补集匹配不在区间范围内字符 >>> st="top tip tqp twp tep">>> res=r 阅读全文
posted @ 2019-10-02 17:43 lemon不酸 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 1.map函数(对指定序列映射到指定函数,返回结果集) >>> a=[1,3,5]>>> b=[2,4,6]>>> def mf(x,y):... return x*y...>>> map(None,a,b)[(1, 2), (3, 4), (5, 6)]>>> map(mf,a,b)[2, 12, 阅读全文
posted @ 2019-10-02 14:49 lemon不酸 阅读(479) 评论(0) 推荐(0) 编辑