第十三课 复习 正则

一、复习

1.文件操作 

 import codecs

with codces.open("1.txt","r") as f:

f.truncate()  清空

f.write()  字符串

f.read()  返回值字符值

f.readlines 返回的是列表

f.readline 返回的是一行

f.seek 寻找,设置偏移量

f.tell 光标在哪里

pass

2.lambda函数

a=lambda x:  x*x    \\a代表函数

迭代器  [x for x in range(1,10) if x%2 ==0 ]

高阶函数 sorted() 可迭代对象,key  反转

3.return和yield区别

4.()跟[]区别 

装饰,列表生成式

5.两个List相加 +

  两个字典相加 update

6.类 class (类都是大写)

构造器 __init__(args)

装饰器 super(子类,self)

继承 A(B) \\A类继承于B

类的封装 a.实例化

               b.main()

               c.if__name__=='__main__':

__init__ 实例化时间需要执行

__name__ 

7.装饰器作用:在不改变函数情况下,对函数增加一些功能

8.常用模块

OS模块  os.mkdir

              os.path.exist ()是否存在文件

              os.linesep 换行

              os.system("ipconfig")  执行系统命令

json模块 json.loads()

              json.dumps()

              json.load()

 commands模块  Python2

 getstatusoutput \\返回结果值

sys模块

import sys

            sys.argv[1]  \\获取第一个参数

random模块

random.random()  0-1取值之间

random.randint(a,b)

random.sample(itertable,k)  验证码

string模块

               string.punctugtion 特殊字符

logging模块

              logger = logging.getlogger(__name__)

              logger.debug

hashlib模块

             m=hashlid.md5()

             src="abcd"

             m.update(bytes(src))

加密 m.hexdigest()

datetime模块

              from datetime import datetime

              datetime.now()

              datetime.year  month  day  hour minute  second

               datetime.now.strptime("%Y-%m-%d")   字符串转换成时间

time模块

              time.time()

               time.sleep(10)

StringIO  模块

              from  io import StringIO ,ByesIO

              s=StringIO()

              s.write("hello word")

              s.getvalue()

              s.truncate() 清空

二、正则

常用的网站  http://tool.oschina.net/regex 正则表达式


1.re.match函数


2.re.search方法

















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值