上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页
摘要: # yield 生成器 # 1.调用yield函数的时候,并不会直接执行这个函数,而是返回一个generator对象 # 2.next去取值的时候,都会直接走到yield就停止(大家可以暂时把yield看成return) # 3.当你yield执行完毕的时候,就相当于这个函数执行结束,直到下次调用n 阅读全文
posted @ 2021-05-03 21:13 Z_sun 阅读(79) 评论(0) 推荐(0) 编辑
摘要: # 匿名函数 lambda # lambda 参数1,参数2:返回的结果 def a(a, b): return a * b # 效果同上面的一致 lambda_a = lambda a, b: a * b # 调用函数 print(a(3, 5)) print('匿名函数调用方法一:',lambd 阅读全文
posted @ 2021-05-03 16:50 Z_sun 阅读(528) 评论(0) 推荐(0) 编辑
摘要: # 闭包 def outer(x): print('outer:',x) def inner(): print('inner:', x) return inner # 外部函数return的一定是内部函数的函数名 def a(x): print('a:',x) def b(y): print('b: 阅读全文
posted @ 2021-05-02 18:33 Z_sun 阅读(74) 评论(0) 推荐(0) 编辑
摘要: # 兔子问题: # 1 1 2 3 5 7 12 # 第一天1只兔子 第二天1只兔子 第三天2只兔子 第四天3只兔子 后面每天的兔子数等于前2天的兔子数之和 # 定义函数,计算第n天的兔子数 def rabbit(n): # 递归结束的条件:n=2 # 第一天和第二天兔子数都是1 if n == 1 阅读全文
posted @ 2021-05-02 18:31 Z_sun 阅读(105) 评论(0) 推荐(0) 编辑
摘要: import os import time # 获取当前文件的绝对路径 dir_1 = os.path.abspath(__file__) # D:\workspace\web-test\Study\Day_5-16\tset3.py # 获取当前文件所在目录的上级路径 dir_2 = os.get 阅读全文
posted @ 2021-05-02 12:27 Z_sun 阅读(109) 评论(0) 推荐(0) 编辑
摘要: # 捕获异常,异常之后,代码不再执行 try : a = 1/0 except ZeroDivisionError as e : print('出异常了,原因:',e) except IOError as e: print('IO异常,原因:', e) except ValueError as e: 阅读全文
posted @ 2021-04-15 16:00 Z_sun 阅读(60) 评论(0) 推荐(0) 编辑
摘要: # re 正则表达式 import re import requests with open('youdao.html',encoding='utf-8',mode='r') as f: date = f.read() pattren = re.compile('翻译') # 输入要匹配的内容 r1 阅读全文
posted @ 2021-04-15 15:57 Z_sun 阅读(80) 评论(0) 推荐(0) 编辑
摘要: # unittest 单元测试框架(必须使用类去做) import unittest class TestFuncation(unittest.TestCase): @classmethod def setUpClass(cls): print('\n************整个类最开始执行**** 阅读全文
posted @ 2021-04-12 19:34 Z_sun 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 一:准备工作(创建数据库) 二:在python中连接数据库并操作 pip install pymysql # 安装第三方库 # 连接mysql数据库,做数据库存储 import pymysql # 连接数据库 connection_fanmao = pymysql.Connection( host= 阅读全文
posted @ 2021-04-02 17:30 Z_sun 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 一:说明 使用pytest 框架的时候,我们可以对测试结果,生成测试报告 支持的第三方插件有很多,我们以 pytest-html 为例说明 二:pytest-html pip install pytest-html # 安装第三方库 # test_case1.py文件 def test_case01 阅读全文
posted @ 2021-04-01 17:34 Z_sun 阅读(375) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页