摘要: ![](https://img2018.cnblogs.com/blog/1632719/202003/1632719-20200301185531839-1928207993.png) ![](https://img2018.cnblogs.com/blog/1632719/202003/1632719-20200301220313604-1392892884.png) ![](https:// 阅读全文
posted @ 2020-03-01 18:30 西半球 阅读(96) 评论(0) 推荐(0) 编辑
摘要: ```python # 3.处理文件,用户指定要查找的文件和内容,将文件中包含要查找内容的每一行都输出到屏幕 # def check_file(filename,aim): # with open(filename,encoding='utf-8') as f: #句柄 : handler,文件操作符,文件句柄 # for i in f: # if aim in i: # yield i # # 阅读全文
posted @ 2020-03-01 18:13 西半球 阅读(90) 评论(0) 推荐(0) 编辑
摘要: ![](https://img2018.cnblogs.com/blog/1632719/202003/1632719-20200301165726353-1625694455.png) ![](https://img2018.cnblogs.com/blog/1632719/202003/1632719-20200301165803503-47788704.png) ![](https://im 阅读全文
posted @ 2020-03-01 18:09 西半球 阅读(99) 评论(0) 推荐(0) 编辑
摘要: ```python # 迭代器和生成器 # 迭代器: # 双下方法 : 很少直接调用的方法。一般情况下,是通过其他语法触发的 # 可迭代的 —— 可迭代协议 含有__iter__的方法('__iter__' in dir(数据)) # 可迭代的一定可以被for循环 # 迭代器协议: 含有__iter__和__next__方法 # 迭代器一定可迭代,可迭代的通过调用iter()方法就能得到一个迭代器 阅读全文
posted @ 2020-02-28 21:24 西半球 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 复习 阅读全文
posted @ 2020-02-27 20:47 西半球 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 迭代器 生成器 监听文件输入的例子 阅读全文
posted @ 2020-02-24 21:10 西半球 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 装饰器 进阶 阅读全文
posted @ 2020-02-24 21:08 西半球 阅读(82) 评论(0) 推荐(0) 编辑
摘要: ```python # 1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), # 要求登录成功一次,后续的函数都无需再输入用户名和密码 # FLAG = False # def login(func): # def inner(*args,**kwargs): # global FLAG # '''登录程序''' # if FLAG: # ret = func(*args, ** 阅读全文
posted @ 2020-02-24 21:05 西半球 阅读(65) 评论(0) 推荐(0) 编辑
摘要: ```python # 装饰器形成的过程 : 最简单的装饰器 有返回值的 有一个参数 万能参数# 装饰器的作用# 原则 :开放封闭原则# 语法糖 :@# 装饰器的固定模式#不懂技术import time# print(time.time()) # 获取当前时间# time.sleep(10) #让程序在执行到这个位置的时候停一会儿# def timmer(f): #装饰器函数# ... 阅读全文
posted @ 2020-02-17 14:17 西半球 阅读(87) 评论(0) 推荐(0) 编辑
摘要: ```python# 2、写函数,接收n个数字,求这些参数数字的和。def sum_func(*args): total = 0 for i in args: total += i return totalprint(sum_func(1,2,3,8,23,6))# 3、读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?# a=10# b=20# def test5(a,b)... 阅读全文
posted @ 2020-02-17 10:23 西半球 阅读(73) 评论(0) 推荐(0) 编辑