摘要: 1. 编写有参函数装饰器 def auth(db_type): def deco(func): def wrapper(*args, **kwargs): name = input('name:').strip() psd = input('password:').strip() if db_typ 阅读全文
posted @ 2020-12-26 16:44 Avery_W 阅读(46) 评论(0) 推荐(0) 编辑
摘要: 1. 编写函数,(函数执行的时间用time.sleep(n)模拟) import time def count_time(): start = time.time() time.sleep(1) print('我是输出的内容!我要花费零点几毫秒的时间\n') stop = time.time() p 阅读全文
posted @ 2020-12-26 16:37 Avery_W 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 1. 函数对象优化多分支if的代码练熟 def exit(): print('退出') def login(): print('登录功能') def transfer(): print('转账功能个') def check_balance(): print('余额查询功能') def withdra 阅读全文
posted @ 2020-12-26 15:51 Avery_W 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 1. 定义域与名称空间解释 input = 333 # 定义全局变量input,赋值333 def func(): # 定义全局函数func input = 444 # 定义局部变量input,赋值444 func() # 调用全局函数func print(input) # 打印全局变量input的 阅读全文
posted @ 2020-12-26 15:47 Avery_W 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 1. 用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 def func(name, **kwargs): import os if not os.path.exists(r'{}'.format(name)): print('文件路径输入错误') return with open( 阅读全文
posted @ 2020-12-26 15:42 Avery_W 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 1. 编写文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改 import os def func(address, old_concent, new_concent): with open(r'{}'.format(address), 'rb') 阅读全文
posted @ 2020-12-26 15:37 Avery_W 阅读(57) 评论(0) 推荐(0) 编辑
摘要: 1. 编写文件copy工具 ori_file=input('原文件路径:').strip() cop_file=input('新文件路径:').strip() with open(r'{}'.format(ori_file), mode='rt', encoding='utf-8') as f1,\ 阅读全文
posted @ 2020-12-26 15:25 Avery_W 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 1. 有列表['alex',49,[1900,3,18]],分别取出列表中的名字,年龄,出生的年,月,日赋值给不同的变量 l = ['alex', 49, [1900, 3, 18]] name = l[0] age = l[1] age_year = l[2][0] age_month = l[2 阅读全文
posted @ 2020-12-26 15:19 Avery_W 阅读(64) 评论(0) 推荐(0) 编辑
摘要: for循环 1. for循环嵌套之打印99乘法表 # ①矩形输出九九乘法表: for i in range(1,10): for j in range(1,10): print(f'{i}X{j}={i*j}',end='') print() # ②左下三角形式九九乘法表: for i in ran 阅读全文
posted @ 2020-12-26 15:14 Avery_W 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 1. 使用while循环输出1 2 3 4 5 6 8 9 10 count = 0 while count < 10: count += 1 if count == 7: continue print(count) 2. 求1-100的所有数的和 count = 0 i = 0 while cou 阅读全文
posted @ 2020-12-26 15:07 Avery_W 阅读(58) 评论(0) 推荐(1) 编辑
摘要: 1. 用户输入姓名、年龄、工作、爱好 ,然后打印成以下格式 info of Egon Name : EgonAge : 22Sex : maleJob : Teacher end name = input('Name:') age = input('Age:') sex = input('Sex:' 阅读全文
posted @ 2020-12-26 15:01 Avery_W 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 嵌套取值操作 1. 请取出第一个学生的第一个爱好 students_info = [['egon', 18, ['play', ]], ['alex', 18, ['play', 'sleep']]] print(students_info[0][2][0]) 2. 针对字典,请取出取公司名 inf 阅读全文
posted @ 2020-12-26 14:46 Avery_W 阅读(55) 评论(0) 推荐(0) 编辑
摘要: sys模块内容 sys.argv # 命令行参数List,第一个参数是程序本身路径 sys.exit(n) # 退出程序,正常退出时exit(0) sys.version # 获取python解释程序的版本信息 sys.maxint # 最大的Int值 sys.path # 返回模块的搜索路径,初始 阅读全文
posted @ 2020-12-26 14:32 Avery_W 阅读(43) 评论(0) 推荐(0) 编辑