diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2455e5f4a51257e917655c3638fd9c5ed642efe7..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -.git -/venv/ -/test -*/__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md index 0daf1a4db565d4f2bde81d24321445ceea2c310e..14d1c280ca60dbca6b31651cd16a26df7ecc6717 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ -# 痴海第二期 Python 训练营 - -链接: https://pan.baidu.com/s/1jNqqWurHDs8gFj1aEEhtEw 提取码: yc82 - - -痴海 Python 训练营第一周疑惑 -https://docs.qq.com/doc/DWVFNTktiRFFSQXZW - -痴海 Python 训练营第二周疑惑 -https://docs.qq.com/doc/DWWxEa3dXSXNFZ0lQ - -痴海 Python 训练营第三周课程&作业讲解 -https://docs.qq.com/doc/DWVBhY0NBWW9Ca1Rz - -痴海 Python 训练营第四周课程&作业讲解 -https://docs.qq.com/doc/DWXdSc1d4ZXRJUmx6 - -痴海 Python 训练营第五周总结&作业讲解 -https://docs.qq.com/doc/DWXNDeGN4R3ZoYXlt - -痴海 Python 训练营第六周总结&作业讲解 -https://docs.qq.com/doc/DWUN4YUhjam9jUEJQ - -痴海 Python 训练营第七周总结&作业讲解 -https://docs.qq.com/doc/DWUJ5eGxIcmpQa3pi - -安装包的百度网盘地址, virtualxposed和justtrustme在apk文件夹里 - -[![0x9E5T.png](https://s1.ax1x.com/2020/10/19/0x9E5T.png)](https://imgchr.com/i/0x9E5T) +# 痴海第二期 Python 训练营 + +链接: https://pan.baidu.com/s/1jNqqWurHDs8gFj1aEEhtEw 提取码: yc82 + + +痴海 Python 训练营第一周疑惑 +https://docs.qq.com/doc/DWVFNTktiRFFSQXZW + +痴海 Python 训练营第二周疑惑 +https://docs.qq.com/doc/DWWxEa3dXSXNFZ0lQ + +痴海 Python 训练营第三周课程&作业讲解 +https://docs.qq.com/doc/DWVBhY0NBWW9Ca1Rz + +痴海 Python 训练营第四周课程&作业讲解 +https://docs.qq.com/doc/DWXdSc1d4ZXRJUmx6 + +痴海 Python 训练营第五周总结&作业讲解 +https://docs.qq.com/doc/DWXNDeGN4R3ZoYXlt + +痴海 Python 训练营第六周总结&作业讲解 +https://docs.qq.com/doc/DWUN4YUhjam9jUEJQ + +痴海 Python 训练营第七周总结&作业讲解 +https://docs.qq.com/doc/DWUJ5eGxIcmpQa3pi + +安装包的百度网盘地址, virtualxposed和justtrustme在apk文件夹里 + +[![0x9E5T.png](https://s1.ax1x.com/2020/10/19/0x9E5T.png)](https://imgchr.com/i/0x9E5T) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index 53c095018586406a506af19e85028e1ca70181b8..76049fb5293d4ca97a0a0a9ba200279142005c8a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,34 +1,34 @@ -# 问题一和问题二:四大基本数据结构的有序和无序,可变和不可变 -对象 是否可变 是否有序 -list 可变 有序 -tuple 不可变 有序 -dict 可变 无序 -set 可变 无序 - - -# 问题三:创建包含6种数据类型的列表\元组\字典\集合 - -a = 5 # 整数 -b = 2.8 #浮点数 -c = "panderleo" # 字符串 -d = True #布尔值 -e = None # 空值 -f = bytes("tidy".encode("utf-8")) # bytes类型 - -# 创建列表list1 -list1 = [a,b,c,d,e,f] -print("list1 = ",list1,"\nlist1的类型为:",type(list1)) - -# 创建元组tuple1 -tuple1 = (a,b,c,d,e,f) -print("tuple1 = ",tuple1,"\ntuple1的类型为:",type(tuple1)) - -# 创建集合set1 -set1 = {a,b,c,d,e,f} - -print("set1 = ",set1,"\nset1的类型为:",type(set1)) - -# 创建字典dict -dict1 = {a:1,b:3.5,c:"griffin",d:0,e:None,f:b"leo"} - +# 问题一和问题二:四大基本数据结构的有序和无序,可变和不可变 +对象 是否可变 是否有序 +list 可变 有序 +tuple 不可变 有序 +dict 可变 无序 +set 可变 无序 + + +# 问题三:创建包含6种数据类型的列表\元组\字典\集合 + +a = 5 # 整数 +b = 2.8 #浮点数 +c = "panderleo" # 字符串 +d = True #布尔值 +e = None # 空值 +f = bytes("tidy".encode("utf-8")) # bytes类型 + +# 创建列表list1 +list1 = [a,b,c,d,e,f] +print("list1 = ",list1,"\nlist1的类型为:",type(list1)) + +# 创建元组tuple1 +tuple1 = (a,b,c,d,e,f) +print("tuple1 = ",tuple1,"\ntuple1的类型为:",type(tuple1)) + +# 创建集合set1 +set1 = {a,b,c,d,e,f} + +print("set1 = ",set1,"\nset1的类型为:",type(set1)) + +# 创建字典dict +dict1 = {a:1,b:3.5,c:"griffin",d:0,e:None,f:b"leo"} + print("dict1 = ",dict1,"\ndict1的类型为:",type(dict1)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" index 7ca47d60e443aecc719b3939651b9a7e8f114968..b99679275e31587fdb159012f233aa557b9e6252 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" @@ -1,137 +1,137 @@ -# 作业1、用for循环和while循环完成简单的计数 -# 作业2、用for循环和while循环两种方式来实现斐波那契函数,限制在100以内 -# - 斐波那契函数 -# 第N项是N - 1,N - 2的和 -# F(n) = F(n - 1) + F(n - 2) -# [0, 1, 1, 2, 3, 5, 8, 13, 21....] -# 作业3、在第二周 - 第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError - -# 用for 循环完成简单计数 -count = 0 -for i in range(10, 100, 6): - if count <= 15: - count += 1 - print(f"第 {count} 个数为:", i) - - -for i, e in enumerate(range(20, 100, 5)): - print(f"索引:{i}, 值:{e}") - -# 用 while 循环完成简单计数 -count = 1 -while count < 9: - print(f"这是第 {count} 次打印本行") - count += 1 - - -# 用for循环来实现斐波那契函数,限制在100以内 -f1 = 0 -f2 = 1 -fn = 1 -list1 = [] - -for i in range(20): - fn = f2 + f1 - f1 = f2 - f2 = fn - if i == 0: - list1.append(0) - if i == 1: - list1.append(1) - if i == 2: - list1.append(fn) - else: - list1.append(fn) -print(list1) - - -# 用while循环两种方式,限制在100以内 -w0 = 0 -w1 = 1 -wn = 1 -list2 = [] -n = 0 -m = 20 -while True: - wn = w0 + w1 - w0 = w1 - w1 = wn - if n == 0: - list2.append(0) - if n == 1: - list2.append(1) - else: - list2.append(wn) - if n == m: - break - print(wn) - n += 1 - - - - -# 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError - -# 和 -def add(a, b): - return a + b - - -# 差 -def minus(a, b): - return a - b - - -# 积 -def multiply(a, b): - return a * b - - -class ParamsError(Exception): - pass - - -# 商 -def divide(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function my_sub end") - - -# 整除 - -def divisi(a, b): - try: - return a // b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function my_sub end") - - -# 取余 -def rem(a, b): - return a % b - - -# 幂 -def pow(a, b): - return a ** b - - -# 开方 -def root(a, b): - return a ** (1 / b) - - -print('256+4等于:', add(256, 4)) -print('256-4等于:', minus(256, 4)) -print('256*4等于:', multiply(256, 4)) -print('256/0等于:', divide(256, 0)) -print('256整除0等于:', divisi(256, 0)) -print('256/4余数为:', rem(256, 4)) -print('256的4次幂等于:', pow(256, 4)) +# 作业1、用for循环和while循环完成简单的计数 +# 作业2、用for循环和while循环两种方式来实现斐波那契函数,限制在100以内 +# - 斐波那契函数 +# 第N项是N - 1,N - 2的和 +# F(n) = F(n - 1) + F(n - 2) +# [0, 1, 1, 2, 3, 5, 8, 13, 21....] +# 作业3、在第二周 - 第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError + +# 用for 循环完成简单计数 +count = 0 +for i in range(10, 100, 6): + if count <= 15: + count += 1 + print(f"第 {count} 个数为:", i) + + +for i, e in enumerate(range(20, 100, 5)): + print(f"索引:{i}, 值:{e}") + +# 用 while 循环完成简单计数 +count = 1 +while count < 9: + print(f"这是第 {count} 次打印本行") + count += 1 + + +# 用for循环来实现斐波那契函数,限制在100以内 +f1 = 0 +f2 = 1 +fn = 1 +list1 = [] + +for i in range(20): + fn = f2 + f1 + f1 = f2 + f2 = fn + if i == 0: + list1.append(0) + if i == 1: + list1.append(1) + if i == 2: + list1.append(fn) + else: + list1.append(fn) +print(list1) + + +# 用while循环两种方式,限制在100以内 +w0 = 0 +w1 = 1 +wn = 1 +list2 = [] +n = 0 +m = 20 +while True: + wn = w0 + w1 + w0 = w1 + w1 = wn + if n == 0: + list2.append(0) + if n == 1: + list2.append(1) + else: + list2.append(wn) + if n == m: + break + print(wn) + n += 1 + + + + +# 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError + +# 和 +def add(a, b): + return a + b + + +# 差 +def minus(a, b): + return a - b + + +# 积 +def multiply(a, b): + return a * b + + +class ParamsError(Exception): + pass + + +# 商 +def divide(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function my_sub end") + + +# 整除 + +def divisi(a, b): + try: + return a // b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function my_sub end") + + +# 取余 +def rem(a, b): + return a % b + + +# 幂 +def pow(a, b): + return a ** b + + +# 开方 +def root(a, b): + return a ** (1 / b) + + +print('256+4等于:', add(256, 4)) +print('256-4等于:', minus(256, 4)) +print('256*4等于:', multiply(256, 4)) +print('256/0等于:', divide(256, 0)) +print('256整除0等于:', divisi(256, 0)) +print('256/4余数为:', rem(256, 4)) +print('256的4次幂等于:', pow(256, 4)) print('256开4次方根为:', root(256, 4)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index c1b304f9c9d1ec98fd1520f4b367afc52d575705..3b7da7c290d165249d7d8f6d0863fef1938b82c4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,125 +1,125 @@ -- 1.背诵作用域的概念 -- 2. 练习作用域之间的转换 -- 3.默写一个装饰器, 用来输出函数的执行时间. -- 4.使用装饰器来为斐波那契函数添加缓存 - -def cache_deco(func): -# 保存n执行后的结果 -a = {} -# 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 -result = func(n) -return result - -@cache_deco -def fibo(n): -pass - - - -# 1.背诵作用域的概念 -# 程序创建、访问、改变一个变量的时候, -# 都是在一个保存该变量的空间内进行, -# 整个空间被称为命名空间,即作用域 - -#2. 练习作用域之间的转换 -a = 1 - - -def foo(): - a = 2 - print(a) - - -print('输出foo函数中a = 2', foo()) -print('输出最上面的a=1:', a) - -# 全局变量global -b = 1 - - -def foo(): - global b - b = 2 - print(b) - - -print("下面将打印全局变量b=2:") -foo() -print('右边打印foo函数里面的全局变量b:', b) - -# 局部变量 -a = 1 -b = [] - - -def foo(): - a = 2 - b.append(2) - return None - - -foo() -print('打印a值1:', a) -print('打印b列表:', b) - -# 3.默写一个装饰器, 用来输出函数的执行时间. - - -def clock_it_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} 执行时间: {format(end_time - start_time, '.2f')} s") - return result - return wrapper - - -# @clock_it_deco -def fib(n): - if n <= 1: - return n - else: - return fib(n - 1) + fib(n - 2) - - -print(fib(15)) - -# 装饰器计时 -a = 1 - - -@clock_it_deco -def foo(): - a = 2 - print(a) - - -print('输出foo函数中a = 2', foo()) -print('输出最上面的a=1:', a) - - -# 4.使用装饰器来为斐波那契函数添加缓存 - - -def cache_deco(func): - - a = {} - - def wrapper(n): - if n in a: - return a[n] - else: - result = func(n) - return result - return wrapper - -@cache_deco -def fib(n): - if n <= 1: - return n - else: - return fib(n - 1) + fib(n - 2) - - +- 1.背诵作用域的概念 +- 2. 练习作用域之间的转换 +- 3.默写一个装饰器, 用来输出函数的执行时间. +- 4.使用装饰器来为斐波那契函数添加缓存 + +def cache_deco(func): +# 保存n执行后的结果 +a = {} +# 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 +result = func(n) +return result + +@cache_deco +def fibo(n): +pass + + + +# 1.背诵作用域的概念 +# 程序创建、访问、改变一个变量的时候, +# 都是在一个保存该变量的空间内进行, +# 整个空间被称为命名空间,即作用域 + +#2. 练习作用域之间的转换 +a = 1 + + +def foo(): + a = 2 + print(a) + + +print('输出foo函数中a = 2', foo()) +print('输出最上面的a=1:', a) + +# 全局变量global +b = 1 + + +def foo(): + global b + b = 2 + print(b) + + +print("下面将打印全局变量b=2:") +foo() +print('右边打印foo函数里面的全局变量b:', b) + +# 局部变量 +a = 1 +b = [] + + +def foo(): + a = 2 + b.append(2) + return None + + +foo() +print('打印a值1:', a) +print('打印b列表:', b) + +# 3.默写一个装饰器, 用来输出函数的执行时间. + + +def clock_it_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} 执行时间: {format(end_time - start_time, '.2f')} s") + return result + return wrapper + + +# @clock_it_deco +def fib(n): + if n <= 1: + return n + else: + return fib(n - 1) + fib(n - 2) + + +print(fib(15)) + +# 装饰器计时 +a = 1 + + +@clock_it_deco +def foo(): + a = 2 + print(a) + + +print('输出foo函数中a = 2', foo()) +print('输出最上面的a=1:', a) + + +# 4.使用装饰器来为斐波那契函数添加缓存 + + +def cache_deco(func): + + a = {} + + def wrapper(n): + if n in a: + return a[n] + else: + result = func(n) + return result + return wrapper + +@cache_deco +def fib(n): + if n <= 1: + return n + else: + return fib(n - 1) + fib(n - 2) + + print(fib(20)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" index afe4fdaad648daf3bd14e08f77bcfb3c801ec8ef..3d48278c3b5903cbd29c4765bcc010e83f3e881b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" @@ -1,79 +1,79 @@ -作业1、给定一个列表, 根据grade来排序 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -作业二、通过filter语句来筛选出Grade为A的同学 - -作业三、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) - -作业四、使用递归函数重构斐波那契函数 -f(n) = f(n-1) + f(n-2) - - -# 1.根据grade排序 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] - -classes1 = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -print("classes的类型为:", type(classes)) - -classes.sort(key=lambda x: x['grade']) -for cl in classes: - print(cl) -print("classes的类型为:", type(classes)) - - -# 2.通过filter语句来筛选出Grade为A的同学 - -f = filter(lambda x: x["grade"] == "A", classes) - -print(list(f)) - - -# 3.通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda) - -# 用了lmbda 增加classes1 -m1 = map(lambda x: x["age"] + 1, classes1) - -print("classes1年龄加1岁:", list(m1)) - -# 不用lmbda,classes加一岁 - -def add(n): - n["age"] = n['age'] + 1 - return n - -m = map(add, classes) -print("不用lambda:", list(m)) - -# 4.使用递归函数重构斐波那契函数 - - -def fib(n): - if n <= 1: - return n - else: - return fib(n - 1) + fib(n - 2) - +作业1、给定一个列表, 根据grade来排序 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +作业二、通过filter语句来筛选出Grade为A的同学 + +作业三、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) + +作业四、使用递归函数重构斐波那契函数 +f(n) = f(n-1) + f(n-2) + + +# 1.根据grade排序 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + +classes1 = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +print("classes的类型为:", type(classes)) + +classes.sort(key=lambda x: x['grade']) +for cl in classes: + print(cl) +print("classes的类型为:", type(classes)) + + +# 2.通过filter语句来筛选出Grade为A的同学 + +f = filter(lambda x: x["grade"] == "A", classes) + +print(list(f)) + + +# 3.通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda) + +# 用了lmbda 增加classes1 +m1 = map(lambda x: x["age"] + 1, classes1) + +print("classes1年龄加1岁:", list(m1)) + +# 不用lmbda,classes加一岁 + +def add(n): + n["age"] = n['age'] + 1 + return n + +m = map(add, classes) +print("不用lambda:", list(m)) + +# 4.使用递归函数重构斐波那契函数 + + +def fib(n): + if n <= 1: + return n + else: + return fib(n - 1) + fib(n - 2) + print(fib(15)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" index 464fb4787b2417ee5ea471ed2374ff86a85f20f8..4038c85fead0640317a0c7b20681c7f546487799 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" @@ -1,41 +1,41 @@ -#my_calculator.py - -#和 -def add(a,b): - return a + b - -#差 -def minus(a,b): - return a - b - -#积 -def multiply(a,b): - return a * b - -#商 -def divide(a,b): - return a / b - -#整除 -def divisi(a,b): - return a // b - -#取余 -def rem(a,b): - return a % b - -#幂运算 -def pow(a,b): - return a ** b -#开方运算 -def root(a,b): - return a **(1/b) - -print('256+4等于:',add(256,4)) -print('256-4等于:',minus(256,4)) -print('256*4等于:',multiply(256,4)) -print('256/4等于:',divide(256,4)) -print('256整除4等于:',divisi(256,4)) -print('256/4余数为:',rem(256,4)) -print('256的4次幂等于:',pow(256,4)) +#my_calculator.py + +#和 +def add(a,b): + return a + b + +#差 +def minus(a,b): + return a - b + +#积 +def multiply(a,b): + return a * b + +#商 +def divide(a,b): + return a / b + +#整除 +def divisi(a,b): + return a // b + +#取余 +def rem(a,b): + return a % b + +#幂运算 +def pow(a,b): + return a ** b +#开方运算 +def root(a,b): + return a **(1/b) + +print('256+4等于:',add(256,4)) +print('256-4等于:',minus(256,4)) +print('256*4等于:',multiply(256,4)) +print('256/4等于:',divide(256,4)) +print('256整除4等于:',divisi(256,4)) +print('256/4余数为:',rem(256,4)) +print('256的4次幂等于:',pow(256,4)) print('256开4次方根为:',root(256,4)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index 20e73c280e4da10c02dd7b2a8e639e90ef5b1348..c413bf809ed24ee7ed76c76aaef90f2c920f3ae7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,146 +1,146 @@ -# 作业:完成四大基础数据结构的CRUD操作 - -# list 列表的操作 -# list-creat 增加 -# append末尾添加元素 -l_1 = [] -print('id(l_1):', id(l_1)) -l_1.append('a') -print("用append末尾添加元素a:", l_1) -print('添加 a 元素之后的l的id为:', id(l_1)) - -# + 拼接两个列表 -l_2 = ["z", 'y', 'x'] -print("拼接两个列表:", l_1 + l_2) - -# +=加法赋值 -l_1 += ['b'] -print("加法赋值:", l_1) - -# * 和 *= -print("乘法赋值之前的l_1的id:", id(l_1)) -l_1 = [l_1] * 5 -print("乘法赋值结果:", l_1) -print("乘法赋值之后的l_1的id:", id(l_1)) - -# insert指定位置添加元素 - -print("l_2:", l_2) -l_2.insert(1, "w") -print("在l_2第一个元素后面增加w元素:", l_2) - -# Retrieve(检索) -# 索引取值 -print("索引取值l_2[2]", l_2[1]) - -# 切片 -l_3 = list(range(100)) -print(l_3) - -print("l_3切片:", l_3[30:80:15]) -print("去最后一个值:", l_3[-1]) - -# index -print(l_2.index('x')) - -# 更新 -# 索引赋值 -l_2[1] = 'j' -print(l_2) - -# 切片赋值 -l_1[1:3] = 'f' -print('切片赋值后l_1:', l_1) - -# 删除 -l_1.pop() -print("删除后的l_1:", l_1) - -# 排序 -l_4 = [2,9,7,6,8] -l_4.sort() -print("为l_4排序sort:", l_4) - -l_5 = sorted(l_4) -print("用sorted之后l_5排序:", l_5) - -print('倒序', list(reversed(l_5))) - - -# 元组 -t_1 = ('a', 'p', 'p', 'l', 'e') -print("元组索引取值", t_1[2]) -print('元组index取值', t_1.index('e')) - -print('切片:', t_1[1:3]) - -# 字典 -# 键对值赋值 -d_1 = {} -d_1['a'] = 1 -print(d_1) - -# 合并字典 -d_2 = {"b": 2, 'c': 3} -d_1.update(d_2) -print(d_1) -#setdefault - -d_1.setdefault('e', 0) -print(d_1) - -# 键对值访问 -print(d_1['e']) - -print('用get取值:', d_1.get('c')) - -print("返回所有值: ", d_1.values()) - -print("返回所有键对值:", d_1.items()) - -# 键对值赋值 -d_1['a'] = 80 -print("给a赋值80:", d_1) - -# 更新 -d_1.update({"b": 55, "c": 66}) -print(d_1) - -# 删除 -d_1.pop('e') -print("删除键值为e的键值对:", d_1) - -print("popitem()相当于随机返回一个item: ", d_1.popitem()) - -# 集合 -s_1 = set() -print(s_1) -#add -s_1.add("p") -print("增加元素add:", s_1) -# uodate -s_1.update({'y', 't', 'h', 'o', 'n'}) - -print(s_1) - -# in -print("a是否在s_1里面:", 'a' in s_1) -print("p是否在s_1里面:", 'p' in s_1) - -# union合并 -s_2 = {'x', 'w'} -print('合并后s_1为:', s_1.union(s_2)) - -# 删除 - -s_2.remove("x") -print("s_2用remove删除x元素后的结果:", s_2) - - -print("s_1为:", s_1) -s_1.discard("p") -print("s_1用discard删除x元素后的结果:", s_1) - -# pop() -s_1.pop() +# 作业:完成四大基础数据结构的CRUD操作 + +# list 列表的操作 +# list-creat 增加 +# append末尾添加元素 +l_1 = [] +print('id(l_1):', id(l_1)) +l_1.append('a') +print("用append末尾添加元素a:", l_1) +print('添加 a 元素之后的l的id为:', id(l_1)) + +# + 拼接两个列表 +l_2 = ["z", 'y', 'x'] +print("拼接两个列表:", l_1 + l_2) + +# +=加法赋值 +l_1 += ['b'] +print("加法赋值:", l_1) + +# * 和 *= +print("乘法赋值之前的l_1的id:", id(l_1)) +l_1 = [l_1] * 5 +print("乘法赋值结果:", l_1) +print("乘法赋值之后的l_1的id:", id(l_1)) + +# insert指定位置添加元素 + +print("l_2:", l_2) +l_2.insert(1, "w") +print("在l_2第一个元素后面增加w元素:", l_2) + +# Retrieve(检索) +# 索引取值 +print("索引取值l_2[2]", l_2[1]) + +# 切片 +l_3 = list(range(100)) +print(l_3) + +print("l_3切片:", l_3[30:80:15]) +print("去最后一个值:", l_3[-1]) + +# index +print(l_2.index('x')) + +# 更新 +# 索引赋值 +l_2[1] = 'j' +print(l_2) + +# 切片赋值 +l_1[1:3] = 'f' +print('切片赋值后l_1:', l_1) + +# 删除 +l_1.pop() +print("删除后的l_1:", l_1) + +# 排序 +l_4 = [2,9,7,6,8] +l_4.sort() +print("为l_4排序sort:", l_4) + +l_5 = sorted(l_4) +print("用sorted之后l_5排序:", l_5) + +print('倒序', list(reversed(l_5))) + + +# 元组 +t_1 = ('a', 'p', 'p', 'l', 'e') +print("元组索引取值", t_1[2]) +print('元组index取值', t_1.index('e')) + +print('切片:', t_1[1:3]) + +# 字典 +# 键对值赋值 +d_1 = {} +d_1['a'] = 1 +print(d_1) + +# 合并字典 +d_2 = {"b": 2, 'c': 3} +d_1.update(d_2) +print(d_1) +#setdefault + +d_1.setdefault('e', 0) +print(d_1) + +# 键对值访问 +print(d_1['e']) + +print('用get取值:', d_1.get('c')) + +print("返回所有值: ", d_1.values()) + +print("返回所有键对值:", d_1.items()) + +# 键对值赋值 +d_1['a'] = 80 +print("给a赋值80:", d_1) + +# 更新 +d_1.update({"b": 55, "c": 66}) +print(d_1) + +# 删除 +d_1.pop('e') +print("删除键值为e的键值对:", d_1) + +print("popitem()相当于随机返回一个item: ", d_1.popitem()) + +# 集合 +s_1 = set() +print(s_1) +#add +s_1.add("p") +print("增加元素add:", s_1) +# uodate +s_1.update({'y', 't', 'h', 'o', 'n'}) + +print(s_1) + +# in +print("a是否在s_1里面:", 'a' in s_1) +print("p是否在s_1里面:", 'p' in s_1) + +# union合并 +s_2 = {'x', 'w'} +print('合并后s_1为:', s_1.union(s_2)) + +# 删除 + +s_2.remove("x") +print("s_2用remove删除x元素后的结果:", s_2) + + +print("s_1为:", s_1) +s_1.discard("p") +print("s_1用discard删除x元素后的结果:", s_1) + +# pop() +s_1.pop() print("使用pop()删除后s_1的结果:", s_1) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" index c7ae7740bb0e2185fcda40a64a93758163206eb9..5f1e5a4ef3f029be87f4bb415eb2d247b7007166 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" @@ -1,102 +1,102 @@ -# 字符串的编码 -a = '你好' -print("'你好'的编码为:",'你好'.encode('utf-8')) -print('\n') -# 字符串的解码 -b = '你好'.encode('utf') -print(b,'解码为:',b.decode('utf')) -print('\n') - -# 字符串的CRUD -#创建字符串s -s = " hello, world,I am coming! " -print('创建的字符串s为:',s) -print('\n') - -# 检索字符串 -print('字符串s的第三个字符为:',s[2]) -print('\n') - -#用find获取目标字符的索引值 -print('用find,字符串s中字母d的索引值为:',s.find('d')) -print('\n') - -#用find获取目标字符的索引值,当不存在时返回-1 -print('用find,字符串s中字母z的索引值为:',s.find('z')) -print('\n') - -#用index获取目标字符的索引值 -print('用index,字符串s中字母r的索引值为:',s.index('r')) -print('\n') - -#用index获取目标字符的索引值,当不存在时报错 -try: - print('用index,字符串s中字母z的索引值为:',s.index('z')) -except: - pass -# startswith 和 endswith 用法 -print('s字符串是否以’hello‘开头的:',s.startswith("hello")) -print('\n') - -print('s字符串是否以’ld‘开头的:',s.endswith("ld")) -print('\n') - -# 字符串更新:replace替换 -print('将字符串中world替换为World:',s.replace('world','World')) -print('\n') - -# 字符串更新:split分割 -s1=s.split(",") -print("s1=",s1) -print('\n') - -# 字符串更新:join拼接 -print("s1拼接后的为:",",".join(s1)) -print('\n') - -#字符串更新:delete删除 -print('用strip删除字符串s中的空格:',s.strip()) -print('\n') - -print('用lstrip删除字符串s中左边的空格:',s.lstrip()) -print('\n') - -print('用rstrip删除字符串s中右边的空格:',s.rstrip()) -print('\n') - - -#练习字符串的格式化 -#默认顺序 -home = "河南" -name = "张三" -print("使用默认顺序格式化:","热烈欢迎来自{}的{}!".format(home,name)) -print('\n') - -#指定参数索引 -print("指定参数索引格式化:","热烈欢迎来自{0}的{1},没错,他来自中原大地{0}!".format(home,name)) -print('\n') - -#按关键词参数 -print("用关键词参数格式化:","热烈欢迎来自{home}的{name},没错,他来自中原大地{home}!".format(home="河南",name="张三")) -print('\n') - -#按变量(推荐使用) -print("按变量格式化(推荐使用):",f'热烈欢迎来自{home}的{name}!') -print('\n') - -# % 格式化 -print("%格式化:",'热烈欢迎来自%s的%s! ' % ('河南','张三')) -print('\n') - -# 小数表示 -print("3.1415926保存两位小数为:","{:.2f}".format(3.1415926)) -print('\n') - -#将content内容保存到本地文件 -# open函数打开文件、指定文件名, 方法(读, 写, 追加), 编码格式 -output = open("big.txt", "w", encoding="utf-8") -content = "Big brother is watching you!" -# 正式写入文件 -output.write(content) -# 关闭文件句柄 +# 字符串的编码 +a = '你好' +print("'你好'的编码为:",'你好'.encode('utf-8')) +print('\n') +# 字符串的解码 +b = '你好'.encode('utf') +print(b,'解码为:',b.decode('utf')) +print('\n') + +# 字符串的CRUD +#创建字符串s +s = " hello, world,I am coming! " +print('创建的字符串s为:',s) +print('\n') + +# 检索字符串 +print('字符串s的第三个字符为:',s[2]) +print('\n') + +#用find获取目标字符的索引值 +print('用find,字符串s中字母d的索引值为:',s.find('d')) +print('\n') + +#用find获取目标字符的索引值,当不存在时返回-1 +print('用find,字符串s中字母z的索引值为:',s.find('z')) +print('\n') + +#用index获取目标字符的索引值 +print('用index,字符串s中字母r的索引值为:',s.index('r')) +print('\n') + +#用index获取目标字符的索引值,当不存在时报错 +try: + print('用index,字符串s中字母z的索引值为:',s.index('z')) +except: + pass +# startswith 和 endswith 用法 +print('s字符串是否以’hello‘开头的:',s.startswith("hello")) +print('\n') + +print('s字符串是否以’ld‘开头的:',s.endswith("ld")) +print('\n') + +# 字符串更新:replace替换 +print('将字符串中world替换为World:',s.replace('world','World')) +print('\n') + +# 字符串更新:split分割 +s1=s.split(",") +print("s1=",s1) +print('\n') + +# 字符串更新:join拼接 +print("s1拼接后的为:",",".join(s1)) +print('\n') + +#字符串更新:delete删除 +print('用strip删除字符串s中的空格:',s.strip()) +print('\n') + +print('用lstrip删除字符串s中左边的空格:',s.lstrip()) +print('\n') + +print('用rstrip删除字符串s中右边的空格:',s.rstrip()) +print('\n') + + +#练习字符串的格式化 +#默认顺序 +home = "河南" +name = "张三" +print("使用默认顺序格式化:","热烈欢迎来自{}的{}!".format(home,name)) +print('\n') + +#指定参数索引 +print("指定参数索引格式化:","热烈欢迎来自{0}的{1},没错,他来自中原大地{0}!".format(home,name)) +print('\n') + +#按关键词参数 +print("用关键词参数格式化:","热烈欢迎来自{home}的{name},没错,他来自中原大地{home}!".format(home="河南",name="张三")) +print('\n') + +#按变量(推荐使用) +print("按变量格式化(推荐使用):",f'热烈欢迎来自{home}的{name}!') +print('\n') + +# % 格式化 +print("%格式化:",'热烈欢迎来自%s的%s! ' % ('河南','张三')) +print('\n') + +# 小数表示 +print("3.1415926保存两位小数为:","{:.2f}".format(3.1415926)) +print('\n') + +#将content内容保存到本地文件 +# open函数打开文件、指定文件名, 方法(读, 写, 追加), 编码格式 +output = open("big.txt", "w", encoding="utf-8") +content = "Big brother is watching you!" +# 正式写入文件 +output.write(content) +# 关闭文件句柄 output.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2541\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2541\350\212\202\344\275\234\344\270\232.py" index 37bb3a9dc89569ef9c61a4edd2352ebf70f61728..4763b1af7f17090c5f7198a621fabb6a2c031ac9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2541\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2541\350\212\202\344\275\234\344\270\232.py" @@ -1,62 +1,62 @@ -# - 利用`Python`实现一个多线程程序 -# - 将多线程程序改为多进程程序 -import requests -import time -from threading import Thread -from multiprocessing import Process - - -def my_spend_time(func): # 装饰器计算运行时间 - def wrapper(*args, **kwargs): - stat_time = time.time() - my_result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__}运行时间为:{format(end_time - stat_time, '.2f')}s") - return my_result - return wrapper - - -result = [] - - -def request_zhihu(index): - time.sleep(2) - url = "https://www.zhihu.com/" # 访问知乎 - # body = "" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(f"当前请求序号{index},返回状态码:{response.status_code}") - result.append(response) - - -@my_spend_time -def my_thread(): - thread_array = [] - for i in range(5): - t = Thread(target=request_zhihu, args=(i, )) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - print("多线程已完成!") - print(result) - - -@my_spend_time -def my_process(): - process_array = [] - for i in range(5): - p = Process(target=request_zhihu, args=(i, )) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("多进程已完成!") - print(result) - - -if __name__ == "__main__": - my_thread() +# - 利用`Python`实现一个多线程程序 +# - 将多线程程序改为多进程程序 +import requests +import time +from threading import Thread +from multiprocessing import Process + + +def my_spend_time(func): # 装饰器计算运行时间 + def wrapper(*args, **kwargs): + stat_time = time.time() + my_result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__}运行时间为:{format(end_time - stat_time, '.2f')}s") + return my_result + return wrapper + + +result = [] + + +def request_zhihu(index): + time.sleep(2) + url = "https://www.zhihu.com/" # 访问知乎 + # body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(f"当前请求序号{index},返回状态码:{response.status_code}") + result.append(response) + + +@my_spend_time +def my_thread(): + thread_array = [] + for i in range(5): + t = Thread(target=request_zhihu, args=(i, )) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print("多线程已完成!") + print(result) + + +@my_spend_time +def my_process(): + process_array = [] + for i in range(5): + p = Process(target=request_zhihu, args=(i, )) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("多进程已完成!") + print(result) + + +if __name__ == "__main__": + my_thread() my_process() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232.py" index 54f4e0ae3e392afe08d233e5169b59a7081b4b62..237ae47ef99e3c2c3bbf330de5c1fa150e8637a4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232.py" @@ -1,225 +1,225 @@ -#作业一 -什么是迭代器?什么是生成器?两者有什么区别? - -#迭代器 -概念上:迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有我们主动去使用next方法调用,才会返回值) -实现上:实现了 __next__接口的对象 -1.传统生命一个列表,里面的元素会立即写进内存当中,占用大量内存 -迭代器可以一次只返回一个元素,占用的内存非常小,在读取大文件和大的数据集合的时候特别有用8 - -### 程序讲话 -#两者实现的功能是一模一样的 -# 通过 iter方法返回一个迭代器对象 -l=list(range(10)) -l2=iter(range(10)) - -#print(l,"\n") -#print("l2=",l2,"\n") - -#通过next 方法主动获取迭代器中的值 -""" -当 迭代器中没有值了以后,会抛出 StopIteration的异常,需要自行处理一下 -""" -try: - iter = iter(range(5)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) -except StopIteration: - print("没 数据了 ") -#生成器 -生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上,提供了额外的功能,实现了程序的暂停 -声明一个生成器 -只要在函数体重有 yield 关键字,它既是一个生成器 -yield 翻译为 让渡,我们可以简单理解为暂停并返回右边的值 - -#让程序 代表 一切 -def my_range_gen(n): - for i in range(n): - yield i*i - print(f"current index:{i}") - -try: - my_range=my_range_gen(3) - #print(my_range) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) -except StopIteration: - print("no data") - - - -#生成器和迭代器的区别? -同样提供了惰性返回的功能,迭代器 侧重于 提供 数据的惰性返回功能,生成器侧重于 指令的惰性返回功能 - - - -#协程 -协程的实现原理就是生成器的实现原理,在生成器的基础上又提供了传递值的功能 -通过 send 方法 向生成器传递值, -对生成器进行 send 操作,一定要调用next 方法预激,使其停留在第一个 yield位置 - - -## 不懂就用代码 拉出来溜溜 - -def simple_coro(a): - print("初始值a=",a) - b=yield a - print("传递值 b=",b) - c=yield a+b - print("传递值 c=",c) - -try: - coro=simple_coro(1) - print(next(coro)) - print(coro.send(2)) - print(coro.send(3)) -except StopIteration: - print("no data") - -## 用协程 来实现 计算平均数的函数 -print("--------用协程 来实现 计算平均数的函数-----------") -def coro_avg(): - total=0 - length=0 - while True: - try: - value=yield total/length - except ZeroDivisionError: - value=yield 0 - total+=value - length+=1 - -my_avg=coro_avg() -print(next(my_avg)) -print(my_avg.send(2)) -print(my_avg.send(3)) -print(my_avg.send(4)) - -# yield 和 yield from的区别 -## yield from 用来驱动 子程序中的循环并返回最终值 - -print("--------------yield from----------") -def return_triple(): - while True: - value=yield - if value%2==0: - return value - -triple_array=[] -def triple_recorder(): - while True: - result=yield from return_triple() - triple_array.append(result) - -coro=triple_recorder() -next(coro) -for i in range(20): - coro.send(i) -print(triple_array) - - -##异步 -# asyncio(异步) -## Python3.4 引入的标准库,替代 yield from 实现协程异步IO,可以更好地实现异步程序 -## 实现原理:自动维护了一个事件队列,然后循环访问 事件来完成异步的消息维护 -import asyncio -import time -print("-----------asyncio(异步)-------") -class Response: - status_code=200 - -async def sim_request(index): - print(f"模拟发送请求:Index:{index}") - response=Response() - ##模拟 网络延迟 - ## 当前是单线程 运行的,如果调用的是 time.sleep(1) 那么这个线程会被阻塞 - ## 当前线程被阻塞之后,不会让渡 CPU资源,异步的效率就不会体现 - - await asyncio.sleep(1) - print(f"requst index {index},response status_code:{response.status_code}") - return response.status_code - -#获取 消息队列 -loop=asyncio.get_event_loop() - -#包装任务 -task_array=[] -for i in range(5): - task_array.append(sim_request(i)) - -#循环访问事件 来完成异步的消息维护 -#loop.run_until_complete(asyncio.wait(task_array)) - -#小技巧::: 获取异步完成之后的所有返回值 -result=loop.run_until_complete(asyncio.gather(*task_array)) -print("----result--->,",result) -#关闭事件循环 -loop.close() - - - -## 编写一个asyncio异步程序 -# 自定义 异步函数 -print("---------自定义 异步函数----------") -async def hello(): - await asyncio.sleep(2) - print("hello,world:%s"%time.time()) - -def run(): - for i in range(5): - loop.run_until_complete(hello()) - -loop=asyncio.get_event_loop() -if __name__=='__main__': - run() - -###扩展: 了解aiohttp异步请求网址 -import aiohttp -print("-----------aiohttp异步请求网址-----------") -#目标协程 -async def run(): - print("start get:") - print(time.time()) - res=await get() - print("finish get:") - print(time.time()) - -# 异步请求 -async def get(): - url='htpp://baidu.com' - async with aiohttp.ClientSession() as session: - async with session.get(url) as response: - # return await response.read() - #假设 请求返回时间 - return await asyncio.sleep(2) - -async def creat_task(event_loop): - while True: - asyncio.run_coroutine_threadsafe(run(),event_loop) - await asyncio.sleep(1)# 设置定时时间 - -# 启动一个 loop -def start_loop(loop): - asyncio.set_event_loop(loop) - loop.run_forever() - -from threading import Thread -if __name__=='__main__': - # 子线程 loop - tread_loop=asyncio.new_event_loop() - - run_loop_thread=Thread(target=start_loop,args=(tread_loop,)) - run_loop_thread.start() - - main_loop=asyncio.new_event_loop() - - #在主线程loop里面 - main_loop.run_until_complete(creat_task(tread_loop)) +#作业一 +什么是迭代器?什么是生成器?两者有什么区别? + +#迭代器 +概念上:迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有我们主动去使用next方法调用,才会返回值) +实现上:实现了 __next__接口的对象 +1.传统生命一个列表,里面的元素会立即写进内存当中,占用大量内存 +迭代器可以一次只返回一个元素,占用的内存非常小,在读取大文件和大的数据集合的时候特别有用8 + +### 程序讲话 +#两者实现的功能是一模一样的 +# 通过 iter方法返回一个迭代器对象 +l=list(range(10)) +l2=iter(range(10)) + +#print(l,"\n") +#print("l2=",l2,"\n") + +#通过next 方法主动获取迭代器中的值 +""" +当 迭代器中没有值了以后,会抛出 StopIteration的异常,需要自行处理一下 +""" +try: + iter = iter(range(5)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) +except StopIteration: + print("没 数据了 ") +#生成器 +生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上,提供了额外的功能,实现了程序的暂停 +声明一个生成器 +只要在函数体重有 yield 关键字,它既是一个生成器 +yield 翻译为 让渡,我们可以简单理解为暂停并返回右边的值 + +#让程序 代表 一切 +def my_range_gen(n): + for i in range(n): + yield i*i + print(f"current index:{i}") + +try: + my_range=my_range_gen(3) + #print(my_range) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) +except StopIteration: + print("no data") + + + +#生成器和迭代器的区别? +同样提供了惰性返回的功能,迭代器 侧重于 提供 数据的惰性返回功能,生成器侧重于 指令的惰性返回功能 + + + +#协程 +协程的实现原理就是生成器的实现原理,在生成器的基础上又提供了传递值的功能 +通过 send 方法 向生成器传递值, +对生成器进行 send 操作,一定要调用next 方法预激,使其停留在第一个 yield位置 + + +## 不懂就用代码 拉出来溜溜 + +def simple_coro(a): + print("初始值a=",a) + b=yield a + print("传递值 b=",b) + c=yield a+b + print("传递值 c=",c) + +try: + coro=simple_coro(1) + print(next(coro)) + print(coro.send(2)) + print(coro.send(3)) +except StopIteration: + print("no data") + +## 用协程 来实现 计算平均数的函数 +print("--------用协程 来实现 计算平均数的函数-----------") +def coro_avg(): + total=0 + length=0 + while True: + try: + value=yield total/length + except ZeroDivisionError: + value=yield 0 + total+=value + length+=1 + +my_avg=coro_avg() +print(next(my_avg)) +print(my_avg.send(2)) +print(my_avg.send(3)) +print(my_avg.send(4)) + +# yield 和 yield from的区别 +## yield from 用来驱动 子程序中的循环并返回最终值 + +print("--------------yield from----------") +def return_triple(): + while True: + value=yield + if value%2==0: + return value + +triple_array=[] +def triple_recorder(): + while True: + result=yield from return_triple() + triple_array.append(result) + +coro=triple_recorder() +next(coro) +for i in range(20): + coro.send(i) +print(triple_array) + + +##异步 +# asyncio(异步) +## Python3.4 引入的标准库,替代 yield from 实现协程异步IO,可以更好地实现异步程序 +## 实现原理:自动维护了一个事件队列,然后循环访问 事件来完成异步的消息维护 +import asyncio +import time +print("-----------asyncio(异步)-------") +class Response: + status_code=200 + +async def sim_request(index): + print(f"模拟发送请求:Index:{index}") + response=Response() + ##模拟 网络延迟 + ## 当前是单线程 运行的,如果调用的是 time.sleep(1) 那么这个线程会被阻塞 + ## 当前线程被阻塞之后,不会让渡 CPU资源,异步的效率就不会体现 + + await asyncio.sleep(1) + print(f"requst index {index},response status_code:{response.status_code}") + return response.status_code + +#获取 消息队列 +loop=asyncio.get_event_loop() + +#包装任务 +task_array=[] +for i in range(5): + task_array.append(sim_request(i)) + +#循环访问事件 来完成异步的消息维护 +#loop.run_until_complete(asyncio.wait(task_array)) + +#小技巧::: 获取异步完成之后的所有返回值 +result=loop.run_until_complete(asyncio.gather(*task_array)) +print("----result--->,",result) +#关闭事件循环 +loop.close() + + + +## 编写一个asyncio异步程序 +# 自定义 异步函数 +print("---------自定义 异步函数----------") +async def hello(): + await asyncio.sleep(2) + print("hello,world:%s"%time.time()) + +def run(): + for i in range(5): + loop.run_until_complete(hello()) + +loop=asyncio.get_event_loop() +if __name__=='__main__': + run() + +###扩展: 了解aiohttp异步请求网址 +import aiohttp +print("-----------aiohttp异步请求网址-----------") +#目标协程 +async def run(): + print("start get:") + print(time.time()) + res=await get() + print("finish get:") + print(time.time()) + +# 异步请求 +async def get(): + url='htpp://baidu.com' + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + # return await response.read() + #假设 请求返回时间 + return await asyncio.sleep(2) + +async def creat_task(event_loop): + while True: + asyncio.run_coroutine_threadsafe(run(),event_loop) + await asyncio.sleep(1)# 设置定时时间 + +# 启动一个 loop +def start_loop(loop): + asyncio.set_event_loop(loop) + loop.run_forever() + +from threading import Thread +if __name__=='__main__': + # 子线程 loop + tread_loop=asyncio.new_event_loop() + + run_loop_thread=Thread(target=start_loop,args=(tread_loop,)) + run_loop_thread.start() + + main_loop=asyncio.new_event_loop() + + #在主线程loop里面 + main_loop.run_until_complete(creat_task(tread_loop)) main_loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2542\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2542\350\212\202\344\275\234\344\270\232.py" index fec225b383b0d2950bd1e688cfc96dd6df41f299..c4d232f03715666f085944f62ecb6d2f7c39a21e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2542\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250_\347\254\2542\350\212\202\344\275\234\344\270\232.py" @@ -1,82 +1,82 @@ -# - 多进程锁, 多线程锁都要自己实现一遍 -# - 多进程通过Queue来实现进程通信 -# - 把上述概念熟记并理解 -import time -from threading import Thread -from multiprocessing import Process, Lock, Queue - -# 以下代码可使用with -# def save_to_file(index): -# f = open("test.log", "w", encoding="utf-8") -# f.write(index) -# f.close() - -# 进程间通信 -# 多进程锁 -def save_to_file(index, lock): - # 拿锁 - # lock.acquire() 替换为上下文管理器:with lock - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - # 释放锁 - # lock.release() 替换为上下文管理器:with lock - - -if __name__ == "__main__": - process_array = [] - lock = Lock() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("done!!!!!") - -# 多进程通过Queue来实现进程通信 - - -def save_to_queue(index, my_queue): - my_queue.put(index) - print(my_queue.get()) - - -if __name__ == "__main__": - process_array2 = [] - my_queue = Queue() - for i in range(10): - p = Process(target=save_to_queue, args=(i, my_queue)) - process_array2.append(p) - p.start() - for p in process_array2: - p.join() - print("多进程通过Queue来实现进程通信:done!") - -# 线程间通信/线程安全及GIL锁 -zero = 0 -# 加互斥锁 -lock = Lock() - - -def foo(): - global zero - for i in range(10**6): - with lock: - zero += 1 - zero -= 1 - - # zero += 1 - # zero -= 1 - - -if __name__ == "__main__": - process_array3 = [] - for i in range(2): - p = Thread(target=foo) - process_array3.append(p) - p.start() - for p in process_array3: - p.join() - +# - 多进程锁, 多线程锁都要自己实现一遍 +# - 多进程通过Queue来实现进程通信 +# - 把上述概念熟记并理解 +import time +from threading import Thread +from multiprocessing import Process, Lock, Queue + +# 以下代码可使用with +# def save_to_file(index): +# f = open("test.log", "w", encoding="utf-8") +# f.write(index) +# f.close() + +# 进程间通信 +# 多进程锁 +def save_to_file(index, lock): + # 拿锁 + # lock.acquire() 替换为上下文管理器:with lock + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + # 释放锁 + # lock.release() 替换为上下文管理器:with lock + + +if __name__ == "__main__": + process_array = [] + lock = Lock() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!!!!!") + +# 多进程通过Queue来实现进程通信 + + +def save_to_queue(index, my_queue): + my_queue.put(index) + print(my_queue.get()) + + +if __name__ == "__main__": + process_array2 = [] + my_queue = Queue() + for i in range(10): + p = Process(target=save_to_queue, args=(i, my_queue)) + process_array2.append(p) + p.start() + for p in process_array2: + p.join() + print("多进程通过Queue来实现进程通信:done!") + +# 线程间通信/线程安全及GIL锁 +zero = 0 +# 加互斥锁 +lock = Lock() + + +def foo(): + global zero + for i in range(10**6): + with lock: + zero += 1 + zero -= 1 + + # zero += 1 + # zero -= 1 + + +if __name__ == "__main__": + process_array3 = [] + for i in range(2): + p = Thread(target=foo) + process_array3.append(p) + p.start() + for p in process_array3: + p.join() + print("zero:", zero) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" index a112d2159281c7c122247089b65f53607be58979..0507452bf8031f0592c2d0ec71163e7489fa5737 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232.py" @@ -1,34 +1,34 @@ -# 1.通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 - -import datetime -from datetime import timedelta - -# 获取当前时间戳 -now_stamp = datetime.datetime.now().timestamp() -print("打印当前时间戳:", now_stamp) - -# 时间戳转为时间对象 -stamp_to_datetime = datetime.datetime.fromtimestamp(now_stamp, tz=None) -print("时间戳转为时间对象:", stamp_to_datetime) - -# 时间对象格式化字符串输出 -datetime_to_string = stamp_to_datetime.strftime("%Y-%m-%d %H:%M:%S") -print("时间对象格式化输出为:", datetime_to_string) - -# 字符串转化为时间对象输出 -string_to_datetime = datetime.datetime.strptime(datetime_to_string, "%Y-%m-%d %H:%M:%S") -print("字符串转化为时间对象输出", string_to_datetime) - -# 时间对象转为时间戳 -datetime_to_stamp = string_to_datetime.timestamp() -print("时间对象转为时间戳:", datetime_to_stamp) - - -# 2.封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02 -def get_days(days): - today = datetime.datetime.now() - someday = today + timedelta(days=days) - return someday.strftime("%Y-%m-%d") - - +# 1.通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 + +import datetime +from datetime import timedelta + +# 获取当前时间戳 +now_stamp = datetime.datetime.now().timestamp() +print("打印当前时间戳:", now_stamp) + +# 时间戳转为时间对象 +stamp_to_datetime = datetime.datetime.fromtimestamp(now_stamp, tz=None) +print("时间戳转为时间对象:", stamp_to_datetime) + +# 时间对象格式化字符串输出 +datetime_to_string = stamp_to_datetime.strftime("%Y-%m-%d %H:%M:%S") +print("时间对象格式化输出为:", datetime_to_string) + +# 字符串转化为时间对象输出 +string_to_datetime = datetime.datetime.strptime(datetime_to_string, "%Y-%m-%d %H:%M:%S") +print("字符串转化为时间对象输出", string_to_datetime) + +# 时间对象转为时间戳 +datetime_to_stamp = string_to_datetime.timestamp() +print("时间对象转为时间戳:", datetime_to_stamp) + + +# 2.封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02 +def get_days(days): + today = datetime.datetime.now() + someday = today + timedelta(days=days) + return someday.strftime("%Y-%m-%d") + + print("所求的日期为:", get_days(1)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index e0092f1d46ab05c00ce569495c5f26c2261da539..5d19e450ff01b6054d70240ce7923e2c7f2380c2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,128 +1,128 @@ -# 作业一:将之前封装的`MyMath`类中的实例方法改为静态方法, 体会两者的区别. - - -class MyMath: - @staticmethod - def add(x, y): - return x + y - - @staticmethod - def min(x, y): - return x - y - - @staticmethod - def mul(x, y): - return x * y - - @staticmethod - def div(x, y): - return x / y - - @staticmethod - def pow(x, y): - return x ** y - - @staticmethod - def root(x, y): - return x ** (1/y) - - -print(MyMath.add(2, 3)) -print(MyMath.min(2, 3)) -print(MyMath.mul(2, 3)) -print(MyMath.div(2, 3)) -print(MyMath.pow(2, 3)) -print(MyMath.root(2, 3)) - -#作业二:为上节课自定义类添加以下功能: -# - 添加类属性 -# - 添加类私有属性 -# - 添加类方法或者类的私有属性 -# - 在`__init__`方法中初始化实例属性 -# - 在`__init__`方法中绑定私有实例属性 -# - 在自定义类中实现`__str__`, 自定义输出格式 - - -class Phone(object): - price = 5000 - - # 添加类属性 - ScreenType = "全面屏" - - # 添加类私有属性 - __ScreenSize = 5.5 - - # 获取私有属性 - @classmethod - def get_ScreenSize(cls): - return cls.__ScreenSize - - -screen = Phone() - -print("打印phone的屏幕类型的类属性,ScreenType:", Phone.ScreenType) -print("打印phone的私有属性,屏幕尺寸,ScreenSize:", Phone._Phone__ScreenSize) -print("获取私有属性:", screen.get_ScreenSize()) - - -class Android(Phone): - syste = "ANDR" - brand = '小米' - color = 'Black' - telephone = True - - # 添加类方法或者类的私有属性 - @classmethod - def __new__(cls, *args, **kwargs): - print("添加的类方法") - return super().__new__(cls) - - -oppo = Android() -print(oppo.telephone) - -# 在__init__中初始化实例属性 - - -class ChinesePhone(Phone): - nation = "cn" - - def __init__(self, rank): - self.__rank = rank - - -xiaomi = ChinesePhone(2) - -print("实例属性中的私有属性(小米排名):", xiaomi._ChinesePhone__rank) - - -class Iphone(Phone): - syste = "IOS" - brand = '苹果' - color = 'white' - - -# 实例化 -print("售价5000的苹果:", Iphone.price) -print("售价5000的Android:", Android.price) -print("将打印Iphone的品牌:", Iphone.brand) - - -# 在自定义类中实现`__str__`, 自定义输出格式 - -class MyDict(dict): - def __iadd__(self, other): - self.update(other) - return self - - def __str__(self): - return f"My Dict {self.items()}" - - -a = MyDict(a=1, b=2) -b = MyDict(c=3, d=4) -print(a) -print(b) - -a += b +# 作业一:将之前封装的`MyMath`类中的实例方法改为静态方法, 体会两者的区别. + + +class MyMath: + @staticmethod + def add(x, y): + return x + y + + @staticmethod + def min(x, y): + return x - y + + @staticmethod + def mul(x, y): + return x * y + + @staticmethod + def div(x, y): + return x / y + + @staticmethod + def pow(x, y): + return x ** y + + @staticmethod + def root(x, y): + return x ** (1/y) + + +print(MyMath.add(2, 3)) +print(MyMath.min(2, 3)) +print(MyMath.mul(2, 3)) +print(MyMath.div(2, 3)) +print(MyMath.pow(2, 3)) +print(MyMath.root(2, 3)) + +#作业二:为上节课自定义类添加以下功能: +# - 添加类属性 +# - 添加类私有属性 +# - 添加类方法或者类的私有属性 +# - 在`__init__`方法中初始化实例属性 +# - 在`__init__`方法中绑定私有实例属性 +# - 在自定义类中实现`__str__`, 自定义输出格式 + + +class Phone(object): + price = 5000 + + # 添加类属性 + ScreenType = "全面屏" + + # 添加类私有属性 + __ScreenSize = 5.5 + + # 获取私有属性 + @classmethod + def get_ScreenSize(cls): + return cls.__ScreenSize + + +screen = Phone() + +print("打印phone的屏幕类型的类属性,ScreenType:", Phone.ScreenType) +print("打印phone的私有属性,屏幕尺寸,ScreenSize:", Phone._Phone__ScreenSize) +print("获取私有属性:", screen.get_ScreenSize()) + + +class Android(Phone): + syste = "ANDR" + brand = '小米' + color = 'Black' + telephone = True + + # 添加类方法或者类的私有属性 + @classmethod + def __new__(cls, *args, **kwargs): + print("添加的类方法") + return super().__new__(cls) + + +oppo = Android() +print(oppo.telephone) + +# 在__init__中初始化实例属性 + + +class ChinesePhone(Phone): + nation = "cn" + + def __init__(self, rank): + self.__rank = rank + + +xiaomi = ChinesePhone(2) + +print("实例属性中的私有属性(小米排名):", xiaomi._ChinesePhone__rank) + + +class Iphone(Phone): + syste = "IOS" + brand = '苹果' + color = 'white' + + +# 实例化 +print("售价5000的苹果:", Iphone.price) +print("售价5000的Android:", Android.price) +print("将打印Iphone的品牌:", Iphone.brand) + + +# 在自定义类中实现`__str__`, 自定义输出格式 + +class MyDict(dict): + def __iadd__(self, other): + self.update(other) + return self + + def __str__(self): + return f"My Dict {self.items()}" + + +a = MyDict(a=1, b=2) +b = MyDict(c=3, d=4) +print(a) +print(b) + +a += b print(a) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" index 4abb13d3ca8109ce579df6b40cb184397ae2d6f4..e006956aa6fb299621c1b84ed6698b3d198008d5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.py" @@ -1,74 +1,74 @@ -# 1.用类封装一个Math类,实现加、减、乘、除、幂、开方 -class MyMath: - def add(self, x, y): - return x + y - - def min(self, x, y): - return x - y - - def mul(self, x, y): - return x * y - - def div(self, x, y): - return x / y - - def pow(self, x, y): - return x ** y - - def root(self, x, y): - return x ** (1/y) - - -calculator = MyMath() -print(MyMath().add(2, 3)) -print(calculator.min(2, 3)) -print(calculator.mul(2, 3)) -print(calculator.div(2, 3)) -print(MyMath().pow(2, 3)) -print(MyMath().root(2, 3)) - - - - -# 2.自由课题,按照自己的想法将身边的事物抽象成类,并创建多个实例 - - -class Phone(object): - price = 5000 - - def powon(self): - pass - - def powoff(self): - pass - - -class Android(Phone): - def powon(self): - pass - - # 实例初始化 - - def __init__(self, nation): - self.nation = nation - - syste = "ANDR" - brand = '小米' - color = "black" - - -class Iphone(Phone): - syste = "IOS" - brand = '苹果' - color = 'white' - - -# 实例化 -xiaomi = Android("中国") - -print(Android.brand, f"{xiaomi.nation}品牌手机") - -print("售价5000的苹果:", Iphone.price) -print("售价5000的Android:", Android.price) -print("将打印Iphone的品牌:", Iphone.brand) +# 1.用类封装一个Math类,实现加、减、乘、除、幂、开方 +class MyMath: + def add(self, x, y): + return x + y + + def min(self, x, y): + return x - y + + def mul(self, x, y): + return x * y + + def div(self, x, y): + return x / y + + def pow(self, x, y): + return x ** y + + def root(self, x, y): + return x ** (1/y) + + +calculator = MyMath() +print(MyMath().add(2, 3)) +print(calculator.min(2, 3)) +print(calculator.mul(2, 3)) +print(calculator.div(2, 3)) +print(MyMath().pow(2, 3)) +print(MyMath().root(2, 3)) + + + + +# 2.自由课题,按照自己的想法将身边的事物抽象成类,并创建多个实例 + + +class Phone(object): + price = 5000 + + def powon(self): + pass + + def powoff(self): + pass + + +class Android(Phone): + def powon(self): + pass + + # 实例初始化 + + def __init__(self, nation): + self.nation = nation + + syste = "ANDR" + brand = '小米' + color = "black" + + +class Iphone(Phone): + syste = "IOS" + brand = '苹果' + color = 'white' + + +# 实例化 +xiaomi = Android("中国") + +print(Android.brand, f"{xiaomi.nation}品牌手机") + +print("售价5000的苹果:", Iphone.price) +print("售价5000的Android:", Android.price) +print("将打印Iphone的品牌:", Iphone.brand) print("将打印Android的一个品牌:", Android.brand) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/\344\270\200\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2321.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/\344\270\200\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2321.py" index e98b4d75b8055015c4116fa0f944772dc26e2ee5..09cbffedcfa80867becfe54f2a5b5db83099ac5f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/\344\270\200\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2321.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212/\344\270\200\347\217\255_\344\270\200\345\217\252\350\277\267\350\267\257\347\232\204\347\206\212_\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2321.py" @@ -1,66 +1,66 @@ -import pymysql -import random -import time - - -# MySQL configuration -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "chaos", - "password": "test123456", - "db": "python_test" -} - - -# 连接数据库 -con = pymysql.connect(**MYSQL_CONF) -my_cur = con.cursor() - - -# fetchone() -try: - with con.cursor() as cur: - cur.execute('SELECT VERSION()') - version = cur.fetchone() - print(f'MySQL version is {version[0]}') -finally: - con.close() - - -# fetchall() -try: - with con.cursor() as cur: - cur.execute('SELECT * FROM players') - rows = cur.fetchall() - for i in rows: - print(f'{row[0]} {row[1]} {row[2]}') -finally: - con.close() - - -def insert_one(): - for i in range(10 ** 4): - player_id = f'player_{i}' - score = f'score {random.randint(1, 50)}' - game_time = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO players(player_id, score, game_time) - VALUES ('{player_id}', '{score}', '{game_time}')""" - - print(SQL) - my_cur.execute(SQL) - con.commit() - -def insert_many(): - my_list = [] - for i in range(10 ** 4): - player_id = f'player_{i}' - score = f'score {random.randint(1, 50)}' - game_time = time.strftime("%Y-%m-%d") - my_list.append((player_id, score, game_time)) - - SQL = f"""INSERT INTO players(player_id, score, game_time) - VALUES ('{player_id}', '{score}', '{game_time}')""" - print(my_list) - my_cur.executemany(SQL, my_list) +import pymysql +import random +import time + + +# MySQL configuration +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "chaos", + "password": "test123456", + "db": "python_test" +} + + +# 连接数据库 +con = pymysql.connect(**MYSQL_CONF) +my_cur = con.cursor() + + +# fetchone() +try: + with con.cursor() as cur: + cur.execute('SELECT VERSION()') + version = cur.fetchone() + print(f'MySQL version is {version[0]}') +finally: + con.close() + + +# fetchall() +try: + with con.cursor() as cur: + cur.execute('SELECT * FROM players') + rows = cur.fetchall() + for i in rows: + print(f'{row[0]} {row[1]} {row[2]}') +finally: + con.close() + + +def insert_one(): + for i in range(10 ** 4): + player_id = f'player_{i}' + score = f'score {random.randint(1, 50)}' + game_time = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO players(player_id, score, game_time) + VALUES ('{player_id}', '{score}', '{game_time}')""" + + print(SQL) + my_cur.execute(SQL) + con.commit() + +def insert_many(): + my_list = [] + for i in range(10 ** 4): + player_id = f'player_{i}' + score = f'score {random.randint(1, 50)}' + game_time = time.strftime("%Y-%m-%d") + my_list.append((player_id, score, game_time)) + + SQL = f"""INSERT INTO players(player_id, score, game_time) + VALUES ('{player_id}', '{score}', '{game_time}')""" + print(my_list) + my_cur.executemany(SQL, my_list) con.commit() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\360\237\207\274 \360\237\207\276 \360\237\207\274 \360\237\207\255/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.mad.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\360\237\207\274 \360\237\207\276 \360\237\207\274 \360\237\207\255/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.mad.md" index f70cba39b904fb50b2a66fb6d060728e3678dfbe..488eee4dd63f7bffa3f5b1b105b34c9116d5ac34 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\360\237\207\274 \360\237\207\276 \360\237\207\274 \360\237\207\255/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.mad.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\360\237\207\274 \360\237\207\276 \360\237\207\274 \360\237\207\255/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.mad.md" @@ -1,189 +1,189 @@ -## 第一周-第三节课-随堂笔记 - -### 变量和赋值 - -- 什么是变量 - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可重新赋值 - -- 为变量赋值 - - - 通过=来赋值 - - ``` - x=3 - ``` - -- python的变量 - - - 被重新赋值之后的值去哪 - - - 被系统回收了 - - - python没有常量这个数据类型 - - - 程序员之间的约定,如果这个变量的命名都是大字母,那么就视为一个常量 - - - -### python的六大基本类型 - -``` -强调基本的原因,数据类型和数据结构指向的范围更加广泛,不要产生错误的认识,形成思想的定式 -``` - -- 通过type()函数来查看当前变量的数据结构 - -- int(整数) - -- float(浮点数) - - - 因为计算机内部只是1和0,所以浮点数强调的是小数的表现形式 - - - ``` - float('1,o') - float('INF') - ``` - -- string(字符串,字符序列) - - 在有些语言中,单个字符也是一个基本的数据类型(char) - - - 有序的 - - - 如何表示字符串 - - '' - - "" - - '''''''' - - - 转义字符 - - 告诉python解释器,我们当前要表示的是一个字符或特殊字符 - - - 通过 \ 来转义 - - ``` - "2\" - "2\n" - ``` - -​ boolean(布尔值) - -``` -bool(2) -bool(0) -``` - -用来表示True或者false - -- bytes(二进制序列) - - 二进制的表示形式 - -- None(空) - - 有了false和0,为什么还要有None,因为false有时候也是代表一种结果 - - - -### python的四大基本数据结构 - -- list(列表) - - - 用来装载不同数据类型的数据集结构 - - 列表的特点 - - 有序的 - - 可以装载任意数据类型 - - 可以更改的 - - 如何表示list - - 通过list()新建一个列表 - - 通过[]声明一个列表 - -- tuple(元组) - - - 就是不可修改的列表,常用来表示记录 - - - 特点 - - 不可更改, - - 有序的 - - 可以装载任意数据类型 - - 不可更改 - - - 通过(,)来声明一个元组 - - ``` - a=(1,2,3) - #声明单个元素的元组,要添加逗号 - a=(1,) - ``` - - - 通过tuple()新建一个元组 - - ``` - tuple("hello") - ``` - -- dict(字典) - - - 字典也叫hashtable.通过hash(散列)函数将传入的key值生成地址来查找value - - key->hash->函数->返回value的地址->通过地址返回value值 - - - 特点 - - 无序的 - - python3.6是有序的,无视这一点 - - - 字典的key必须是可hash的,也就是不可更改的,唯一的 - - - 字典本身是可更该的 - - - 如何表示字典 - - - 通过dict()来创建字典 - - ``` - dict(a=2) - ``` - - - 通过{}来声明一个字典 - - ``` - a={"a":2} - ``` - -- set(集合) - - - 什么是set - - 没有value的字典 - - - 特点 - - 无序的 - - 集合中的key必须是可hash的 - - 可以更改的 - - 元素是唯一的 - - - 通过set()来创建集合 - - ``` - set([1,1,3]) - ``` - +## 第一周-第三节课-随堂笔记 + +### 变量和赋值 + +- 什么是变量 + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可重新赋值 + +- 为变量赋值 + + - 通过=来赋值 + + ``` + x=3 + ``` + +- python的变量 + + - 被重新赋值之后的值去哪 + + - 被系统回收了 + + - python没有常量这个数据类型 + + - 程序员之间的约定,如果这个变量的命名都是大字母,那么就视为一个常量 + + + +### python的六大基本类型 + +``` +强调基本的原因,数据类型和数据结构指向的范围更加广泛,不要产生错误的认识,形成思想的定式 +``` + +- 通过type()函数来查看当前变量的数据结构 + +- int(整数) + +- float(浮点数) + + - 因为计算机内部只是1和0,所以浮点数强调的是小数的表现形式 + + - ``` + float('1,o') + float('INF') + ``` + +- string(字符串,字符序列) + - 在有些语言中,单个字符也是一个基本的数据类型(char) + + - 有序的 + + - 如何表示字符串 + - '' + - "" + - '''''''' + + - 转义字符 + + 告诉python解释器,我们当前要表示的是一个字符或特殊字符 + + - 通过 \ 来转义 + + ``` + "2\" + "2\n" + ``` + +​ boolean(布尔值) + +``` +bool(2) +bool(0) +``` + +用来表示True或者false + +- bytes(二进制序列) + + 二进制的表示形式 + +- None(空) + + 有了false和0,为什么还要有None,因为false有时候也是代表一种结果 + + + +### python的四大基本数据结构 + +- list(列表) + + - 用来装载不同数据类型的数据集结构 + - 列表的特点 + - 有序的 + - 可以装载任意数据类型 + - 可以更改的 + - 如何表示list + - 通过list()新建一个列表 + - 通过[]声明一个列表 + +- tuple(元组) + + - 就是不可修改的列表,常用来表示记录 + + - 特点 + + 不可更改, + + 有序的 + + 可以装载任意数据类型 + + 不可更改 + + - 通过(,)来声明一个元组 + + ``` + a=(1,2,3) + #声明单个元素的元组,要添加逗号 + a=(1,) + ``` + + - 通过tuple()新建一个元组 + + ``` + tuple("hello") + ``` + +- dict(字典) + + - 字典也叫hashtable.通过hash(散列)函数将传入的key值生成地址来查找value + + key->hash->函数->返回value的地址->通过地址返回value值 + + - 特点 + + 无序的 + + python3.6是有序的,无视这一点 + + - 字典的key必须是可hash的,也就是不可更改的,唯一的 + + - 字典本身是可更该的 + + - 如何表示字典 + + - 通过dict()来创建字典 + + ``` + dict(a=2) + ``` + + - 通过{}来声明一个字典 + + ``` + a={"a":2} + ``` + +- set(集合) + + - 什么是set + + 没有value的字典 + + - 特点 + + 无序的 + + 集合中的key必须是可hash的 + + 可以更改的 + + 元素是唯一的 + + - 通过set()来创建集合 + + ``` + set([1,1,3]) + ``` + - 通过{}来表示 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/chaos_defined_exception.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/chaos_defined_exception.py" index c268c11061a14badd5e5acc6a00203af0bc3494a..1e5ad1c15d93541c95b9311b681586f1a5c060dc 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/chaos_defined_exception.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/chaos_defined_exception.py" @@ -1,11 +1,11 @@ -class ParmasError(Exception): - """Raised when denominator is zero""" - def __init__(self, expression, message): - self.expression = expression - self.message = message - - -try: - raise (ParmasError("1/0", "The denominator cannot be zero")) -except ParmasError as e: +class ParmasError(Exception): + """Raised when denominator is zero""" + def __init__(self, expression, message): + self.expression = expression + self.message = message + + +try: + raise (ParmasError("1/0", "The denominator cannot be zero")) +except ParmasError as e: print(e.message) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" index 4bbefc83e453b52768ee7b599bf35f5ca7d781fe..979ab41d7406285224d3a8925de1949134b4efde 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" @@ -1,17 +1,17 @@ -def count_use_for(n=10): - result = [] - for x in range(n): - result.append(x) - return result - - -def count_use_while(n=10): - result = [] - while n > 0: - n -= 1 - result.append(n) - return result - - -print(count_use_while(15)) +def count_use_for(n=10): + result = [] + for x in range(n): + result.append(x) + return result + + +def count_use_while(n=10): + result = [] + while n > 0: + n -= 1 + result.append(n) + return result + + +print(count_use_while(15)) print(count_use_for(20)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/practice_function.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/practice_function.py" index 67ac1f714beb98909b6ad49b640113e2772ba40f..eae5d01d63a1ae3583234a19357d51d0a484eb85 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/practice_function.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/practice_function.py" @@ -1,39 +1,39 @@ -from pprint import pprint - -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] - - -# sort list by grade -def sort_by_grade(ori_list): - copy_list = ori_list.copy() - return sorted(copy_list, key=lambda k: k['grade']) - - -# function of filter grade equals to A -def filter_grade(ori_list): - copy_list = ori_list.copy() - filter_result = filter(lambda k: k['grade'] == 'A', copy_list) - return list(filter_result) - - -# use map to increase age -def increase_age_use(ori_list, increase=1): - copy_list = ori_list.copy() - map_result = list(map(lambda v: v['age'] + increase, copy_list)) - for i in range(len(copy_list)): - copy_list[i]['age'] = map_result[i] - return copy_list - - -pprint(classes) -print(sort_by_grade(classes)) -print(filter_grade(classes)) +from pprint import pprint + +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + + +# sort list by grade +def sort_by_grade(ori_list): + copy_list = ori_list.copy() + return sorted(copy_list, key=lambda k: k['grade']) + + +# function of filter grade equals to A +def filter_grade(ori_list): + copy_list = ori_list.copy() + filter_result = filter(lambda k: k['grade'] == 'A', copy_list) + return list(filter_result) + + +# use map to increase age +def increase_age_use(ori_list, increase=1): + copy_list = ori_list.copy() + map_result = list(map(lambda v: v['age'] + increase, copy_list)) + for i in range(len(copy_list)): + copy_list[i]['age'] = map_result[i] + return copy_list + + +pprint(classes) +print(sort_by_grade(classes)) +print(filter_grade(classes)) print(increase_age_use(classes, 1)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/practice_json.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/practice_json.py" index a4bdfaf4cfecc905fd7fd1b4613c93d01c9346fb..ee9f7ee3a58a6a86bbf0ab37e5f97fc5031ce0b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/practice_json.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/practice_json.py" @@ -1,13 +1,13 @@ -import json - - -test_dict = { - "1": "a", - "2": ["a", "b"], - "3": {'4': 'c', '5': 'd'} -} - -json_data = json.dumps(test_dict) -dict_data = json.loads(json_data) -print(type(json_data), json_data) -print(type(dict_data), dict_data) +import json + + +test_dict = { + "1": "a", + "2": ["a", "b"], + "3": {'4': 'c', '5': 'd'} +} + +json_data = json.dumps(test_dict) +dict_data = json.loads(json_data) +print(type(json_data), json_data) +print(type(dict_data), dict_data) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/request_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/request_search.py" index b2e5e8568b06e454c972516602ca148d6ed93c0b..90d9995e130ee6484495354544442ec07410528f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/request_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\200\350\212\202/request_search.py" @@ -1,48 +1,48 @@ -import requests -import time - - -def commodity_jd(keyword): - url = "https://search.jd.com/Search" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers) - return response.text - - -def details_jd(commodity_id): - url = "https://item.jd.com/{}.html".format(commodity_id) - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - return response.text - - -def write_to_file(file_name, content): - with open(file_name, 'w', encoding='utf-8') as f: - f.write(content) - - -if __name__ == "__main__": - commodity = { - '69579131503': "手机", - '100017275152': "电脑", - '32345517501': "男装", - '100018382478': "美妆", - '10026866824101': "男鞋", - '59397995078': "女鞋", - '62603602537': "键盘", - '100017597080': "鼠标", - '100016898598': "显示器", - '100009167181': "屏幕挂灯" - } - for k, v in commodity.items(): - write_to_file(f'commodity_{k}.html', commodity_jd(v)) - time.sleep(5) - write_to_file(f'details_{k}.html', details_jd(k)) +import requests +import time + + +def commodity_jd(keyword): + url = "https://search.jd.com/Search" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers) + return response.text + + +def details_jd(commodity_id): + url = "https://item.jd.com/{}.html".format(commodity_id) + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + return response.text + + +def write_to_file(file_name, content): + with open(file_name, 'w', encoding='utf-8') as f: + f.write(content) + + +if __name__ == "__main__": + commodity = { + '69579131503': "手机", + '100017275152': "电脑", + '32345517501': "男装", + '100018382478': "美妆", + '10026866824101': "男鞋", + '59397995078': "女鞋", + '62603602537': "键盘", + '100017597080': "鼠标", + '100016898598': "显示器", + '100009167181': "屏幕挂灯" + } + for k, v in commodity.items(): + write_to_file(f'commodity_{k}.html', commodity_jd(v)) + time.sleep(5) + write_to_file(f'details_{k}.html', details_jd(k)) time.sleep(5) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/default_settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/default_settings.py" index 86b2aae23848c3dbee53882e71fbc5f18e0a223e..f96dff2827694eea3d71e7a7cdced175b7818a4f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/default_settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/default_settings.py" @@ -1,24 +1,24 @@ -""" -Default configuration -""" - - -HEADERS = { - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36' -} - - -PROXY = { - 'http': '/your/http/proxy/' -} - - -MYSQL_CONF = { - 'db': { - 'host': '127.0.0.1', - 'port': 3306, - 'user': 'chaos', - 'password': 'chaos123456', - 'db': 'spider' - } -} +""" +Default configuration +""" + + +HEADERS = { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36' +} + + +PROXY = { + 'http': '/your/http/proxy/' +} + + +MYSQL_CONF = { + 'db': { + 'host': '127.0.0.1', + 'port': 3306, + 'user': 'chaos', + 'password': 'chaos123456', + 'db': 'spider' + } +} diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" index 18ea711631628801b0a8591d4e26157d84a3bd27..a4f7807bf076e3484f86be2df1b7e500a616bb46 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" @@ -1,45 +1,45 @@ -from W9_L3 import default_settings, parser -import requests -import pymysql -from threading import Thread - - -headers = default_settings.HEADERS -mysql_conf = default_settings.MYSQL_CONF - - -def downloader(task): - url = "https://search.jd.com/Search" - params = { - 'keyword': task - } - response = requests.get(url=url, params=params, headers=headers) - return response - - -def saver(item): - cursor = conn.cursor() - SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) - VALUES (%s, %s, %s, %s, %s, %s)""" - cursor.executemany(SQL, item) - conn.commit() - cursor.close() - - -def main_task(task_array): - for task in task_array: - result = downloader(task) - item = parser.parser(result.text) - saver(item) - - -if __name__ == '__main__': - conn = pymysql.connect(**mysql_conf['db']) - search_array = ["手机", "电脑", "显卡", "内存"] - thread_array = [] - for i in range(4): - t = Thread(target=main_task, args=(search_array, )) - t.start() - thread_array.append(t) - for t in thread_array: - t.join() +from W9_L3 import default_settings, parser +import requests +import pymysql +from threading import Thread + + +headers = default_settings.HEADERS +mysql_conf = default_settings.MYSQL_CONF + + +def downloader(task): + url = "https://search.jd.com/Search" + params = { + 'keyword': task + } + response = requests.get(url=url, params=params, headers=headers) + return response + + +def saver(item): + cursor = conn.cursor() + SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) + VALUES (%s, %s, %s, %s, %s, %s)""" + cursor.executemany(SQL, item) + conn.commit() + cursor.close() + + +def main_task(task_array): + for task in task_array: + result = downloader(task) + item = parser.parser(result.text) + saver(item) + + +if __name__ == '__main__': + conn = pymysql.connect(**mysql_conf['db']) + search_array = ["手机", "电脑", "显卡", "内存"] + thread_array = [] + for i in range(4): + t = Thread(target=main_task, args=(search_array, )) + t.start() + thread_array.append(t) + for t in thread_array: + t.join() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser.py" index 64a21ab2ae016850d3d39733ec02da449dc5fdbf..78795e35f5fac0151e46687adef2c86e8ccf29d2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser.py" @@ -1,24 +1,24 @@ -from bs4 import BeautifulSoup -import json - - -def parser(html): - result = [] - soup = BeautifulSoup(html, 'lxml') - content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in content: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2'] em") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text.strip() if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].text.strip() if shop else "" - icons = json.dumps([ele.text.strip() for ele in icons[0].select('i')]) if icons else '[]' - - result.append((sku_id, img, price, title, shop, icons)) +from bs4 import BeautifulSoup +import json + + +def parser(html): + result = [] + soup = BeautifulSoup(html, 'lxml') + content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in content: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2'] em") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text.strip() if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].text.strip() if shop else "" + icons = json.dumps([ele.text.strip() for ele in icons[0].select('i')]) if icons else '[]' + + result.append((sku_id, img, price, title, shop, icons)) return result \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_bs4.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_bs4.py" index 4c7552bd0330c816fc81e2f3b3c4b62a5ba7fb37..b9a423bb56de366b2f235d438385689d23fcda45 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_bs4.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_bs4.py" @@ -1,25 +1,25 @@ -from bs4 import BeautifulSoup - - -def search(html_file): - result = [] - soup = BeautifulSoup(html_file, 'lxml') - content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in content: - img = item.select("img[data-img='1']") - result.append(img) - return result - - -def practice_bs4_method(html): - soup = BeautifulSoup(html, 'lxml') - content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - item1 = soup.select("li[data-sku='100012223322']")[0] - text = soup.select("div[class='p-name p-name-type-2']")[0].text.strip() - - -if __name__ == '__main__': - with open("moudongshouji.html", 'r', encoding="utf-8") as f: - html_file = f.read() - #search(html_file) - practice_bs4_method(html_file) +from bs4 import BeautifulSoup + + +def search(html_file): + result = [] + soup = BeautifulSoup(html_file, 'lxml') + content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in content: + img = item.select("img[data-img='1']") + result.append(img) + return result + + +def practice_bs4_method(html): + soup = BeautifulSoup(html, 'lxml') + content = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + item1 = soup.select("li[data-sku='100012223322']")[0] + text = soup.select("div[class='p-name p-name-type-2']")[0].text.strip() + + +if __name__ == '__main__': + with open("moudongshouji.html", 'r', encoding="utf-8") as f: + html_file = f.read() + #search(html_file) + practice_bs4_method(html_file) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_css_selector" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_css_selector" index 9c1f19b9f691f67e75a9c9015db4449eb0b73d18..e9846ea4a74fa3eeabb5b7ebfa7791e6d59a9c40 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_css_selector" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\271\235\345\221\250_\347\254\254\344\272\214\350\212\202/practice_css_selector" @@ -1,22 +1,22 @@ -$("#J_filter") -$(".filter") - -$("div[class='p-name p-name-type-2']")[0] -$("li[data-sku='100012223322']")[0] -$("div[class='p-name p-name-type-2']")[0].innerText - -$("li[data-sku*='1']") -$("li[data-sku^='1']") -$("li[data-sku$='1']") - -tmp = $("li[data-sku='100012223322']")[0] -tmp.nextElementSibling -tmp.previousElementSibling -tmp.parentElement - -$("ul[class='gl-warp clearfix'] li:first-child")[0] -$("ul[class='gl-warp clearfix'] li:last-child")[0] -$("ul[class='gl-warp clearfix'] li:nth-child(5)")[0] - -$("ul[class='gl-warp clearfix'] li")[0].getAttribute("data-sku") -$("ul[class='gl-warp clearfix'] li")[0].getAttribute("ware-type") +$("#J_filter") +$(".filter") + +$("div[class='p-name p-name-type-2']")[0] +$("li[data-sku='100012223322']")[0] +$("div[class='p-name p-name-type-2']")[0].innerText + +$("li[data-sku*='1']") +$("li[data-sku^='1']") +$("li[data-sku$='1']") + +tmp = $("li[data-sku='100012223322']")[0] +tmp.nextElementSibling +tmp.previousElementSibling +tmp.parentElement + +$("ul[class='gl-warp clearfix'] li:first-child")[0] +$("ul[class='gl-warp clearfix'] li:last-child")[0] +$("ul[class='gl-warp clearfix'] li:nth-child(5)")[0] + +$("ul[class='gl-warp clearfix'] li")[0].getAttribute("data-sku") +$("ul[class='gl-warp clearfix'] li")[0].getAttribute("ware-type") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" index 3f5dd977e9063901790bf2145d414e78c4fc1062..e4c8fb57e8bbf1bef329e536b0330d78653660ca 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" @@ -1,36 +1,36 @@ -# simple calculator - -# Return x add y -def add(x, y): - return x + y - -# Return x subtract y -def subtract(x, y): - return x - y - -# Return x multiply y -def multiply(x, y): - return x * y - -# Return x divide y -def divide(x, y): - return x / y - -# Return the square root of x -def my_sqrt(x): - return x ** (1 / 2) - -# Return x raised to the power y -def power(x, y): - return x ** y - -def mod(x, y): - return x % y - -print(add(1, 2)) -print(subtract(2, 4)) -print(multiply(4, 8)) -print(divide(8, 16)) -print(my_sqrt(32)) -print(power(64, 2)) -print(mod(128, 5)) +# simple calculator + +# Return x add y +def add(x, y): + return x + y + +# Return x subtract y +def subtract(x, y): + return x - y + +# Return x multiply y +def multiply(x, y): + return x * y + +# Return x divide y +def divide(x, y): + return x / y + +# Return the square root of x +def my_sqrt(x): + return x ** (1 / 2) + +# Return x raised to the power y +def power(x, y): + return x ** y + +def mod(x, y): + return x % y + +print(add(1, 2)) +print(subtract(2, 4)) +print(multiply(4, 8)) +print(divide(8, 16)) +print(my_sqrt(32)) +print(power(64, 2)) +print(mod(128, 5)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_enhance/my_calculator_with_exception_handle.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_enhance/my_calculator_with_exception_handle.py" index ade4b1676d28a52b87dd346392230ee47829018e..616228960668075bc4fce1b4f3cb52d4ba5ed821 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_enhance/my_calculator_with_exception_handle.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_enhance/my_calculator_with_exception_handle.py" @@ -1,57 +1,57 @@ -# simple calculator with exception handling - -operator_set = {'+', 'add', - '-', 'subtract', - '*', 'multiply', - '/', 'divide', - '%', 'mod', - '**', 'power', - '//'} - -def user_input(): - raw_input = [] - while True: - try: - num1 = float(input("Enter first number: ")) - raw_input.append(num1) - num2 = float(input("Enter second number: ")) - raw_input.append(num2) - operator = input("Enter operator: ") - - except Exception as e: - print("Error : {}".format(str(e))) - - else: - if operator in operator_set: - raw_input.append(operator) - break - else: - print("Please re-enter the operator.") - raw_input = [] - - return raw_input - -def calculator(input): - if(input[2] == '+' or input[2] == 'add'): - return input[0] + input[1] - elif(input[2] == '-' or input[2] == 'subtract'): - return input[0] - input[1] - elif(input[2] == '*' or input[2] == 'multipy'): - return input[0] * input[1] - elif(input[2] == '/' or input[2] == 'divide'): - try: - result = input[0] / input[1] - except ZeroDivisionError: - print("divisor can't be zero") - else: - return result - elif(input[2] == '%' or input[2] == 'mod'): - return input[0] % input[1] - elif(input[2] == '**' or input[2] =='power'): - return input[0] ** input[1] - else: - return input[0] // input[1] - -if __name__ == '__main__': - result = calculator(user_input()) +# simple calculator with exception handling + +operator_set = {'+', 'add', + '-', 'subtract', + '*', 'multiply', + '/', 'divide', + '%', 'mod', + '**', 'power', + '//'} + +def user_input(): + raw_input = [] + while True: + try: + num1 = float(input("Enter first number: ")) + raw_input.append(num1) + num2 = float(input("Enter second number: ")) + raw_input.append(num2) + operator = input("Enter operator: ") + + except Exception as e: + print("Error : {}".format(str(e))) + + else: + if operator in operator_set: + raw_input.append(operator) + break + else: + print("Please re-enter the operator.") + raw_input = [] + + return raw_input + +def calculator(input): + if(input[2] == '+' or input[2] == 'add'): + return input[0] + input[1] + elif(input[2] == '-' or input[2] == 'subtract'): + return input[0] - input[1] + elif(input[2] == '*' or input[2] == 'multipy'): + return input[0] * input[1] + elif(input[2] == '/' or input[2] == 'divide'): + try: + result = input[0] / input[1] + except ZeroDivisionError: + print("divisor can't be zero") + else: + return result + elif(input[2] == '%' or input[2] == 'mod'): + return input[0] % input[1] + elif(input[2] == '**' or input[2] =='power'): + return input[0] ** input[1] + else: + return input[0] // input[1] + +if __name__ == '__main__': + result = calculator(user_input()) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202/save_string_function_to_file.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202/save_string_function_to_file.py" index ac492d8153459e45a4caca4cae297043c3432787..51f2d9fe75b550cfbbf37450b73bc41a4bef48da 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202/save_string_function_to_file.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202/save_string_function_to_file.py" @@ -1,101 +1,101 @@ -encode_decode_content = """ ->>> a = 'Hello python' ->>> print(f'original string is : {a}') -original string is : Hello python ->>> encode_bytes = a.encode('utf-8') ->>> print(f'encode bytes is : {encode_bytes}') -encode bytes is : b'Hello python' ->>> decode_correct = encode_bytes.decode('utf-8') ->>> print(f'decode bytes is : {decode_correct}') -decode bytes is : Hello python -""" - -create_string_content = """ ->>> a = "create" ->>> a += " a string" ->>> a -'create a string' ->>> b = "test " + a ->>> b -'test create a string' -""" - -retrieve_string_content = """ ->>> a -'create a string' ->>> a[3] -'a' ->>> a.index("a") -3 ->>> a.find("r") -1 ->>> a.startswith("cr") -True ->>> a.startswith("zr") -False ->>> a.endswith("te") -False ->>> a.endswith("ing") -True -""" - -update_string_content = """ ->>> a -'create a string' ->>> a.replace("create", "delete") -'delete a string' ->>> a.replace("a", "b") -'crebte b string' ->>> a.split(" ") -['create', 'a', 'string'] ->>> ", ".join(a) -'c, r, e, a, t, e, , a, , s, t, r, i, n, g' -""" - -delete_string_content = """ ->>> a = " hello world " ->>> a.strip() -'hello world' ->>> a.lstrip() -'hello world ' ->>> a.rstrip() -' hello world' -""" - -format_string_content = """ -print("hello %s" % "world") -print("hello {0} and {1}.".format("world","Python")) -# after python 3.6 f-strings -language = 'Python' -print(f'hello {language}') -""" - -practice_content = {"encode_decode": encode_decode_content, - "create_string": create_string_content, - "retrieve_string": retrieve_string_content, - "update_string": update_string_content, - "delete_string": delete_string_content, - "format_string": format_string_content} - - -def write_content_to_file(): - practice_file = open("practice.txt", "a+") - for key, val in practice_content.items(): - practice_file.write(f'{key} = \"\"\" {val}\"\"\"\n') - practice_file.close() - - -def check_file_content(): - file_name = "practice.txt" - try: - with open(file_name, 'r') as f: - file_content = f.read() - print(file_content) - print("check done") - except FileNotFoundError as e: - print(f'{e}') - - -if __name__ == '__main__': - write_content_to_file() +encode_decode_content = """ +>>> a = 'Hello python' +>>> print(f'original string is : {a}') +original string is : Hello python +>>> encode_bytes = a.encode('utf-8') +>>> print(f'encode bytes is : {encode_bytes}') +encode bytes is : b'Hello python' +>>> decode_correct = encode_bytes.decode('utf-8') +>>> print(f'decode bytes is : {decode_correct}') +decode bytes is : Hello python +""" + +create_string_content = """ +>>> a = "create" +>>> a += " a string" +>>> a +'create a string' +>>> b = "test " + a +>>> b +'test create a string' +""" + +retrieve_string_content = """ +>>> a +'create a string' +>>> a[3] +'a' +>>> a.index("a") +3 +>>> a.find("r") +1 +>>> a.startswith("cr") +True +>>> a.startswith("zr") +False +>>> a.endswith("te") +False +>>> a.endswith("ing") +True +""" + +update_string_content = """ +>>> a +'create a string' +>>> a.replace("create", "delete") +'delete a string' +>>> a.replace("a", "b") +'crebte b string' +>>> a.split(" ") +['create', 'a', 'string'] +>>> ", ".join(a) +'c, r, e, a, t, e, , a, , s, t, r, i, n, g' +""" + +delete_string_content = """ +>>> a = " hello world " +>>> a.strip() +'hello world' +>>> a.lstrip() +'hello world ' +>>> a.rstrip() +' hello world' +""" + +format_string_content = """ +print("hello %s" % "world") +print("hello {0} and {1}.".format("world","Python")) +# after python 3.6 f-strings +language = 'Python' +print(f'hello {language}') +""" + +practice_content = {"encode_decode": encode_decode_content, + "create_string": create_string_content, + "retrieve_string": retrieve_string_content, + "update_string": update_string_content, + "delete_string": delete_string_content, + "format_string": format_string_content} + + +def write_content_to_file(): + practice_file = open("practice.txt", "a+") + for key, val in practice_content.items(): + practice_file.write(f'{key} = \"\"\" {val}\"\"\"\n') + practice_file.close() + + +def check_file_content(): + file_name = "practice.txt" + try: + with open(file_name, 'r') as f: + file_content = f.read() + print(file_content) + print("check done") + except FileNotFoundError as e: + print(f'{e}') + + +if __name__ == '__main__': + write_content_to_file() check_file_content() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/practice_threading.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/practice_threading.py" index bc203a2e8b4d6fa7e30494b12689067b48a1e69a..c4b03090345f8911b6534b8daf44e49872358a97 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/practice_threading.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/practice_threading.py" @@ -1,18 +1,18 @@ -from threading import Thread -import time - - -def sleeper(i): - print(f"thread {i} sleep for 5 seconds") - time.sleep(5) - print(f"thread {i} wake up") - - -if __name__ == "__main__": - thread_array = [] - for i in range(5): - t = Thread(target=sleeper, args=(i,)) - t.start() - thread_array.append(t) - for t in thread_array: +from threading import Thread +import time + + +def sleeper(i): + print(f"thread {i} sleep for 5 seconds") + time.sleep(5) + print(f"thread {i} wake up") + + +if __name__ == "__main__": + thread_array = [] + for i in range(5): + t = Thread(target=sleeper, args=(i,)) + t.start() + thread_array.append(t) + for t in thread_array: t.join() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/python_process.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/python_process.py" index 1ad2ccfbc84bf8e77ba88a8aac78b34d95a10bca..d18b623df180d359925c4c96ca3d5013059a65d1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/python_process.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/python_process.py" @@ -1,28 +1,28 @@ -from multiprocessing import Process -import os - - -def info(title): - print(title) - print(f"module name is: {__name__}") - print(f"parent process is: {os.getppid()}") - print(f"process is: {os.getpid()}") - - -def f(name): - info("function f") - print(f"hello {name}") - - -if __name__ == "__main__": - info("this is main process") - process_list = [] - for i in range(10): - p = Process(target=f, args=(i,)) - process_list.append(p) - - for p in process_list: - p.start() - - for p in process_list: +from multiprocessing import Process +import os + + +def info(title): + print(title) + print(f"module name is: {__name__}") + print(f"parent process is: {os.getppid()}") + print(f"process is: {os.getpid()}") + + +def f(name): + info("function f") + print(f"hello {name}") + + +if __name__ == "__main__": + info("this is main process") + process_list = [] + for i in range(10): + p = Process(target=f, args=(i,)) + process_list.append(p) + + for p in process_list: + p.start() + + for p in process_list: p.join() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/practice_asyncio.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/practice_asyncio.py" index a0c8ba6968e3b9aafdc7e01905abefdaa8e10fd9..0c6960c90c8de97ed7c918bbee43771d6c4bbcee 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/practice_asyncio.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/practice_asyncio.py" @@ -1,14 +1,14 @@ -import asyncio - - -async def say_hello(delay, name): - await asyncio.sleep(delay) - print(f'hello {name}') - -async def main(l): - for i in l: - await say_hello(1, i) - -loop = asyncio.get_event_loop() -loop.run_until_complete(main(["John", "Mary", "Li lei"])) +import asyncio + + +async def say_hello(delay, name): + await asyncio.sleep(delay) + print(f'hello {name}') + +async def main(l): + for i in l: + await say_hello(1, i) + +loop = asyncio.get_event_loop() +loop.run_until_complete(main(["John", "Mary", "Li lei"])) loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/yield_average.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/yield_average.py" index 85c5725b48e3a89f63b11799469d61fb7598ea41..98e5f66065918fc63207da60252d98c50bd05e36 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/yield_average.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/yield_average.py" @@ -1,15 +1,15 @@ -def yield_average(): - length = 0 - total = 0 - while True: - try: - result = yield total / length - except ZeroDivisionError: - result = yield 0 - total += result - length += 1 - -my_avg = yield_average() -next(my_avg) -print(my_avg.send(2)) +def yield_average(): + length = 0 + total = 0 + while True: + try: + result = yield total / length + except ZeroDivisionError: + result = yield 0 + total += result + length += 1 + +my_avg = yield_average() +next(my_avg) +print(my_avg.send(2)) print(my_avg.send(3)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_ipc.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_ipc.py" index ce81a92323cd950a29684117332087be24b2f807..6c4035093ec78d062e0ae05ca51793e86356c985 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_ipc.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_ipc.py" @@ -1,73 +1,73 @@ -""" -practice IPC -1. Pipe - pipe() returns a pair of connection objects. - each connection object has send() and recv() methods. -2. Queue -3. File -4. Socket -5. Event -6. Shared memory -""" -from multiprocessing import Process, Pipe, Queue, \ - Lock, Array, Value - - -# use pipe and queue for exchanging objects between processes -def ipc_pipe(conn): - conn.send(['hello', 'world']) - conn.close() - -def ipc_queue(i, q): - q.put(i) - - -# use lock for synchronization between processes -def ipc_lock(l, i): - l.acquire() - try: - print(f"hello {i}") - finally: - l.release() - - -# use sharing state between processes -def ipc_sharing_state(n, a): - n.value = 3.1415 - for i in range(len(a)): - a[i] += 1 - - -if __name__ == "__main__": - parent_conn, child_conn = Pipe() - p_pipe = Process(target=ipc_pipe, args=(child_conn,)) - p_pipe.start() - print(parent_conn.recv()) - p_pipe.join() - - q = Queue() - queue_thread_array = [] - for i in range(4): - p_queue = Process(target=ipc_queue, args=(i, q)) - p_queue.start() - queue_thread_array.append(p_queue) - for p in queue_thread_array: - p.join() - while True: - if not q.empty(): - print(q.get()) - else: - break - - lock = Lock() - for i in range(5): - p_lock = Process(target=ipc_lock, args=(lock, i)) - p_lock.start() - - num = Value('d', 0.0) - array = Array('i', range(5)) - p_sharing_state = Process(target=ipc_sharing_state, args=(num, array)) - p_sharing_state.start() - p_sharing_state.join() - print(num.value) +""" +practice IPC +1. Pipe + pipe() returns a pair of connection objects. + each connection object has send() and recv() methods. +2. Queue +3. File +4. Socket +5. Event +6. Shared memory +""" +from multiprocessing import Process, Pipe, Queue, \ + Lock, Array, Value + + +# use pipe and queue for exchanging objects between processes +def ipc_pipe(conn): + conn.send(['hello', 'world']) + conn.close() + +def ipc_queue(i, q): + q.put(i) + + +# use lock for synchronization between processes +def ipc_lock(l, i): + l.acquire() + try: + print(f"hello {i}") + finally: + l.release() + + +# use sharing state between processes +def ipc_sharing_state(n, a): + n.value = 3.1415 + for i in range(len(a)): + a[i] += 1 + + +if __name__ == "__main__": + parent_conn, child_conn = Pipe() + p_pipe = Process(target=ipc_pipe, args=(child_conn,)) + p_pipe.start() + print(parent_conn.recv()) + p_pipe.join() + + q = Queue() + queue_thread_array = [] + for i in range(4): + p_queue = Process(target=ipc_queue, args=(i, q)) + p_queue.start() + queue_thread_array.append(p_queue) + for p in queue_thread_array: + p.join() + while True: + if not q.empty(): + print(q.get()) + else: + break + + lock = Lock() + for i in range(5): + p_lock = Process(target=ipc_lock, args=(lock, i)) + p_lock.start() + + num = Value('d', 0.0) + array = Array('i', range(5)) + p_sharing_state = Process(target=ipc_sharing_state, args=(num, array)) + p_sharing_state.start() + p_sharing_state.join() + print(num.value) print(array[:]) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_read_write.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_read_write.py" index d33f16707ec8a5c04827834d5e10b148a8af5d2e..c32c831541b27d1d0ec195536b01f3ace74acf0d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_read_write.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_read_write.py" @@ -1,36 +1,36 @@ -""" -Using locks, conditions, and semaphores in the with statement -usage: - -with some_lock: - # do something... - -is equivalent to: - -some_lock.acquire() -try: - # do something... -finally: - some_lock.release() -""" -from multiprocessing import Process, Lock - - -def file_lock(l, i): - with l: - with open("test.log", 'a', encoding="utf-8") as f: - f.write(str(i)) - - -if __name__ == "__main__": - p_file = [] - l = Lock() - for i in range(5): - p = Process(target=file_lock, args=(l, i)) - p.start() - p_file.append(p) - for p in p_file: - p.join() - - with open("test.log", 'r') as f: +""" +Using locks, conditions, and semaphores in the with statement +usage: + +with some_lock: + # do something... + +is equivalent to: + +some_lock.acquire() +try: + # do something... +finally: + some_lock.release() +""" +from multiprocessing import Process, Lock + + +def file_lock(l, i): + with l: + with open("test.log", 'a', encoding="utf-8") as f: + f.write(str(i)) + + +if __name__ == "__main__": + p_file = [] + l = Lock() + for i in range(5): + p = Process(target=file_lock, args=(l, i)) + p.start() + p_file.append(p) + for p in p_file: + p.join() + + with open("test.log", 'r') as f: print(f.read()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_thread_with_lock.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_thread_with_lock.py" index a02e374fa2ff5476de8e54a4c2f8ba891f52d728..fc63811c7852ee2acf4edd9d3835ed6d4e2c20d7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_thread_with_lock.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/practice_thread_with_lock.py" @@ -1,23 +1,23 @@ -from threading import Thread, Lock - - -num = 0 - -def thread_lock(l): - global num - for i in range(10**6): - with l: - num += i - num -= i - - -if __name__ == "__main__": - lock = Lock() - arr = [] - for _ in range(3): - lock_thread = Thread(target=thread_lock, args=(lock,)) - lock_thread.start() - arr.append(lock_thread) - for t in arr: - t.join() +from threading import Thread, Lock + + +num = 0 + +def thread_lock(l): + global num + for i in range(10**6): + with l: + num += i + num -= i + + +if __name__ == "__main__": + lock = Lock() + arr = [] + for _ in range(3): + lock_thread = Thread(target=thread_lock, args=(lock,)) + lock_thread.start() + arr.append(lock_thread) + for t in arr: + t.join() print(num) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202/test_pymysql.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202/test_pymysql.py" index e98b4d75b8055015c4116fa0f944772dc26e2ee5..09cbffedcfa80867becfe54f2a5b5db83099ac5f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202/test_pymysql.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\211\350\212\202/test_pymysql.py" @@ -1,66 +1,66 @@ -import pymysql -import random -import time - - -# MySQL configuration -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "chaos", - "password": "test123456", - "db": "python_test" -} - - -# 连接数据库 -con = pymysql.connect(**MYSQL_CONF) -my_cur = con.cursor() - - -# fetchone() -try: - with con.cursor() as cur: - cur.execute('SELECT VERSION()') - version = cur.fetchone() - print(f'MySQL version is {version[0]}') -finally: - con.close() - - -# fetchall() -try: - with con.cursor() as cur: - cur.execute('SELECT * FROM players') - rows = cur.fetchall() - for i in rows: - print(f'{row[0]} {row[1]} {row[2]}') -finally: - con.close() - - -def insert_one(): - for i in range(10 ** 4): - player_id = f'player_{i}' - score = f'score {random.randint(1, 50)}' - game_time = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO players(player_id, score, game_time) - VALUES ('{player_id}', '{score}', '{game_time}')""" - - print(SQL) - my_cur.execute(SQL) - con.commit() - -def insert_many(): - my_list = [] - for i in range(10 ** 4): - player_id = f'player_{i}' - score = f'score {random.randint(1, 50)}' - game_time = time.strftime("%Y-%m-%d") - my_list.append((player_id, score, game_time)) - - SQL = f"""INSERT INTO players(player_id, score, game_time) - VALUES ('{player_id}', '{score}', '{game_time}')""" - print(my_list) - my_cur.executemany(SQL, my_list) +import pymysql +import random +import time + + +# MySQL configuration +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "chaos", + "password": "test123456", + "db": "python_test" +} + + +# 连接数据库 +con = pymysql.connect(**MYSQL_CONF) +my_cur = con.cursor() + + +# fetchone() +try: + with con.cursor() as cur: + cur.execute('SELECT VERSION()') + version = cur.fetchone() + print(f'MySQL version is {version[0]}') +finally: + con.close() + + +# fetchall() +try: + with con.cursor() as cur: + cur.execute('SELECT * FROM players') + rows = cur.fetchall() + for i in rows: + print(f'{row[0]} {row[1]} {row[2]}') +finally: + con.close() + + +def insert_one(): + for i in range(10 ** 4): + player_id = f'player_{i}' + score = f'score {random.randint(1, 50)}' + game_time = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO players(player_id, score, game_time) + VALUES ('{player_id}', '{score}', '{game_time}')""" + + print(SQL) + my_cur.execute(SQL) + con.commit() + +def insert_many(): + my_list = [] + for i in range(10 ** 4): + player_id = f'player_{i}' + score = f'score {random.randint(1, 50)}' + game_time = time.strftime("%Y-%m-%d") + my_list.append((player_id, score, game_time)) + + SQL = f"""INSERT INTO players(player_id, score, game_time) + VALUES ('{player_id}', '{score}', '{game_time}')""" + print(my_list) + my_cur.executemany(SQL, my_list) con.commit() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\345\221\250_\347\254\254\344\270\200\350\212\202/test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\345\221\250_\347\254\254\344\270\200\350\212\202/test.py" index 370f54a9a48e17bed9c8aa4de3e3f5a2dc2b39a8..ad3a8a470d525f6005f99c07bd6bc0f5c277f956 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\345\221\250_\347\254\254\344\270\200\350\212\202/test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\345\221\250_\347\254\254\344\270\200\350\212\202/test.py" @@ -1,9 +1,9 @@ -import sys -from W9_L3 import main -import os - -print(f'current dir is : {os.getcwd()}') -path = os.path.dirname(os.path.abspath(__file__)) -print(f'path is : {path}') -print(f'sys path is : {sys.path}') +import sys +from W9_L3 import main +import os + +print(f'current dir is : {os.getcwd()}') +path = os.path.dirname(os.path.abspath(__file__)) +print(f'path is : {path}') +print(f'sys path is : {sys.path}') print(main.downloader("iphone").status_code) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202/datetime_usage.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202/datetime_usage.py" index f762a1cc5fe6cb1c213c80f44c3ab0f409f31023..08f01ebbcb0e40047b4bda5163bd4aa82d683886 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202/datetime_usage.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202/datetime_usage.py" @@ -1,55 +1,55 @@ -import datetime - - -now = datetime.datetime.now() -today = datetime.date.today() -tomorrow = datetime.timedelta(days = 1) -birthday = datetime.date(1990, 1, 1) - -t1 = datetime.timedelta(weeks=1, days=2, hours=1, seconds=33) -t2 = datetime.timedelta(weeks=2, days=1, hours=2, seconds=33) - -time_now = now.strftime("%H:%M:%S") -time_now_2 = today.strftime("%Y-%m-%d %H:%M:%S") - - -# get current date and time -print(now) -print(type(now)) - - -# get current date -print(today) -print(type(today)) - - -# date object to represent a date -# expected result: 2019-02-04 -print(birthday) - - -# difference between two dates and times -print(f'time difference is {t2 - t1}') - - -# format date using strftime() -print(time_now) -print(time_now_2) - - -# arithmetic with timedelta -print(f'tomorrow is {now + tomorrow}') - - -# get date after offset day_delta -def get_date(day_delta=1): - now = datetime.date.today() - try: - time_delta = datetime.timedelta(days = day_delta) - except OverflowError as e: - print(f'e') - return now + time_delta - - -# test function get_date +import datetime + + +now = datetime.datetime.now() +today = datetime.date.today() +tomorrow = datetime.timedelta(days = 1) +birthday = datetime.date(1990, 1, 1) + +t1 = datetime.timedelta(weeks=1, days=2, hours=1, seconds=33) +t2 = datetime.timedelta(weeks=2, days=1, hours=2, seconds=33) + +time_now = now.strftime("%H:%M:%S") +time_now_2 = today.strftime("%Y-%m-%d %H:%M:%S") + + +# get current date and time +print(now) +print(type(now)) + + +# get current date +print(today) +print(type(today)) + + +# date object to represent a date +# expected result: 2019-02-04 +print(birthday) + + +# difference between two dates and times +print(f'time difference is {t2 - t1}') + + +# format date using strftime() +print(time_now) +print(time_now_2) + + +# arithmetic with timedelta +print(f'tomorrow is {now + tomorrow}') + + +# get date after offset day_delta +def get_date(day_delta=1): + now = datetime.date.today() + try: + time_delta = datetime.timedelta(days = day_delta) + except OverflowError as e: + print(f'e') + return now + time_delta + + +# test function get_date print(get_date(-9999)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/abstract_factory.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/abstract_factory.py" index 42f0b2e207e91f01a16e5935bec337dceaaaeb0e..cf1805d9dd47b9b73882acaee5d069b30804d8bf 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/abstract_factory.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/abstract_factory.py" @@ -1,52 +1,52 @@ -class PetShop: - welcome = "Welcome to our pet shop" - __hiden = "We are a free pet shop" - - def __init__(self, name, animal_factory=None): - self.name = name - self.__sex = "male" - self.pet_factory = animal_factory - - def show_pet(self): - pet = self.pet_factory() - print(f"We have a {self.__sex} {pet} named {self.name}") - print(f"It says {pet.speak()}") - - -class Dog: - def speak(self): - return "wang wang" - - def __str__(self): - return "Dog" - - -class Cat: - def speak(self): - return "miao miao" - - def __str__(self): - return "Cat" - - -def main(): - """ - >>> dog_shop = PetShop("bobi", Dog) - >>> cat_shop = PetShop("susu", Cat) - >>> PetShop._PetShop__hiden - 'We are a free pet shop' - >>> dog_shop.welcome - 'Welcome to our pet shop' - >>> dog_shop.show_pet() - We have a male Dog named bobi - It says wang wang - >>> cat_shop.show_pet() - We have a male Cat named susu - It says miao miao - """ - - -if __name__ == "__main__": - import doctest - +class PetShop: + welcome = "Welcome to our pet shop" + __hiden = "We are a free pet shop" + + def __init__(self, name, animal_factory=None): + self.name = name + self.__sex = "male" + self.pet_factory = animal_factory + + def show_pet(self): + pet = self.pet_factory() + print(f"We have a {self.__sex} {pet} named {self.name}") + print(f"It says {pet.speak()}") + + +class Dog: + def speak(self): + return "wang wang" + + def __str__(self): + return "Dog" + + +class Cat: + def speak(self): + return "miao miao" + + def __str__(self): + return "Cat" + + +def main(): + """ + >>> dog_shop = PetShop("bobi", Dog) + >>> cat_shop = PetShop("susu", Cat) + >>> PetShop._PetShop__hiden + 'We are a free pet shop' + >>> dog_shop.welcome + 'Welcome to our pet shop' + >>> dog_shop.show_pet() + We have a male Dog named bobi + It says wang wang + >>> cat_shop.show_pet() + We have a male Cat named susu + It says miao miao + """ + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/my_math_static.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/my_math_static.py" index fd951b7e007189549d671791a2f1dae218e4a456..5333043304523f99b01cc70fb1311f843de17f67 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/my_math_static.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/my_math_static.py" @@ -1,57 +1,57 @@ -class MyStaticMath: - def __init__(self, name): - self.name = name - print(f"This is {self.name}'s Static Math class") - - @staticmethod - def add(x, y): - return x + y - - @staticmethod - def subtract(x, y): - return x - y - - @staticmethod - def multiply(x, y): - return x * y - - @staticmethod - def divide(x, y): - return x / y - - @staticmethod - def my_sqrt(x, const=1/2): - return x ** const - - @staticmethod - def power(x, y): - return x ** y - - @staticmethod - def mod(x, y): - return x % y - - -def main(): - """ - >>> MyStaticMath.add(1, 2) - 3 - >>> MyStaticMath.my_sqrt(4) - 2.0 - >>> MyStaticMath.subtract(2, 1) - 1 - >>> MyStaticMath.multiply(3, 4) - 12 - >>> MyStaticMath.divide(6, 4) - 1.5 - >>> MyStaticMath.power(2, 4) - 16 - >>> MyStaticMath.mod(10, 3) - 1 - """ - - -if __name__ == "__main__": - import doctest - +class MyStaticMath: + def __init__(self, name): + self.name = name + print(f"This is {self.name}'s Static Math class") + + @staticmethod + def add(x, y): + return x + y + + @staticmethod + def subtract(x, y): + return x - y + + @staticmethod + def multiply(x, y): + return x * y + + @staticmethod + def divide(x, y): + return x / y + + @staticmethod + def my_sqrt(x, const=1/2): + return x ** const + + @staticmethod + def power(x, y): + return x ** y + + @staticmethod + def mod(x, y): + return x % y + + +def main(): + """ + >>> MyStaticMath.add(1, 2) + 3 + >>> MyStaticMath.my_sqrt(4) + 2.0 + >>> MyStaticMath.subtract(2, 1) + 1 + >>> MyStaticMath.multiply(3, 4) + 12 + >>> MyStaticMath.divide(6, 4) + 1.5 + >>> MyStaticMath.power(2, 4) + 16 + >>> MyStaticMath.mod(10, 3) + 1 + """ + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" index 699d14353199ece94efd009fb51b3ab2c94fb544..b95d9bdea5382f9b361db089ee946c7d6803096d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" @@ -1,46 +1,46 @@ -class MyMath: - def __init__(self, name): - self.name = name - print(f"This is {self.name}'s Math class") - - - def add(self, x, y): - result = x + y - print(f'The result of {x} add {y} is {result}') - - - def subtract(self, x, y): - result = x - y - print(f'The result of {x} subtract {y} is {result}') - - - def multiply(self, x, y): - result = x * y - print(f'The result of {x} multiply {y} is {result}') - - - def divide(self, x, y): - result = x / y - print(f'The result of {x} divide {y} is {result}') - - - def my_sqrt(self, x, cons=1/2): - result = x ** cons - print(f'The result of {x}\'s sqrt is {result}') - - - def power(self, x, y): - result = x ** y - print(f'The result of {x} power {y} is {result}') - - - def mod(self, x, y): - result = x % y - print(f'The result of {x} mod {y} is {result}') - - - -chaos_math = MyMath('chaos') -chaos_math.add(5, 6) -chaos_math.subtract(1, 2) +class MyMath: + def __init__(self, name): + self.name = name + print(f"This is {self.name}'s Math class") + + + def add(self, x, y): + result = x + y + print(f'The result of {x} add {y} is {result}') + + + def subtract(self, x, y): + result = x - y + print(f'The result of {x} subtract {y} is {result}') + + + def multiply(self, x, y): + result = x * y + print(f'The result of {x} multiply {y} is {result}') + + + def divide(self, x, y): + result = x / y + print(f'The result of {x} divide {y} is {result}') + + + def my_sqrt(self, x, cons=1/2): + result = x ** cons + print(f'The result of {x}\'s sqrt is {result}') + + + def power(self, x, y): + result = x ** y + print(f'The result of {x} power {y} is {result}') + + + def mod(self, x, y): + result = x % y + print(f'The result of {x} mod {y} is {result}') + + + +chaos_math = MyMath('chaos') +chaos_math.add(5, 6) +chaos_math.subtract(1, 2) chaos_math.my_sqrt(4) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/practice_class_usage.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/practice_class_usage.py" index 3adaeb7ad460b5fe9a8db83af820dc9737acfe54..f4f5a8008adc68093e918bd20229adbd70447478 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/practice_class_usage.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/practice_class_usage.py" @@ -1,22 +1,22 @@ -class A: - def __init__(self): - print("Enter A") - print("Leave A") - - -class B(A): - def __init__(self): - print("Enter B") - super(B, self).__init__() - print("Leave B") - - -class C(B, A): - def __init__(self): - print("Enter C") - super(C, self).__init__() - print("Leave C") - - -c = C() +class A: + def __init__(self): + print("Enter A") + print("Leave A") + + +class B(A): + def __init__(self): + print("Enter B") + super(B, self).__init__() + print("Leave B") + + +class C(B, A): + def __init__(self): + print("Enter C") + super(C, self).__init__() + print("Leave C") + + +c = C() print(C.mro()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/self_defined_class.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/self_defined_class.py" index 572e5cc7e9d4e693a292e26159fb2bcfa2ba8599..b2195e71264696906a52ec167b008bf586a95fb9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/self_defined_class.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/self_defined_class.py" @@ -1,19 +1,19 @@ -class Animal: - def __init__(self, sex): - self.sex = sex - - -class Mammal(Animal): - def __init__(self, category, sex): - self.category = category - super(Mammal, self).__init__(sex) - - -class Dog(Mammal): - def __init__(self, name, action, sex, category): - super(Dog, self).__init__(category, sex) - print(f'{name} is {action}ning to me ' - f'and it is a {self.sex} {self.category}') - - +class Animal: + def __init__(self, sex): + self.sex = sex + + +class Mammal(Animal): + def __init__(self, category, sex): + self.category = category + super(Mammal, self).__init__(sex) + + +class Dog(Mammal): + def __init__(self, name, action, sex, category): + super(Dog, self).__init__(category, sex) + print(f'{name} is {action}ning to me ' + f'and it is a {self.sex} {self.category}') + + haha = Dog("haha", "run", "male", "mammal") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" index f7e2fba75dc642d6fcf15c0b73f6dd950f7118bc..158d3272608ad406e40b9720ea356a78006af811 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" @@ -1,56 +1,56 @@ -**1.讲述清楚,我们在浏览器输入URL到页面展示发生了什么?** - -- 输入URL -- DNS解析(根据域名,拿到服务端的IP) -- 客户端和服务端建立连接(TCP/IP连接) -- 服务端返回一个包含HTML等文件的资源包 -- 浏览器进行渲染,就是我们看到的页面展示 - -**2.五层协议是哪五层?举例说明。** - -- 第一层:应用层 - - - 为进程(客户端应用)和进程(服务器应用)之间提供服务。定义数据交互方式 - - ``` - TELNET, SSH, HTTP, HTTPS, SMTP, POP, SSL/TLS, FTP, MIME, HTML, SNMP, MIB, SIP, RTP…… - ``` - -- 第二层:传输层 - - - 负责为两个主机应用进程之间的通信提供服务。 - - ``` - TCP, UDP, UDP-Lite, SCTP, DCCP - ``` - -- 第三层:网络层 - - - 封装和分组运输层产生的报文段/用户数据段,负责为分组交换网上的不同主机提供通信服务 - - ``` - IPv4, IPv6, ICMP, IPsec - ``` - -- 第四层:数据链路层 - - - 负责两台主机的数据传输,向网络层提供数据传输服务。主要作用是检查和纠错 - - ``` - 流量控制,差错检测,差错控制,协议,wifi,以太网,ARP - ``` - -- 第五层:物理层 - - - 在局域网上传播数据帧,负责管理电脑等通信设备和网络媒体之间的互通。 - - ``` - 双绞线电缆,光纤,集成器,中继器 - ``` - - - - - - - +**1.讲述清楚,我们在浏览器输入URL到页面展示发生了什么?** + +- 输入URL +- DNS解析(根据域名,拿到服务端的IP) +- 客户端和服务端建立连接(TCP/IP连接) +- 服务端返回一个包含HTML等文件的资源包 +- 浏览器进行渲染,就是我们看到的页面展示 + +**2.五层协议是哪五层?举例说明。** + +- 第一层:应用层 + + - 为进程(客户端应用)和进程(服务器应用)之间提供服务。定义数据交互方式 + + ``` + TELNET, SSH, HTTP, HTTPS, SMTP, POP, SSL/TLS, FTP, MIME, HTML, SNMP, MIB, SIP, RTP…… + ``` + +- 第二层:传输层 + + - 负责为两个主机应用进程之间的通信提供服务。 + + ``` + TCP, UDP, UDP-Lite, SCTP, DCCP + ``` + +- 第三层:网络层 + + - 封装和分组运输层产生的报文段/用户数据段,负责为分组交换网上的不同主机提供通信服务 + + ``` + IPv4, IPv6, ICMP, IPsec + ``` + +- 第四层:数据链路层 + + - 负责两台主机的数据传输,向网络层提供数据传输服务。主要作用是检查和纠错 + + ``` + 流量控制,差错检测,差错控制,协议,wifi,以太网,ARP + ``` + +- 第五层:物理层 + + - 在局域网上传播数据帧,负责管理电脑等通信设备和网络媒体之间的互通。 + + ``` + 双绞线电缆,光纤,集成器,中继器 + ``` + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" index fbe7ce341fa80a2359bcd2a05850a37cc7d0e42a..6b6df0fab9a5ab926f814c8eb9bf9000da072b3a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_spiderchen/Week6/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202_\350\257\276\345\220\216\344\275\234\344\270\232.md" @@ -1,29 +1,29 @@ -**1.讲述TCP/IP三次握手** - -- 客户端向服务端发送带有SYN标识的数据包,服务端确认了客户端的发送能力是正常的。 -- 服务端向客户端返回带有SYN/ACK标识的数据包。服务端确认自己的接收能力是正常的 -- 客户端向服务端发送带有ACK标识的数据包。服务端确认了自己发送能力正常,客户端接收能力正常。 - -至此,客户端和服务端都确认了彼此的收发能力是正常的。 - - - -**2.讲述TCP/IP四次挥手** - -*以客户端作为主动关闭方来描述四次挥手的过程。* - -- 客户端向服务端发送一个FIN数据包。目的是关闭客户端到服务端的连接通道 -- 服务端收到FIN数据包之后,向客户端返回ACK数据包。目的是通知客户端,服务端已经知道了客户端到服务端的连接通道已经关闭。 -- 服务端关闭与客户端的链接,并向客户端发送FIN数据包。 -- 客户端收到服务端发送的FIN数据包之后,向服务端返回ACK数据包。目的是通知服务端,客户端已经知道了服务端到客户端的连接通道已关闭。 - - - -**3.讲述HTTPS加密的过程** - -- 客户端向服务端发送通信请求 -- 服务端向客户端返回证书和密钥 -- 客户端通过CA中心验证证书的真实性 -- 客户端完成认证后,使用密钥对发送的内容进行加密,发送给服务端 -- 服务端收到加密后的请求数据后,使用私钥进行解密 +**1.讲述TCP/IP三次握手** + +- 客户端向服务端发送带有SYN标识的数据包,服务端确认了客户端的发送能力是正常的。 +- 服务端向客户端返回带有SYN/ACK标识的数据包。服务端确认自己的接收能力是正常的 +- 客户端向服务端发送带有ACK标识的数据包。服务端确认了自己发送能力正常,客户端接收能力正常。 + +至此,客户端和服务端都确认了彼此的收发能力是正常的。 + + + +**2.讲述TCP/IP四次挥手** + +*以客户端作为主动关闭方来描述四次挥手的过程。* + +- 客户端向服务端发送一个FIN数据包。目的是关闭客户端到服务端的连接通道 +- 服务端收到FIN数据包之后,向客户端返回ACK数据包。目的是通知客户端,服务端已经知道了客户端到服务端的连接通道已经关闭。 +- 服务端关闭与客户端的链接,并向客户端发送FIN数据包。 +- 客户端收到服务端发送的FIN数据包之后,向服务端返回ACK数据包。目的是通知服务端,客户端已经知道了服务端到客户端的连接通道已关闭。 + + + +**3.讲述HTTPS加密的过程** + +- 客户端向服务端发送通信请求 +- 服务端向客户端返回证书和密钥 +- 客户端通过CA中心验证证书的真实性 +- 客户端完成认证后,使用密钥对发送的内容进行加密,发送给服务端 +- 服务端收到加密后的请求数据后,使用私钥进行解密 - 服务器和客户端使用对称加密进行通信。 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/my_calculator.py" index 6b02a7027b43eb9c69f68a15b679028a18743f9d..f329c73b8b17d29d3bac47e496297d0a1409597a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/my_calculator.py" @@ -1,22 +1,22 @@ -def add(a, b): - print(a+b) -#加法 -def minus(a, b): - print(a-b) -#减法 -def mul(a, b): - print(a*b) -#乘法 -def div(a, b): - print(a/b) -#除法 -def amul(a, b): - print(a//b) -#整除 -def yu(a, b): - print(a%b) -#取余 -def pre(a, b): - print(a**b) -#开方 - +def add(a, b): + print(a+b) +#加法 +def minus(a, b): + print(a-b) +#减法 +def mul(a, b): + print(a*b) +#乘法 +def div(a, b): + print(a/b) +#除法 +def amul(a, b): + print(a//b) +#整除 +def yu(a, b): + print(a%b) +#取余 +def pre(a, b): + print(a**b) +#开方 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\2541\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\2541\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232.md" index d5a5d7c96f08cb05f3ceaea940d72d17d3bff50b..fe8ded28754066eb188232748db245f8be034a7c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\2541\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\2541\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,26 +1,26 @@ -# 1.四大基本数据结构中哪些是可变的,哪些是不可变的? - -## ①元素可变的数据结构:list(列表)、dict - -### list改变元素方式:a=["1",“2”]、list("") - -#### 在末尾添加a.append("x"), - -#### 在列表中添加a.insert(0,"x") - -#### 在列表中删除del a[0]、a.pop(0)、a.remove("x") - -### dict可添加、改变、删除key值,但key是唯一的、不可更改。 - -## ②元素不可变的数据结构:tuple(元组)、set。 - - - -# 2.四大基本数据结构中哪些是有序的、哪些是无序的? - -## 有序的:list,tuple - -## 无序的:set,dict - - - +# 1.四大基本数据结构中哪些是可变的,哪些是不可变的? + +## ①元素可变的数据结构:list(列表)、dict + +### list改变元素方式:a=["1",“2”]、list("") + +#### 在末尾添加a.append("x"), + +#### 在列表中添加a.insert(0,"x") + +#### 在列表中删除del a[0]、a.pop(0)、a.remove("x") + +### dict可添加、改变、删除key值,但key是唯一的、不可更改。 + +## ②元素不可变的数据结构:tuple(元组)、set。 + + + +# 2.四大基本数据结构中哪些是有序的、哪些是无序的? + +## 有序的:list,tuple + +## 无序的:set,dict + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" index 088ad177e9148fff9cabffce7c06ff0db2566cc6..cc0753acbc852329e77fba2ff01654d50fb24bb7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" @@ -1,18 +1,18 @@ -g=True -t=b"hello" -ff=None -list1=["a","2","1.0",g,t,ff] -tuple2=("a",2,1.0,g,t,ff) -dict3={ - "a":"aa", - "b":34, - "c":1.0, - "d":True, - "e":b"hello", - "f":None -} -set4={"a",2,1.0,g,t,ff} -print(list1) -print(tuple2) -print(dict3) -print(set4) +g=True +t=b"hello" +ff=None +list1=["a","2","1.0",g,t,ff] +tuple2=("a",2,1.0,g,t,ff) +dict3={ + "a":"aa", + "b":34, + "c":1.0, + "d":True, + "e":b"hello", + "f":None +} +set4={"a",2,1.0,g,t,ff} +print(list1) +print(tuple2) +print(dict3) +print(set4) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" index 7fba1363a288d7215e6012a2ba3a6b28f6c70fa3..6cb76bb588c3fd014c93f1aca8963f9e1e6c43d9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2541\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211\347\254\254\344\270\200\345\221\250\347\254\2543\350\212\202\350\257\276\344\275\234\344\270\232\347\254\2543\351\227\256.py.py" @@ -1,18 +1,18 @@ -g = True -t = b"hello" -ff = None -list1 = ["a", "2", "1.0", g, t, ff] -tuple2 = ("a", 2, 1.0, g, t, ff) -dict3 = { - "a": "aa", - "b": 34, - "c": 1.0, - "d": True, - "e": b"hello", - "f": None -} -set4 = {"a", 2, 1.0, g, t, ff} -print(list1) -print(tuple2) -print(dict3) -print(set4) +g = True +t = b"hello" +ff = None +list1 = ["a", "2", "1.0", g, t, ff] +tuple2 = ("a", 2, 1.0, g, t, ff) +dict3 = { + "a": "aa", + "b": 34, + "c": 1.0, + "d": True, + "e": b"hello", + "f": None +} +set4 = {"a", 2, 1.0, g, t, ff} +print(list1) +print(tuple2) +print(dict3) +print(set4) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2ed week work mistakes.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2ed week work mistakes.md" index 2bbc2c5481daf551e0b538b0387100d03f4824bc..694228083beb46065545e08868e59e862c1b7c5e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2ed week work mistakes.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2ed week work mistakes.md" @@ -1,41 +1,41 @@ -# 2ed week work mistakes - -## 1.变量与运算符之间要空格 - -## 2.函数与函数之间空两行 - -``` -def add(a, b): - print(a+ b) -#加法 - - -def minus(a, b): - print(a - b) -#减法 - - -def mul(a, b): - print(a * b) -#乘法 - - -def div(a, b): - print(a / b) -#除法 - - -def amul(a, b): - print(a // b) -#整除 - - -def yu(a, b): - print(a % b) -#取余 - - -def pre(a, b): - print(a ** b) -#开方 +# 2ed week work mistakes + +## 1.变量与运算符之间要空格 + +## 2.函数与函数之间空两行 + +``` +def add(a, b): + print(a+ b) +#加法 + + +def minus(a, b): + print(a - b) +#减法 + + +def mul(a, b): + print(a * b) +#乘法 + + +def div(a, b): + print(a / b) +#除法 + + +def amul(a, b): + print(a // b) +#整除 + + +def yu(a, b): + print(a % b) +#取余 + + +def pre(a, b): + print(a ** b) +#开方 ``` \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211my_calculator.py" index 7ad15198fb39da864fe241d24d472e9942e7ce67..d88e97d5538a1a97827d5025fbe462d9d1f856d9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\2102\346\224\271\357\274\211my_calculator.py" @@ -1,51 +1,51 @@ -#加法 -def add(a, b): - print(f"{a} + {b} =" ) - print(a + b) -add(3, 4) -#加法 - - -def minus(a, b): - print(f"{a} - {b} =") - print(a - b) -minus(1, 5) -#减法 - - -def mul(a, b): - print(f"{a} * {b} =") - print(a * b) -mul(5, 7) -#乘法 - - -def div(a, b): - print(f"{a} / {b} =") - print(a / b) -div(8, 2) -#除法 - - -def amul(a, b): - print(f"{a} // {b} =") - print(a // b) -amul(4, 7) -#整除 - - -def yu(a, b): - print(f"{a} % {b} =") - print(a % b) -yu(7, 8) -#取余 - - -def pre(a, b): - print(f"{a} ** {b} =") - print(a ** b) -pre(7, 9) -#开方 - - - +#加法 +def add(a, b): + print(f"{a} + {b} =" ) + print(a + b) +add(3, 4) +#加法 + + +def minus(a, b): + print(f"{a} - {b} =") + print(a - b) +minus(1, 5) +#减法 + + +def mul(a, b): + print(f"{a} * {b} =") + print(a * b) +mul(5, 7) +#乘法 + + +def div(a, b): + print(f"{a} / {b} =") + print(a / b) +div(8, 2) +#除法 + + +def amul(a, b): + print(f"{a} // {b} =") + print(a // b) +amul(4, 7) +#整除 + + +def yu(a, b): + print(f"{a} % {b} =") + print(a % b) +yu(7, 8) +#取余 + + +def pre(a, b): + print(f"{a} ** {b} =") + print(a ** b) +pre(7, 9) +#开方 + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\210\346\224\271\357\274\211my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\210\346\224\271\357\274\211my_calculator.py" index af3279e70e4e4ce9ef82d4c01f5f1f3b394125ed..ae561b095d2658ac181a90cb9ae79e5ab4f82f13 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\210\346\224\271\357\274\211my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\357\274\210\346\224\271\357\274\211my_calculator.py" @@ -1,36 +1,36 @@ -def add(a, b): - print(a + b) -#加法 - - -def minus(a, b): - print(a - b) -#减法 - - -def mul(a, b): - print(a * b) -#乘法 - - -def div(a, b): - print(a / b) -#除法 - - -def amul(a, b): - print(a // b) -#整除 - - -def yu(a, b): - print(a % b) -#取余 - - -def pre(a, b): - print(a ** b) -#开方 - - - +def add(a, b): + print(a + b) +#加法 + + +def minus(a, b): + print(a - b) +#减法 + + +def mul(a, b): + print(a * b) +#乘法 + + +def div(a, b): + print(a / b) +#除法 + + +def amul(a, b): + print(a // b) +#整除 + + +def yu(a, b): + print(a % b) +#取余 + + +def pre(a, b): + print(a ** b) +#开方 + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/1-\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/1-\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" index e65e0e8558c37c01050226e781f7bfb0005818fd..8b05964dd3582db8a5f2eac78616547ad3e54437 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/1-\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/1-\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" @@ -1,9 +1,9 @@ -#编码 -"你好".encode("utf-8") -b'\xe4\xbd\xa0\xe5\xa5\xbd' - - -#解码 ->>> b'\xe4\xbd\xa0\xe5\xa5\xbd'.decode("utf") -'你好' - +#编码 +"你好".encode("utf-8") +b'\xe4\xbd\xa0\xe5\xa5\xbd' + + +#解码 +>>> b'\xe4\xbd\xa0\xe5\xa5\xbd'.decode("utf") +'你好' + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/2-\345\255\227\347\254\246\344\270\262\347\232\204CRUD\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/2-\345\255\227\347\254\246\344\270\262\347\232\204CRUD\347\273\203\344\271\240.py" index 7acda5fef3b11eb5bb46696e6a15bf67cca1fb71..1f8df48101b67590f968bcf547046c9006168c18 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/2-\345\255\227\347\254\246\344\270\262\347\232\204CRUD\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/2-\345\255\227\347\254\246\344\270\262\347\232\204CRUD\347\273\203\344\271\240.py" @@ -1,81 +1,81 @@ -#创建(Create) -a = "a" -a = a + "b" -a -'ab' - - -a = "a" -a += "b" -a -'ab' - - -#索引(Retrieve) -a = "wang" -a[1] -'a' - -#.find() -a.find("e") --1 -a.find("w") -0 - - -#.index() -a.index("a") -1 -a.index("8") -Traceback (most recent call last): - File "", line 1, in -ValueError: substring not found - - -#starswith -f = "2020-12-26-xxx" -f.startswith("2020-12-26") -True - - -#endswith -a = "xxx.jpg" -a.endswith("jpg") -True - - -#更新(UPDATE) -a = "favorite, favoritt" -a.replace("itt", "ite") -'favorite, favorite' - - -#分割(split) -a = "<>, <>, <>" -a.split(",") -['<>', ' <>', ' <>'] - -#拼接(join) -b = a.split(",") -b -['<>', ' <>', ' <>'] -",".join(b) -'<>, <>, <>' - - -#删除(DELETE) -a = " world" -a -' world' -a.strip() -'world' - - -a = " ddddd " -a.lstrip() -'ddddd ' -a.rstrip() -' ddddd' -#用dir("")rhd 看方法 - - +#创建(Create) +a = "a" +a = a + "b" +a +'ab' + + +a = "a" +a += "b" +a +'ab' + + +#索引(Retrieve) +a = "wang" +a[1] +'a' + +#.find() +a.find("e") +-1 +a.find("w") +0 + + +#.index() +a.index("a") +1 +a.index("8") +Traceback (most recent call last): + File "", line 1, in +ValueError: substring not found + + +#starswith +f = "2020-12-26-xxx" +f.startswith("2020-12-26") +True + + +#endswith +a = "xxx.jpg" +a.endswith("jpg") +True + + +#更新(UPDATE) +a = "favorite, favoritt" +a.replace("itt", "ite") +'favorite, favorite' + + +#分割(split) +a = "<>, <>, <>" +a.split(",") +['<>', ' <>', ' <>'] + +#拼接(join) +b = a.split(",") +b +['<>', ' <>', ' <>'] +",".join(b) +'<>, <>, <>' + + +#删除(DELETE) +a = " world" +a +' world' +a.strip() +'world' + + +a = " ddddd " +a.lstrip() +'ddddd ' +a.rstrip() +' ddddd' +#用dir("")rhd 看方法 + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3-\345\260\206\342\200\234\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt\342\200\235\344\277\235\345\255\230\345\210\260\346\234\254\345\234\260\346\226\207\344\273\266.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3-\345\260\206\342\200\234\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt\342\200\235\344\277\235\345\255\230\345\210\260\346\234\254\345\234\260\346\226\207\344\273\266.py" index 05332078289e59e85a321b8c8388fdeec446c3ca..ea1fbd3626d6cdff6f1a4a7512a5e19d7bc1a7a0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3-\345\260\206\342\200\234\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt\342\200\235\344\277\235\345\255\230\345\210\260\346\234\254\345\234\260\346\226\207\344\273\266.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3-\345\260\206\342\200\234\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt\342\200\235\344\277\235\345\255\230\345\210\260\346\234\254\345\234\260\346\226\207\344\273\266.py" @@ -1,39 +1,39 @@ -output = open("字符串的格式化练习.txt", "w", encoding="utf-8") -content = """ -#format -a = "ping" -b = "pong" -print("play pingpong: {}, {}".format(a, b)) - - -#按指定的参数索引 -a = "ping" -b = "pong" -print("play pingpong: {0}, {1}, {1}".format(a, b)) - - -#按关键词参数索引 -a = "ping" -b = "pong" -print("play pingpong: {a}, {b}, {b}".format(a = "ping", b = "321")) - - -#按照变量 -a = "ping" -b = "pong" -print(f"playing pingpong: {a}, {b}") - - -#小数的表示{:.2f} -print("{:.2f}".format(3.45666)) - - -#% -"playing %s %s" % ("ping", "pong") -'playing ping pong' - -""" - -output.write(content) -output.close() - +output = open("字符串的格式化练习.txt", "w", encoding="utf-8") +content = """ +#format +a = "ping" +b = "pong" +print("play pingpong: {}, {}".format(a, b)) + + +#按指定的参数索引 +a = "ping" +b = "pong" +print("play pingpong: {0}, {1}, {1}".format(a, b)) + + +#按关键词参数索引 +a = "ping" +b = "pong" +print("play pingpong: {a}, {b}, {b}".format(a = "ping", b = "321")) + + +#按照变量 +a = "ping" +b = "pong" +print(f"playing pingpong: {a}, {b}") + + +#小数的表示{:.2f} +print("{:.2f}".format(3.45666)) + + +#% +"playing %s %s" % ("ping", "pong") +'playing ping pong' + +""" + +output.write(content) +output.close() + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\351\231\204\344\273\266\357\274\232\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\351\231\204\344\273\266\357\274\232\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt" index 661c8cc2e8634d45d04e20307977daf926cdf867..b67f07f0d6d4c1648be6cc976bedafed289e8084 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\351\231\204\344\273\266\357\274\232\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\351\231\204\344\273\266\357\274\232\345\255\227\347\254\246\344\270\262\347\232\204\346\240\274\345\274\217\345\214\226\347\273\203\344\271\240.txt" @@ -1,33 +1,33 @@ - -#format -a = "ping" -b = "pong" -print("play pingpong: {}, {}".format(a, b)) - - -#按指定的参数索引 -a = "ping" -b = "pong" -print("play pingpong: {0}, {1}, {1}".format(a, b)) - - -#按关键词参数索引 -a = "ping" -b = "pong" -print("play pingpong: {a}, {b}, {b}".format(a = "ping", b = "321")) - - -#按照变量 -a = "ping" -b = "pong" -print(f"playing pingpong: {a}, {b}") - - -#小数的表示{:.2f} -print("{:.2f}".format(3.45666)) - - -#% -"playing %s %s" % ("ping", "pong") -'playing ping pong' - + +#format +a = "ping" +b = "pong" +print("play pingpong: {}, {}".format(a, b)) + + +#按指定的参数索引 +a = "ping" +b = "pong" +print("play pingpong: {0}, {1}, {1}".format(a, b)) + + +#按关键词参数索引 +a = "ping" +b = "pong" +print("play pingpong: {a}, {b}, {b}".format(a = "ping", b = "321")) + + +#按照变量 +a = "ping" +b = "pong" +print(f"playing pingpong: {a}, {b}") + + +#小数的表示{:.2f} +print("{:.2f}".format(3.45666)) + + +#% +"playing %s %s" % ("ping", "pong") +'playing ping pong' + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/dict_crud\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/dict_crud\347\273\203\344\271\240.py" index 732f31ff0aab8cd99257d800e8862ecc10d22250..19f50281bd5a720b83da571d456aa643926b33e5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/dict_crud\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/dict_crud\347\273\203\344\271\240.py" @@ -1,62 +1,62 @@ -#dict - -#Create -#键对值赋值 -c = {} -c["a"] = 1 -print(c) - - -#update -t = {"c": 4, "b": 5} -c.update(t) -print(c) - - -#setdefault -c.setdefault("x", 4) -print(c) - - - - -#Retrieve -#键对值访问 -print(c["x"]) - - -#get -print(c.get("c")) - - -#keys() -print(c.keys()) -print(list(c.keys())) - - -#Values() -print(list(c.values())) - - -#items() -print(list(c.items())) - - -#Update -c["x"] = 55 -print(c) -c.update({"x": 45, "c": 88, "nn": 909}) -print(c) - - -#Delete -#pop -c.pop("x") -print(c) - - -#popitem() -c.popitem() -print(c) - - +#dict + +#Create +#键对值赋值 +c = {} +c["a"] = 1 +print(c) + + +#update +t = {"c": 4, "b": 5} +c.update(t) +print(c) + + +#setdefault +c.setdefault("x", 4) +print(c) + + + + +#Retrieve +#键对值访问 +print(c["x"]) + + +#get +print(c.get("c")) + + +#keys() +print(c.keys()) +print(list(c.keys())) + + +#Values() +print(list(c.values())) + + +#items() +print(list(c.items())) + + +#Update +c["x"] = 55 +print(c) +c.update({"x": 45, "c": 88, "nn": 909}) +print(c) + + +#Delete +#pop +c.pop("x") +print(c) + + +#popitem() +c.popitem() +print(c) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/list_crud\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/list_crud\347\273\203\344\271\240.py" index 8c9d3a8cfcc1599ddc50c5f233b6d5fc465c8d63..c305c0a860488f266d3ad8b5a769f5eaef829808 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/list_crud\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/list_crud\347\273\203\344\271\240.py" @@ -1,89 +1,89 @@ -#list -#cteate -list_1 = ["ddd"] -list_1.append("adsd") -print(list_1) - - -#+和+= -l_1 = ["a"] -l_2 = ["b"] -l_3 = l_1 + l_2 -print(l_3) -l_3 += ["333"] -print(l_3) - - -#* -l_4 = ["444"] * 3 -print(l_4) - - -#insert -name = ["333"] -name.insert(0, "444") -print(name) - - -#Retrieve -name1 = ["qq", "ww"] -print(name1[1]) - - -#切片 -l = list(range(100)) -print(l[0:10]) -print(l[20:30]) -print(l[0:-1]) -print(l[-1]) -print(l[20:0]) -print(l[1:45:3]) - - -#index -m = ["qq", "ee"] -print(m.index("ee")) -m.insert(m.index("ee"), "dd") -print(m) - - -#Update -#索引赋值 -m[0] = "aa" -print(m) - - -#切片赋值 -l4 = list(range(50)) -l4[0:8] = "d" -print(l4) - - -#pop -m_2 = list(range(30)) -print(m_2.pop()) - - -#clear -m_2.clear() -print(m_2) - - -#SORT -l_0 = [1, 5, 3, 2] -l_0.sort() -print(l_0) - - -#sorted -l_88 = [5, 4, 3, 2] -print(sorted(l_88)) - - -#reverse -l_88.reverse() -print(l_88) - - -#reversed +#list +#cteate +list_1 = ["ddd"] +list_1.append("adsd") +print(list_1) + + +#+和+= +l_1 = ["a"] +l_2 = ["b"] +l_3 = l_1 + l_2 +print(l_3) +l_3 += ["333"] +print(l_3) + + +#* +l_4 = ["444"] * 3 +print(l_4) + + +#insert +name = ["333"] +name.insert(0, "444") +print(name) + + +#Retrieve +name1 = ["qq", "ww"] +print(name1[1]) + + +#切片 +l = list(range(100)) +print(l[0:10]) +print(l[20:30]) +print(l[0:-1]) +print(l[-1]) +print(l[20:0]) +print(l[1:45:3]) + + +#index +m = ["qq", "ee"] +print(m.index("ee")) +m.insert(m.index("ee"), "dd") +print(m) + + +#Update +#索引赋值 +m[0] = "aa" +print(m) + + +#切片赋值 +l4 = list(range(50)) +l4[0:8] = "d" +print(l4) + + +#pop +m_2 = list(range(30)) +print(m_2.pop()) + + +#clear +m_2.clear() +print(m_2) + + +#SORT +l_0 = [1, 5, 3, 2] +l_0.sort() +print(l_0) + + +#sorted +l_88 = [5, 4, 3, 2] +print(sorted(l_88)) + + +#reverse +l_88.reverse() +print(l_88) + + +#reversed print(list(reversed(l_88))) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/set_crud\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/set_crud\347\273\203\344\271\240.py" index 6842606d411fdda16e149f6132a2db5dd4f18e07..e681d6b9acb30fed381a1712b5612d548df70ee1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/set_crud\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/set_crud\347\273\203\344\271\240.py" @@ -1,49 +1,49 @@ -#set -#Create -#add -s = set() -s.add("b") -print(s) - -#dir(s)查看函数 - - -#Retrieve -"b" in s -True - - -#Update -s.update("b", "d") -print(s) - - -#union -m = {"s"} -n = {"d"} -m.union(n) -{'s', 'd'} -m.union("tttt") -{'t', 's'} -m.union({"tttt"}) -{'s', 'tttt'} - - -dd = {"q", "e", "p"} -print(s.union({"dd"})) - - -#delete -#remove -dd.remove("q") -print(dd) - - -#discard -dd.discard("e") -print(dd) - - -#pop -dd.pop() +#set +#Create +#add +s = set() +s.add("b") +print(s) + +#dir(s)查看函数 + + +#Retrieve +"b" in s +True + + +#Update +s.update("b", "d") +print(s) + + +#union +m = {"s"} +n = {"d"} +m.union(n) +{'s', 'd'} +m.union("tttt") +{'t', 's'} +m.union({"tttt"}) +{'s', 'tttt'} + + +dd = {"q", "e", "p"} +print(s.union({"dd"})) + + +#delete +#remove +dd.remove("q") +print(dd) + + +#discard +dd.discard("e") +print(dd) + + +#pop +dd.pop() print(dd) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/tuple_Retrievea\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/tuple_Retrievea\347\273\203\344\271\240.py" index e9f3f4ebadc8adb20878287d288168308e947bef..f55b24850fcdc368691f8985dbf677e956480bb9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/tuple_Retrievea\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2542\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/tuple_Retrievea\347\273\203\344\271\240.py" @@ -1,20 +1,20 @@ -#tuple -#Create无 -#Retrieve -name1 = (1, 2, 4, 9, 4, 3, 5) - - -#索引取值 -print(name1[0]) - - -#index -print(name1.index(2)) - - -#切片 -print(name1[1:4]) - - -#Update无 +#tuple +#Create无 +#Retrieve +name1 = (1, 2, 4, 9, 4, 3, 5) + + +#索引取值 +print(name1[0]) + + +#index +print(name1.index(2)) + + +#切片 +print(name1[1:4]) + + +#Update无 #Delete无 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/1.\347\224\250for\345\222\214while\350\256\241\346\225\260\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/1.\347\224\250for\345\222\214while\350\256\241\346\225\260\347\273\203\344\271\240.py" index 2a691f0f20c90f51bc4a79469b30001447f887a1..0b8d5e3cfb64257b0c40cf2101f93a6947e23d74 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/1.\347\224\250for\345\222\214while\350\256\241\346\225\260\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/1.\347\224\250for\345\222\214while\350\256\241\346\225\260\347\273\203\344\271\240.py" @@ -1,14 +1,14 @@ -#用for计数 -squares = [] -for counter in range(13): - if counter == 10: - break - squares.append(counter **2) -print(squares) - - -#用while计数 -nn = 1 -while nn <= 5: - print(nn) +#用for计数 +squares = [] +for counter in range(13): + if counter == 10: + break + squares.append(counter **2) +print(squares) + + +#用while计数 +nn = 1 +while nn <= 5: + print(nn) nn += 1 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2.\350\217\262\346\263\242\351\202\243\345\210\207\346\225\260\345\210\227.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2.\350\217\262\346\263\242\351\202\243\345\210\207\346\225\260\345\210\227.py" index 5e63473d14f1d54e1c0258e348f209fb66a0b8c4..faf3fd12a44d1700a8348cb62214c2ab9832c7da 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2.\350\217\262\346\263\242\351\202\243\345\210\207\346\225\260\345\210\227.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/2.\350\217\262\346\263\242\351\202\243\345\210\207\346\225\260\345\210\227.py" @@ -1,8 +1,8 @@ -feibo = [0, 1] -while True: - if feibo[-1] >= 100: - del feibo[-1] - break - mm = feibo[-2] + feibo[-1] - feibo.append(mm) +feibo = [0, 1] +while True: + if feibo[-1] >= 100: + del feibo[-1] + break + mm = feibo[-2] + feibo[-1] + feibo.append(mm) print(feibo) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/3.\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270ParamsError.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/3.\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270ParamsError.py" index 1d3c85c3573633beb9cc3b4e72adffd2b50597ef..ffb560c9ec3a332242e9144d2e5d85b5e950d809 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/3.\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270ParamsError.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/3.\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270ParamsError.py" @@ -1,12 +1,12 @@ -class ParamsError(Exception): - pass - -def sub(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("sub end") - +class ParamsError(Exception): + pass + +def sub(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("sub end") + sub(3, 0) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3\344\270\252\344\275\234\344\270\232\351\203\275\345\234\250\351\207\214\351\235\242.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3\344\270\252\344\275\234\344\270\232\351\203\275\345\234\250\351\207\214\351\235\242.py" index abbe48be3cc873b21b7d0ddb8718ffaab0f6d07e..8b27e6300ae55e1dc244013ce7fb8d4a112fa324 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3\344\270\252\344\275\234\344\270\232\351\203\275\345\234\250\351\207\214\351\235\242.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/3\344\270\252\344\275\234\344\270\232\351\203\275\345\234\250\351\207\214\351\235\242.py" @@ -1,37 +1,37 @@ -from pprint import pprint -classes = [ - {"name": "name_1", "age": 25, "grade": "A"}, - {"name": "name_2", "age": 3, "grade": "C"}, - {"name": "name_4", "age": 15, "grade": "B"}, - {"name": "name_3", "age": 14, "grade": "D"}, - {"name": "name_5", "age": 13, "grade": "B"}, - {"name": "name_6", "age": 4, "grade": "B"}, - {"name": "name_7", "age": 5, "grade": "A"}, - {"name": "name_8", "age": 88, "grade": "D"}, -] - -#通过filter语句来筛选出Grade为A的同学 -f = filter(lambda x: x.get("grade") == "A", classes) -print("grade为A的同学有:") -pprint(list(f)) - - -#通过map函数将上述同学的age + 1(对原数据结构有影响,尽量不要用lambda) -def add(d): - d["age"] += 1 - -m = map(add, classes) -list(m) -print("改变年龄之后:") -pprint(classes) - - -#使用递归函数重构菲波那切函数 -def fibo(n): - if n <= 1: - return n - else: - return fibo(n - 1) + fibo(n - 2) -for mm in range(1, 20): - print(fibo(mm), end=",") - +from pprint import pprint +classes = [ + {"name": "name_1", "age": 25, "grade": "A"}, + {"name": "name_2", "age": 3, "grade": "C"}, + {"name": "name_4", "age": 15, "grade": "B"}, + {"name": "name_3", "age": 14, "grade": "D"}, + {"name": "name_5", "age": 13, "grade": "B"}, + {"name": "name_6", "age": 4, "grade": "B"}, + {"name": "name_7", "age": 5, "grade": "A"}, + {"name": "name_8", "age": 88, "grade": "D"}, +] + +#通过filter语句来筛选出Grade为A的同学 +f = filter(lambda x: x.get("grade") == "A", classes) +print("grade为A的同学有:") +pprint(list(f)) + + +#通过map函数将上述同学的age + 1(对原数据结构有影响,尽量不要用lambda) +def add(d): + d["age"] += 1 + +m = map(add, classes) +list(m) +print("改变年龄之后:") +pprint(classes) + + +#使用递归函数重构菲波那切函数 +def fibo(n): + if n <= 1: + return n + else: + return fibo(n - 1) + fibo(n - 2) +for mm in range(1, 20): + print(fibo(mm), end=",") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/1_\347\273\203\344\271\240\344\275\234\347\224\250\345\237\237\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/1_\347\273\203\344\271\240\344\275\234\347\224\250\345\237\237\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" index f03508cae850bda81cec83bcb99ad1def4a9df85..fe95c939e966e8fb26706c8fbb071b4685bdf904 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/1_\347\273\203\344\271\240\344\275\234\347\224\250\345\237\237\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/1_\347\273\203\344\271\240\344\275\234\347\224\250\345\237\237\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" @@ -1,43 +1,43 @@ -#将局部变量变成全局变量,用global关键字 -a = 1 -def foo(): - global a - a = 2 - print(a) -foo() -print(a) - - -#将局部变量变成自由变量,用nonlocal关键字 -def make_averager(): - total = 0 - count = 0 - def averager(value): - nonlocal total, count - total += value - count +=1 - return total / count - return averager - -my_avg = make_averager() -print(my_avg(1)) -print(my_avg(2)) -print(my_avg(3)) -print(my_avg(4)) - - -#局部变量定义优先 -a = 1 -b = [] -def foo(): - a = 2 - b.append(2) - #b = 3 先执行定义的b = 3# - return None -foo() -print(a) -print(b) - - - - +#将局部变量变成全局变量,用global关键字 +a = 1 +def foo(): + global a + a = 2 + print(a) +foo() +print(a) + + +#将局部变量变成自由变量,用nonlocal关键字 +def make_averager(): + total = 0 + count = 0 + def averager(value): + nonlocal total, count + total += value + count +=1 + return total / count + return averager + +my_avg = make_averager() +print(my_avg(1)) +print(my_avg(2)) +print(my_avg(3)) +print(my_avg(4)) + + +#局部变量定义优先 +a = 1 +b = [] +def foo(): + a = 2 + b.append(2) + #b = 3 先执行定义的b = 3# + return None +foo() +print(a) +print(b) + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/2_\350\243\205\351\245\260\345\231\250\357\274\210\345\256\236\347\216\260\345\207\275\346\225\260\346\211\247\350\241\214\346\227\266\351\227\264\357\274\211.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/2_\350\243\205\351\245\260\345\231\250\357\274\210\345\256\236\347\216\260\345\207\275\346\225\260\346\211\247\350\241\214\346\227\266\351\227\264\357\274\211.py" index 7a55547cfe3c3f54d7b1568533709327915fbdd7..0588f5ebbfbe2174d8095e6355118b71c050565d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/2_\350\243\205\351\245\260\345\231\250\357\274\210\345\256\236\347\216\260\345\207\275\346\225\260\346\211\247\350\241\214\346\227\266\351\227\264\357\274\211.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/2_\350\243\205\351\245\260\345\231\250\357\274\210\345\256\236\347\216\260\345\207\275\346\225\260\346\211\247\350\241\214\346\227\266\351\227\264\357\274\211.py" @@ -1,23 +1,23 @@ -import time - - -def clock_it_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - return wrapper - - -@clock_it_deco -def foo_1(a, b): - count = 1 - while True: - if count > a ** b: - break - count +=1 - -#foo = clock_it_deco(foo) +import time + + +def clock_it_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + return wrapper + + +@clock_it_deco +def foo_1(a, b): + count = 1 + while True: + if count > a ** b: + break + count +=1 + +#foo = clock_it_deco(foo) foo_1(10, 5) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/3_\344\275\277\347\224\250\350\243\205\351\245\260\345\231\250\344\270\272\346\226\220\346\263\242\347\272\263\345\245\221\345\207\275\346\225\260\346\267\273\345\212\240\347\274\223\345\255\230.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/3_\344\275\277\347\224\250\350\243\205\351\245\260\345\231\250\344\270\272\346\226\220\346\263\242\347\272\263\345\245\221\345\207\275\346\225\260\346\267\273\345\212\240\347\274\223\345\255\230.py" index ab84731aab69fe11461500c35ca776339646f096..ea8e6e9652f4e294011b7938a1a678bb13e0fb80 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/3_\344\275\277\347\224\250\350\243\205\351\245\260\345\231\250\344\270\272\346\226\220\346\263\242\347\272\263\345\245\221\345\207\275\346\225\260\346\267\273\345\212\240\347\274\223\345\255\230.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2543\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/3_\344\275\277\347\224\250\350\243\205\351\245\260\345\231\250\344\270\272\346\226\220\346\263\242\347\272\263\345\245\221\345\207\275\346\225\260\346\267\273\345\212\240\347\274\223\345\255\230.py" @@ -1,18 +1,18 @@ -a = {} -def cache_deco(func): - global a - def wrapper(n): - if n not in a: - a[n] = func(n) - return a[n] - return wrapper - -@ cache_deco -def fibo(n): - if n < 2: - return n - else: - return fibo(n - 2) + fibo(n - 1) - -print(fibo(10)) +a = {} +def cache_deco(func): + global a + def wrapper(n): + if n not in a: + a[n] = func(n) + return a[n] + return wrapper + +@ cache_deco +def fibo(n): + if n < 2: + return n + else: + return fibo(n - 2) + fibo(n - 1) + +print(fibo(10)) print(a) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\344\270\200\344\270\252\345\207\275\346\225\260\357\274\214\344\275\234\345\207\272\350\277\220\347\256\227.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\344\270\200\344\270\252\345\207\275\346\225\260\357\274\214\344\275\234\345\207\272\350\277\220\347\256\227.py" index b368294fc0e80be332771d54bbf7b1cab381f1ce..d97e44e70786b659ca54b3d84d4bae3480f941d4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\344\270\200\344\270\252\345\207\275\346\225\260\357\274\214\344\275\234\345\207\272\350\277\220\347\256\227.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\344\270\200\344\270\252\345\207\275\346\225\260\357\274\214\344\275\234\345\207\272\350\277\220\347\256\227.py" @@ -1,23 +1,23 @@ -import time -import datetime -from datetime import timedelta - - -def my_datetime_exercise(): - now = datetime.datetime.now(tz=None) - my_timestamp = now.timestamp() # 时间戳 - print(my_timestamp) - my_timestamp_to_datetime = datetime.datetime.fromtimestamp(my_timestamp, tz=None) - print(type(my_timestamp_to_datetime)) - my_datetime_to_str = now.strftime("%Y-%m-%d %H:%M:%S") # 转换成字符串 - print(my_datetime_to_str) - my_str_to_datetime = datetime.datetime.strptime(my_datetime_to_str, "%Y-%m-%d %H:%M:%S") - print(type(my_str_to_datetime)) # 转换成Datetime 格式 - - -# 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期 -def get_date(day_delta): - now_time = datetime.datetime.now(tz=None) - my_result = now_time+timedelta(days=day_delta) - my_today_date = my_result.strftime("%Y-%m-%d") - print(my_today_date) +import time +import datetime +from datetime import timedelta + + +def my_datetime_exercise(): + now = datetime.datetime.now(tz=None) + my_timestamp = now.timestamp() # 时间戳 + print(my_timestamp) + my_timestamp_to_datetime = datetime.datetime.fromtimestamp(my_timestamp, tz=None) + print(type(my_timestamp_to_datetime)) + my_datetime_to_str = now.strftime("%Y-%m-%d %H:%M:%S") # 转换成字符串 + print(my_datetime_to_str) + my_str_to_datetime = datetime.datetime.strptime(my_datetime_to_str, "%Y-%m-%d %H:%M:%S") + print(type(my_str_to_datetime)) # 转换成Datetime 格式 + + +# 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期 +def get_date(day_delta): + now_time = datetime.datetime.now(tz=None) + my_result = now_time+timedelta(days=day_delta) + my_today_date = my_result.strftime("%Y-%m-%d") + print(my_today_date) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\2643\344\270\252\346\240\274\345\274\217\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\2643\344\270\252\346\240\274\345\274\217\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" index e6e2fc2203e4c1ab9b7d84b2475dae66d24f1958..5d19aba486e12df93c5ffd8c5ea9aca50e843523 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\2643\344\270\252\346\240\274\345\274\217\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\2643\344\270\252\346\240\274\345\274\217\344\271\213\351\227\264\347\232\204\350\275\254\346\215\242.py" @@ -1,15 +1,15 @@ -import time -import datetime -#通过datetime模块完成时间戳、datetime对象、格式化字符串三者之间的转换 -now = print(time.time()) -1609869221.6649473 - -now = datetime.datetime.now(tz=None) -now -datetime.datetime(2021, 1, 6, 1, 45, 53, 767724) - -print(now.strftime("%Y-%m-%d %H:%M:%S")) -2021-01-06 01:45:53 - -now.timestamp() +import time +import datetime +#通过datetime模块完成时间戳、datetime对象、格式化字符串三者之间的转换 +now = print(time.time()) +1609869221.6649473 + +now = datetime.datetime.now(tz=None) +now +datetime.datetime(2021, 1, 6, 1, 45, 53, 767724) + +print(now.strftime("%Y-%m-%d %H:%M:%S")) +2021-01-06 01:45:53 + +now.timestamp() 1609868753.767724 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\347\261\273\345\217\212\345\210\233\345\273\272\347\261\273\347\232\204\345\256\236\344\276\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\347\261\273\345\217\212\345\210\233\345\273\272\347\261\273\347\232\204\345\256\236\344\276\213.py" index 2fd490ce5a3a9dfbf24a23bf54b1d415023531dc..3f656f48a1f79447cadedb9ea90a8180b7ffa0e4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\347\261\273\345\217\212\345\210\233\345\273\272\347\261\273\347\232\204\345\256\236\344\276\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\345\260\201\350\243\205\347\261\273\345\217\212\345\210\233\345\273\272\347\261\273\347\232\204\345\256\236\344\276\213.py" @@ -1,40 +1,40 @@ -#用类封装一个MyMath类 -class MyMath: - def add(self, a, b): - return a + b - - def sub(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - return a / b - - def ediv(self, a, b): - return a // b - - def rem(self, a, b): - return a % b - - def sqrt(self, a, b): - return float(a ** (1 / 2)) -a = MyMath() -a. add(5, 6) - -#定义类 -class Dog: - def __init__(self, name, age): - self.name = name - self.age = age - - def sit(self): - print(f"{self.name} is now sitting.") - - def roll(self): - print(f"{self.name} rolled ouer!") - -my_dog = Dog("Tom", 8) -print(f"My dog's name is {my_dog.name}.") -print(f"My dog is {my_dog.age} years old.") +#用类封装一个MyMath类 +class MyMath: + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def ediv(self, a, b): + return a // b + + def rem(self, a, b): + return a % b + + def sqrt(self, a, b): + return float(a ** (1 / 2)) +a = MyMath() +a. add(5, 6) + +#定义类 +class Dog: + def __init__(self, name, age): + self.name = name + self.age = age + + def sit(self): + print(f"{self.name} is now sitting.") + + def roll(self): + print(f"{self.name} rolled ouer!") + +my_dog = Dog("Tom", 8) +print(f"My dog's name is {my_dog.name}.") +print(f"My dog is {my_dog.age} years old.") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/0125.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/0125.py" index 06e3e47c8124783247d884587a80f202acdf210e..0e62d71e1c11a8b56e5ac1cd0055c73d17f3a4d7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/0125.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2544\345\221\250\347\254\2543\350\257\276\344\275\234\344\270\232/0125.py" @@ -1,48 +1,48 @@ -#第一问 -class MyMath: - @staticmethod - def add(a, b): - return a + b - - def sub(a, b): - return a - b - - def mul(a, b): - return a * b - - def div(a, b): - return a / b - - def ediv(a, b): - return a // b - - def rem(a, b): - return a % b - - def sqrt(a, b): - return float(a ** (1 / 2)) -print(MyMath.add(10,5)) - -#第二问 -class Dog: - cute_dog = True - __mydog = {"mm": 3} - def __init__(self, name, age): - self.name = name - self.age = age - - @classmethod - def sit(self): - print(f"{self.name} is now sitting.") - - def roll(self): - print(f"{self.name} rolled ouer!") - -print(Dog._Dog__mydog) -tole = Dog("加菲",40) -print(tole) - - - - - +#第一问 +class MyMath: + @staticmethod + def add(a, b): + return a + b + + def sub(a, b): + return a - b + + def mul(a, b): + return a * b + + def div(a, b): + return a / b + + def ediv(a, b): + return a // b + + def rem(a, b): + return a % b + + def sqrt(a, b): + return float(a ** (1 / 2)) +print(MyMath.add(10,5)) + +#第二问 +class Dog: + cute_dog = True + __mydog = {"mm": 3} + def __init__(self, name, age): + self.name = name + self.age = age + + @classmethod + def sit(self): + print(f"{self.name} is now sitting.") + + def roll(self): + print(f"{self.name} rolled ouer!") + +print(Dog._Dog__mydog) +tole = Dog("加菲",40) +print(tole) + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232.md" index 43c1bea2c8565d457abc224f2c3bab6a87c98295..f7c9c956c25991e385ffe04ec02a9032244dfe41 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2541\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232.md" @@ -1,31 +1,31 @@ -# 第一问: - -第一,浏览器连接DNS服务器,向url服务器请求把url转换为IP地址 -第二,DNS服务器返回url的IP地址 -第三,浏览器建立一个TCP链接到web服务器80端口 -第四,web服务器发回html代码 -第五,浏览器的渲染器根据html代码将内容呈现到窗口上 -第六,当窗口关闭的时候浏览器关闭连接 - -# 第二问: - -第一,应用层 -休系结构中最高的一层。直接为用户的应用进程提供服务。 -比如,电子邮件,文件传输和终端仿真 - -第二,运输层 -负责向两个主机中进程之间的通信提供服务。一个主机可以开启不同的应用,同不同的服务器之间进行通信,但是都是共用一个传输服务来发送和接受信息。 -TCP和UDP,前者是提供面向连接,能够保证数据的可靠性。后者提供无连接,数据可靠性无法保证。 -TCP出现于文件传输,浏览网页 -UDP出现于直播,实况游戏 - -第三,网络层 -主要负责为分组交换网上的不同主机提供通信服务。在发送数据时,网络层把运输层产生的报文段或数据封装成分组或包进行传送。 -再选中一个合适的路由,使一个主机运输层传下来的分组,能够通过网络中的路由器找到需要到达的目的主机。 -协议:IP,IGMP,ICMP - -第四,数据链接层 -在两个相邻的结点间传送数据时,数据链路层将网络层传下来的IP数据组装成帧,在两个相邻结点之间的链路上传送帧中的数据。 - -第五,物理层 +# 第一问: + +第一,浏览器连接DNS服务器,向url服务器请求把url转换为IP地址 +第二,DNS服务器返回url的IP地址 +第三,浏览器建立一个TCP链接到web服务器80端口 +第四,web服务器发回html代码 +第五,浏览器的渲染器根据html代码将内容呈现到窗口上 +第六,当窗口关闭的时候浏览器关闭连接 + +# 第二问: + +第一,应用层 +休系结构中最高的一层。直接为用户的应用进程提供服务。 +比如,电子邮件,文件传输和终端仿真 + +第二,运输层 +负责向两个主机中进程之间的通信提供服务。一个主机可以开启不同的应用,同不同的服务器之间进行通信,但是都是共用一个传输服务来发送和接受信息。 +TCP和UDP,前者是提供面向连接,能够保证数据的可靠性。后者提供无连接,数据可靠性无法保证。 +TCP出现于文件传输,浏览网页 +UDP出现于直播,实况游戏 + +第三,网络层 +主要负责为分组交换网上的不同主机提供通信服务。在发送数据时,网络层把运输层产生的报文段或数据封装成分组或包进行传送。 +再选中一个合适的路由,使一个主机运输层传下来的分组,能够通过网络中的路由器找到需要到达的目的主机。 +协议:IP,IGMP,ICMP + +第四,数据链接层 +在两个相邻的结点间传送数据时,数据链路层将网络层传下来的IP数据组装成帧,在两个相邻结点之间的链路上传送帧中的数据。 + +第五,物理层 在局部局域网中传送数据帧,在相邻两个节点间透明地传送比特流,传输数据单位是比特。 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232.md" index 8f3402b14e878071ba4a197383d6758e172569e6..d82cdd5368d6fdc0893b918c3fdebe4f45cd21ce 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\344\277\212\347\204\272/\347\254\2546\345\221\250\347\254\2542\350\257\276\344\275\234\344\270\232/\347\254\254\345\205\255\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232.md" @@ -1,21 +1,21 @@ -## 第一问 - -第一步:客户端向服务端发送带有SYN(同步序列编号)标识的数据包 -第二步:服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包 -第三步:客户端向服务端返回带有ACK标识的数据包 - -## 第二问 - -第一步:客户端向服务端发送了一个FIN(finish)数据包 -第二步:服务器收到了FIN后,返回了ACK数据包 -第三步:服务端发送FIN数据包至客户端,关闭与客户端的连接 -第四步:客户端返回ACK数据包确认 - -## 第三问 - -第一步:客户端向服务端发送通信请求 -第二步:服务端返回给客户端证书和密钥 -第三步:客户端通过CA中心验证证书的真实性 -第四步:客户端完成认证之后,使用公钥对发送数据进行加密,发送给服务端 -第五步:服务端收到加密后的请求数据后,使用私钥进行解密 +## 第一问 + +第一步:客户端向服务端发送带有SYN(同步序列编号)标识的数据包 +第二步:服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包 +第三步:客户端向服务端返回带有ACK标识的数据包 + +## 第二问 + +第一步:客户端向服务端发送了一个FIN(finish)数据包 +第二步:服务器收到了FIN后,返回了ACK数据包 +第三步:服务端发送FIN数据包至客户端,关闭与客户端的连接 +第四步:客户端返回ACK数据包确认 + +## 第三问 + +第一步:客户端向服务端发送通信请求 +第二步:服务端返回给客户端证书和密钥 +第三步:客户端通过CA中心验证证书的真实性 +第四步:客户端完成认证之后,使用公钥对发送数据进行加密,发送给服务端 +第五步:服务端收到加密后的请求数据后,使用私钥进行解密 第六步:服务器和客户端使用对称加密进行通信 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/shili.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/shili.py" index 96110eff67f571cca2039dc14100bec5b5577728..f805d0463c3f3885f99fa381e05f574f34e44a34 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/shili.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/shili.py" @@ -1,12 +1,12 @@ -a = 1 -b = 2.0 -c = ('3') -d = True -e = False -f = None -list = (a,b,c,d,e,f) -tuple = (a,b,c,d,e,f) -set = {a,b,c,d,e,f} -print(list) -print(tuple) +a = 1 +b = 2.0 +c = ('3') +d = True +e = False +f = None +list = (a,b,c,d,e,f) +tuple = (a,b,c,d,e,f) +set = {a,b,c,d,e,f} +print(list) +print(tuple) print(set) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/notebook.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/notebook.md" index 66b42e450d70cdb12d7bb98263094a18aad81e79..0adc7117ddfad95382a17ec6c9f231fe81cd5d80 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/notebook.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/notebook.md" @@ -1,259 +1,259 @@ -# 第一周_第三节课 - -## 变量和赋值 - -- 什么是变量 - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可变化的 可重新赋值 - -- 为变量赋值 - - - 通过 = 来赋值 - - ``` - x = 3 - ``` - - - 被重新赋值之后的值去哪儿了 - - - 被系统回收了 - -- python的常量 - - - python没有常量这个数据类型 - - 程序员之间的约定,如果这个命名都是大写字母,那么就视为一个常量 - -## python的六大基本类型 - -``` -*强调基本的原因 数据类型和数据结构指向的范围更广泛(像堆,栈,树),不要产生错误的认知,形成思维定式 -``` - -- 通过type函数来查看当前变量的数据类型 - -- **int(整数)** - - ``` - int("1") - ``` - -- **float(浮点数** - - ``` - float("1.0") - ``` - - - 因为计算机只认识0和1,所以浮点数强调的是小数的表现形式 - - - 表现无限 - - ``` - float("INF") - ``` - - - -- **string(字符串,字符序列)** - - ``` - str() #转换数据类型 - ``` - - - 在有些语言中,单个字符也是一个基本的数据类型(char),python中没有 - - - 有序的 - - - 如何表示字符串 - - - ``` - '' - ``` - - - ``` - "" - ``` - - - ``` - '''''' - ``` - - - ``` - """""" - ``` - - - 转义字符 - - - 告诉python解释器 我们当前表示的是一个字符或者是特殊字符 - - - 通过\来转义 \n 换行 - - ``` - "2\"" - "2\n3" - ``` - -- **boolean(布尔值)** - - 用来表示True 或者 False - - - ``` - True = 1 - True - False == 0 - True - ``` - - - true 等价于 1 False 等价于 0 - -- **bytes(二进制序列)** - - - 二进制表现形式 - -- **None(空) #比较重要,后面应用很多** - - - 有了False和0为什么还要有None - - 因为False和0有时候也代表了一种结果 - -## python的四大基本数据结构 - -- **list(列表)** - - - 什么是列表 - - 用来装载不同数据类型的数集结构 - - - 列表的特点 - - - 有序的 - - 可以装载任意数据类型 - - - 如何让表示list - - - 通过list()新建一个列表 - - - 通过[]声明一个列表 - - ``` - list() - [] - a = [1,2,3] - type(a) - - ``` - -- **tuple(元组)** - - - 什么是元组 - - 简单地认为,元组是不可修改得列表,常用来表示记录 - - - 元组的特点 - - - 有序的 - - 可以装载任意数据;类型 - - 不可修改 - - - 如何表示tuple - - - 通过tuple()新建一个元组 - - - 通过(,)来声明一个元组 - - ``` - tuple("hallo") - ('h', 'a', 'l', 'l', 'o') - - a = (1,2) - a - (1, 2) - - type(a) - - ``` - - - 声明单个元素的元组,要添加逗号 - - ``` - a = (1,) - a - (1,) - type(a) - - ``` - - - -- **dict(字典)** - - - 什么是字典 - - 字典也叫hashtable ,通过hash(散列)函数将传入的key值生成地址来查找value - - key -> hash 函数 -> 返回了value的地址 -> 通过地址返回value值 - - - 字典的特点 - - - 无序的 #python3.6是有序的,无视这一点 - - 字典中的key 必须是可哈希的 - - 其本身是可以更改的 - - - 如何表示字典 - - - 通过dict()函数来创建字典 - - - 通过{}来声明一个字典 - - ``` - dict() - {} - - a = {"a":1} - type(a) - - ``` - - - -- **set(集合)** - - - 什么是set - - - 其实是没有value的字典 - - - 集合的特点 - - - 无序的 - - 集合中的key必须是可hash的 - - 元素是唯一的 - - - 如何表示set - - - 通过set()函数来创建集合 - - - 通过{}来声明一个集合 - - ``` - set({1,2}) - {1, 2} - - a = {"a",1} - type(a) - - ``` - -- **课后作业** - - - 四大基本数据结构中哪些是可变的,哪些是不可变的 - - 可变的 list dict 不可变的 tuple set - - 四大基本数据结构中哪些是有序的,哪些是无序的 - - 有序的 list tupple 无序的 dict set +# 第一周_第三节课 + +## 变量和赋值 + +- 什么是变量 + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可变化的 可重新赋值 + +- 为变量赋值 + + - 通过 = 来赋值 + + ``` + x = 3 + ``` + + - 被重新赋值之后的值去哪儿了 + + - 被系统回收了 + +- python的常量 + + - python没有常量这个数据类型 + - 程序员之间的约定,如果这个命名都是大写字母,那么就视为一个常量 + +## python的六大基本类型 + +``` +*强调基本的原因 数据类型和数据结构指向的范围更广泛(像堆,栈,树),不要产生错误的认知,形成思维定式 +``` + +- 通过type函数来查看当前变量的数据类型 + +- **int(整数)** + + ``` + int("1") + ``` + +- **float(浮点数** + + ``` + float("1.0") + ``` + + - 因为计算机只认识0和1,所以浮点数强调的是小数的表现形式 + + - 表现无限 + + ``` + float("INF") + ``` + + + +- **string(字符串,字符序列)** + + ``` + str() #转换数据类型 + ``` + + - 在有些语言中,单个字符也是一个基本的数据类型(char),python中没有 + + - 有序的 + + - 如何表示字符串 + + - ``` + '' + ``` + + - ``` + "" + ``` + + - ``` + '''''' + ``` + + - ``` + """""" + ``` + + - 转义字符 + + - 告诉python解释器 我们当前表示的是一个字符或者是特殊字符 + + - 通过\来转义 \n 换行 + + ``` + "2\"" + "2\n3" + ``` + +- **boolean(布尔值)** + + 用来表示True 或者 False + + - ``` + True = 1 + True + False == 0 + True + ``` + + - true 等价于 1 False 等价于 0 + +- **bytes(二进制序列)** + + - 二进制表现形式 + +- **None(空) #比较重要,后面应用很多** + + - 有了False和0为什么还要有None + + 因为False和0有时候也代表了一种结果 + +## python的四大基本数据结构 + +- **list(列表)** + + - 什么是列表 + + 用来装载不同数据类型的数集结构 + + - 列表的特点 + + - 有序的 + - 可以装载任意数据类型 + + - 如何让表示list + + - 通过list()新建一个列表 + + - 通过[]声明一个列表 + + ``` + list() + [] + a = [1,2,3] + type(a) + + ``` + +- **tuple(元组)** + + - 什么是元组 + + 简单地认为,元组是不可修改得列表,常用来表示记录 + + - 元组的特点 + + - 有序的 + - 可以装载任意数据;类型 + - 不可修改 + + - 如何表示tuple + + - 通过tuple()新建一个元组 + + - 通过(,)来声明一个元组 + + ``` + tuple("hallo") + ('h', 'a', 'l', 'l', 'o') + + a = (1,2) + a + (1, 2) + + type(a) + + ``` + + - 声明单个元素的元组,要添加逗号 + + ``` + a = (1,) + a + (1,) + type(a) + + ``` + + + +- **dict(字典)** + + - 什么是字典 + + 字典也叫hashtable ,通过hash(散列)函数将传入的key值生成地址来查找value + + key -> hash 函数 -> 返回了value的地址 -> 通过地址返回value值 + + - 字典的特点 + + - 无序的 #python3.6是有序的,无视这一点 + - 字典中的key 必须是可哈希的 + - 其本身是可以更改的 + + - 如何表示字典 + + - 通过dict()函数来创建字典 + + - 通过{}来声明一个字典 + + ``` + dict() + {} + + a = {"a":1} + type(a) + + ``` + + + +- **set(集合)** + + - 什么是set + + - 其实是没有value的字典 + + - 集合的特点 + + - 无序的 + - 集合中的key必须是可hash的 + - 元素是唯一的 + + - 如何表示set + + - 通过set()函数来创建集合 + + - 通过{}来声明一个集合 + + ``` + set({1,2}) + {1, 2} + + a = {"a",1} + type(a) + + ``` + +- **课后作业** + + - 四大基本数据结构中哪些是可变的,哪些是不可变的 + - 可变的 list dict 不可变的 tuple set + - 四大基本数据结构中哪些是有序的,哪些是无序的 + - 有序的 list tupple 无序的 dict set - 创建set,list,dict.tuple实例,每个数据结构中的实例需要包括六大基本数据类型(有一个是没办法包含数据结构的) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/shili.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/shili.py" index 3b77452a3597818d3eea659dc49ae9a4560df7b5..87ce1ce1d9d16867d13f058c3ea41e2bd857503c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/shili.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/shili.py" @@ -1,12 +1,12 @@ -a = 1 -b = 2.0 -c = ('3') -d = True -e = False -f = None -list = (a, b, c, d, e, f) -tuple = (a, b, c, d, e, f) -set = {a, b, c, d, e, f} -print(list) -print(tuple) +a = 1 +b = 2.0 +c = ('3') +d = True +e = False +f = None +list = (a, b, c, d, e, f) +tuple = (a, b, c, d, e, f) +set = {a, b, c, d, e, f} +print(list) +print(tuple) print(set) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/wenda.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/wenda.md" index 10d601d9bc9c5c810912fe4f21dc0b461d0bf79b..7b4342d1218dad273711c62e2fb045f8d4bff0aa 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/wenda.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\345\261\213/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/wenda.md" @@ -1,4 +1,4 @@ -- 四大基本数据结构中哪些是可变的,哪些是不可变的 - - 可变的 list dict 不可变的 tuple set -- 四大基本数据结构中哪些是有序的,哪些是无序的 +- 四大基本数据结构中哪些是可变的,哪些是不可变的 + - 可变的 list dict 不可变的 tuple set +- 四大基本数据结构中哪些是有序的,哪些是无序的 - 有序的 list tupple 无序的 dict set \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/lesson3.py" index c7be0e16d5414ceb8f107bf1b60dff876b5eb92c..861bc8a91094e5104f186ca03427a0b5688cab3e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/lesson3.py" @@ -1,25 +1,25 @@ -# 创建一个列表list - -a = [1, 1.0, 'hello', True, b'', None] - -# 创建一个元组tuple - -b = (1, 1.0, 'hello', True, b'', None) - -# 建一个字典dict - -c = {'a': 1, 'b': 1.0, 'c': 'hello', 'd': True, 'e': b'', 'f': None} - -# 创建一个集合set - -d = {1, 1.0, 'hello', True, B'', None} - -# 验证一下 - -print(type(a), type(b), type(c), type(d)) - -print(a, b, c, d) - -# 测试了一下看了下结果,老师说的坑大概就出现在set这里。 -# 在set里面,0和False会被去重,1和1.0还有True也会被去重,最后都只会显示0和1。 +# 创建一个列表list + +a = [1, 1.0, 'hello', True, b'', None] + +# 创建一个元组tuple + +b = (1, 1.0, 'hello', True, b'', None) + +# 建一个字典dict + +c = {'a': 1, 'b': 1.0, 'c': 'hello', 'd': True, 'e': b'', 'f': None} + +# 创建一个集合set + +d = {1, 1.0, 'hello', True, B'', None} + +# 验证一下 + +print(type(a), type(b), type(c), type(d)) + +print(a, b, c, d) + +# 测试了一下看了下结果,老师说的坑大概就出现在set这里。 +# 在set里面,0和False会被去重,1和1.0还有True也会被去重,最后都只会显示0和1。 # 但是 b''和 b'\x00'还是会显示出来,所以有点不明白bytes到底是什么意思了,明明我的b''和b'\x00'是通过bytes(0)和bytes(1)给转化过来的。 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/\344\272\214\347\217\255_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/\344\272\214\347\217\255_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\346\217\220\344\272\244.md" index 19156f1125326ef9a214384e516c05d02dccf239..63248b5de75e5f8fb7e4e115db4271404f99e3aa 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/\344\272\214\347\217\255_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\200\345\221\250/\344\272\214\347\217\255_\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,14 +1,14 @@ -- 四大基本数据结构中哪些是可变的,哪些是不可变的? - - 可变的 - - list(列表) - - dict(字典) - - set(集合) - - 不可变的 - - tuple(元组) -- 四大基本数据结构中哪些是有序的,哪些是无序的? - - 有序的 - - list(列表) - - tuple(元组) - - 无序的 - - dict(字典) +- 四大基本数据结构中哪些是可变的,哪些是不可变的? + - 可变的 + - list(列表) + - dict(字典) + - set(集合) + - 不可变的 + - tuple(元组) +- 四大基本数据结构中哪些是有序的,哪些是无序的? + - 有序的 + - list(列表) + - tuple(元组) + - 无序的 + - dict(字典) - set(集合) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250\347\254\254\344\270\200\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250\347\254\254\344\270\200\350\212\202.md" index c0389ea161377a7e7966d090155cc5dbd2a8d243..1f6c97f502fa8abfbf7ef668248407739e9b4f57 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250\347\254\254\344\270\200\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250\347\254\254\344\270\200\350\212\202.md" @@ -1,49 +1,49 @@ -#### 什么是关系型数据表,什么是非关系行型数据库表,他们有什么区别,各有什么应用场景? - -- 关系型数据表 - - 创建在关系模型基础上的数据库,用来存储和给康结构化的数据。 - - - 适用场景 - - 考虑到事务和日志 - - - 对数据完整性有要求 - - - 存储的数据结构化完整 - - - 单个数据库服务实例可以满足需求 - - ​ 建立集群方案,大多需要使用企业版,企业版收费高昂 - - - 读表操作远远大于写表操作 - -- 非关系型数据表 - - 创建在`Nosql`系统存储(键对值)上的数据库,既可以存储机构化的数据,要和可以存储非结构化的数据。 - -#### 什么是事务,事务的特点 - -- 事务 - -- ACID - - - Atomic(原子性) - - 不可分割的就,指事务的操作是不可分割的。要么完成,要么不完成,不存在其他的中间态。 - - - Consistence(一致性) - - 事务A和事务B同时运行,无论谁先结束,数据库都会到达一致。 - - - Isolation(隔离性) - - 解决多个事务同时对数据进行读写和修改的能力 - - - Duration(持久性) - - 当某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够持久化地保存下来。 - - 事务的所有操作都是有记录的,即使数据库中途崩溃,仍然可以通过记录恢复。 - +#### 什么是关系型数据表,什么是非关系行型数据库表,他们有什么区别,各有什么应用场景? + +- 关系型数据表 + + 创建在关系模型基础上的数据库,用来存储和给康结构化的数据。 + + - 适用场景 + + 考虑到事务和日志 + + - 对数据完整性有要求 + + - 存储的数据结构化完整 + + - 单个数据库服务实例可以满足需求 + + ​ 建立集群方案,大多需要使用企业版,企业版收费高昂 + + - 读表操作远远大于写表操作 + +- 非关系型数据表 + + 创建在`Nosql`系统存储(键对值)上的数据库,既可以存储机构化的数据,要和可以存储非结构化的数据。 + +#### 什么是事务,事务的特点 + +- 事务 + +- ACID + + - Atomic(原子性) + + 不可分割的就,指事务的操作是不可分割的。要么完成,要么不完成,不存在其他的中间态。 + + - Consistence(一致性) + + 事务A和事务B同时运行,无论谁先结束,数据库都会到达一致。 + + - Isolation(隔离性) + + 解决多个事务同时对数据进行读写和修改的能力 + + - Duration(持久性) + + 当某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够持久化地保存下来。 + + 事务的所有操作都是有记录的,即使数据库中途崩溃,仍然可以通过记录恢复。 + ​ \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/classes.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/classes.py" index 27b5c93d3cbfbd1ce8456be3cfb017376d063fb9..4f6edbd064bbd97ad35803b3b78c6115b96bad17 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/classes.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/classes.py" @@ -1,34 +1,34 @@ -# 给定一个列表, 根据grade来排序 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -classes.sort(key=lambda x: x["grade"]) -print(classes) - - -# 通过filter语句来筛选出Grade为A的同学 -f = filter(lambda x: True if x["grade"] == "A" else False, classes) -l = list(f) -print(l) - - -# 通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) -def age_21(a): - return a["age"]+1 -m = map(age_21, classes) -n = list(m) -print(n) - - -# 使用递归函数重构斐波那契函数 -# F(n) = F(n-2) + F(n-1) -def fact(n): - if n <= 1: - return n - return fact(n-2) + fact(n-1) +# 给定一个列表, 根据grade来排序 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +classes.sort(key=lambda x: x["grade"]) +print(classes) + + +# 通过filter语句来筛选出Grade为A的同学 +f = filter(lambda x: True if x["grade"] == "A" else False, classes) +l = list(f) +print(l) + + +# 通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) +def age_21(a): + return a["age"]+1 +m = map(age_21, classes) +n = list(m) +print(n) + + +# 使用递归函数重构斐波那契函数 +# F(n) = F(n-2) + F(n-1) +def fact(n): + if n <= 1: + return n + return fact(n-2) + fact(n-1) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/for_while.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/for_while.py" index 684a48e5e386ee9a0fc4b795ef003cb1da8b3b14..ad80acc32a2ef3a69356b65e4612ff3d62142896 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/for_while.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/for_while.py" @@ -1,98 +1,98 @@ -# 用for循环来完成简单的计数 -for x in range(0, 100): - x += 1 - print(x) - - -# 用while来完成简单计数 - y = 0 -while y < 100: - y += 1 - print(y) - - -# 用for循环来实现斐波那契函数 -result_f = [0, 1] -for i in range(10): - result_f.append(result_f[-2] + result_f[-1]) - print(result_f) - - -# 用while循环来实现斐波那契函数 -result_w = [0] -a, b = 0, 1 -while b < 100: - result_w.append(b) - a, b = b, a+b - print(result_w) - - -# 对简单计算器进行参数检查 -# 加法 -def add(a, b): - return int(a) + int(b) - - -# 减法 -def sub(a, b): - return int(a) - int(b) - - -# 乘法 -def mul(a, b): - return int(a) * int(b) - - -# 除法 -def div(a, b): - try: - return int(a) / int(b) - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - - -# 整除 -def exa(a, b): - try: - return int(a) // int(b) - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - -# 取余 -def rem(a, b): - try: - return int(a) % int(b) - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - -# 开方 -def sqrt(a, b): - return int(a) ** (1 / int(b)) - - -if __name__ == "__main__": - result_add = add(1, 2) - print(result_add) - - - result_sub = sub(1, 2) - print(result_sub) - - - result_mul = mul(1, 2) - print(result_mul) - - result_div = div(1, 2) - print(result_div) - - result_exa = exa(1, 2) - print(result_exa) - - result_rem = rem(1, 2) - print(result_rem) - - result_sqrt = sqrt(1, 2) +# 用for循环来完成简单的计数 +for x in range(0, 100): + x += 1 + print(x) + + +# 用while来完成简单计数 + y = 0 +while y < 100: + y += 1 + print(y) + + +# 用for循环来实现斐波那契函数 +result_f = [0, 1] +for i in range(10): + result_f.append(result_f[-2] + result_f[-1]) + print(result_f) + + +# 用while循环来实现斐波那契函数 +result_w = [0] +a, b = 0, 1 +while b < 100: + result_w.append(b) + a, b = b, a+b + print(result_w) + + +# 对简单计算器进行参数检查 +# 加法 +def add(a, b): + return int(a) + int(b) + + +# 减法 +def sub(a, b): + return int(a) - int(b) + + +# 乘法 +def mul(a, b): + return int(a) * int(b) + + +# 除法 +def div(a, b): + try: + return int(a) / int(b) + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + + +# 整除 +def exa(a, b): + try: + return int(a) // int(b) + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + +# 取余 +def rem(a, b): + try: + return int(a) % int(b) + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + +# 开方 +def sqrt(a, b): + return int(a) ** (1 / int(b)) + + +if __name__ == "__main__": + result_add = add(1, 2) + print(result_add) + + + result_sub = sub(1, 2) + print(result_sub) + + + result_mul = mul(1, 2) + print(result_mul) + + result_div = div(1, 2) + print(result_div) + + result_exa = exa(1, 2) + print(result_exa) + + result_rem = rem(1, 2) + print(result_rem) + + result_sqrt = sqrt(1, 2) print(result_sqrt) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/week3_lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/week3_lesson3.py" index 3f37aa4eac013e1c50761fa65a16165fb4dccd67..9fd6332fba99c256846151f056267a23c3fe6974 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/week3_lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\270\211\345\221\250/week3_lesson3.py" @@ -1,83 +1,83 @@ -# 练习作用域之间的转换 -# 全局变量 -a = 1 - -def foo(): - global a - a = 2 - print(a) - -foo() -print(a) - - -# Enclosed(嵌套)自由变量 -def make_averager(): - total = 0 - count = 0 - def averager(value): - nonlocal total, count - total += value - count += 1 - return total / count - return averager - -my_avg = make_averager() -print(my_avg(1)) -print(my_avg(2)) - - -# local 局部变量 -a = 1 -b = [] - -def foo(): - a = 2 - b.append(2) - return None -foo() -print(a) -print(b) - -# 默写一个装饰器, 用来输出函数的执行时间. -import time -def clock_it_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - return wrapper - - -@clock_it_deco -def foo(a, b): - count = 1 - while True: - if count > a ** b: - break - count += 1 -foo(10, 5) - - -# 使用装饰器来为斐波那契函数添加缓存 -def cache_deco(func): -# 保存n执行后的结果 - a = {1: 1, 2: 1, 3: 2, 4: 3, 5: 5, 6: 8} -# 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 - def wrapper(*args): - if args not in a: - a[args] = func(*args) - return a[args] - return wrapper - - -@cache_deco -def fact(n): - if n <= 1: - return n - return fact(n-2) + fact(n-1) - - -print(fact(6)) +# 练习作用域之间的转换 +# 全局变量 +a = 1 + +def foo(): + global a + a = 2 + print(a) + +foo() +print(a) + + +# Enclosed(嵌套)自由变量 +def make_averager(): + total = 0 + count = 0 + def averager(value): + nonlocal total, count + total += value + count += 1 + return total / count + return averager + +my_avg = make_averager() +print(my_avg(1)) +print(my_avg(2)) + + +# local 局部变量 +a = 1 +b = [] + +def foo(): + a = 2 + b.append(2) + return None +foo() +print(a) +print(b) + +# 默写一个装饰器, 用来输出函数的执行时间. +import time +def clock_it_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + return wrapper + + +@clock_it_deco +def foo(a, b): + count = 1 + while True: + if count > a ** b: + break + count += 1 +foo(10, 5) + + +# 使用装饰器来为斐波那契函数添加缓存 +def cache_deco(func): +# 保存n执行后的结果 + a = {1: 1, 2: 1, 3: 2, 4: 3, 5: 5, 6: 8} +# 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 + def wrapper(*args): + if args not in a: + a[args] = func(*args) + return a[args] + return wrapper + + +@cache_deco +def fact(n): + if n <= 1: + return n + return fact(n-2) + fact(n-1) + + +print(fact(6)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/content.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/content.py" index 83c46503e8cc18e974b47be6f96bcb3ff6fe12e6..8c0d9f14dad2f90271e9b9e4294b62b72e358e45 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/content.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/content.py" @@ -1,161 +1,161 @@ -# open函数打开一个文件,没有文件会新建,但是路径不对会报错 -# 指定文件名,方法(读,写,追加),编码格式 - - -# 保存到文件 -output = open("output.md", "w", encoding="utf-8") -content = """ -# 编码 ->>> '训练营'.encode("utf-8") -b'\xe8\xae\xad\xe7\xbb\x83\xe8\x90\xa5' - - -# 解码 ->>> a = '训练营'.encode("utf-8") ->>> a -b'\xe8\xae\xad\xe7\xbb\x83\xe8\x90\xa5' ->>> a.decode("utf") -'训练营' - - -# Create(创建) ->>> a = 'a' ->>> a += 'b' ->>> a -'ab' - - -# Retrieve(检索) -# 根据索引获取字符 ->>> a = 'hello, python' ->>> a[0] -'h' - - -# find和index ->>> a = 'hello, python' ->>> a.find("p") -7 ->>> a.find("@") --1 ->>> a.index("h") -0 ->>> a.index("@") -Traceback (most recent call last): - File "", line 1, in -ValueError: substring not found - - -# startswith和endswith ->>> a = "2020-12-25.python.py" ->>> a -'2020-12-25.python.py' ->>> a.startwith("2020") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'str' object has no attribute 'startwith' ->>> a.startswith("2020") -True ->>> a.endswith("py") -True - - -# Update(更新) -# replace(替换) ->>> a = "hello, python" ->>> a.replace("on", "off") -'hello, pythoff' ->>> a -'hello, python' ->>> b = a.replace("on","off") ->>> b -'hello, pythoff' - - -# split(分割) ->>> a = "<>, <>, <>, <>" ->>> a.split(",") -['<>', ' <>', ' <>', ' <>'] ->>> - - -# join(拼接) ->>> b = a.split(",") ->>> b -['<>', ' <>', ' <>', ' <>'] ->>> b.join(",") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'list' object has no attribute 'join' ->>> ",".join(b) -'<>, <>, <>, <>' - - -# Delete(删除) -# strip, lstrip, rstrip ->>> a = " hello, python " ->>> a.lstrip() -'hello, python\t\t' ->>> a.rstrip() -'\thello, python' ->>> a = " hello, python " ->>> a.strip() -'hello, python' ->>> a.lstrip() -'hello, python ' - - -# format -# 按传入参数默认顺序 ->>> a = "ping" ->>> b = "pong" ->>> "play pingpong: {}, {}".format(a, b) -'play pingpong: ping, pong' - - -# 按指定参数索引 ->>> "play pingpong: {0}, {1}, {0}, {1}".format(b, a) -'play pingpong: pong, ping, pong, ping' - - -# 按关键词参数 ->>> "play pingpong: {a}, {b}, {a}, {b}".format(a = a, b = b) -'play pingpong: ping, pong, ping, pong' - - -# 按变量(推荐,但是只有3.6以上版本才可以使用) ->>> f"playing pingpong: {a}, {b}" -'playing pingpong: ping, pong' - - -# 小数的表示 ->>> "{:.2f}".format(3.1415926) -'3.14' - - -# %的用法 ->>> "playing %s %s" % ("ping","pong") -'playing ping pong' -""" -# 正式写入文件 -output.write(content) -# 关闭文件句柄 -output.close() - - -# 读取文件 -input = open("output.txt", "r", encoding="utf-8") -# 获取文件中的内容 -content = input.read() -print(content) -# 暂时理解为只能读取一遍 -content_2 = input.read() -print(content_2) - - -# 追加文件 -output = open("output.txt", "a", encoding="utf-8") -content_a = "\nhello, python" -# 正式写入文件 -output.write(content_a) +# open函数打开一个文件,没有文件会新建,但是路径不对会报错 +# 指定文件名,方法(读,写,追加),编码格式 + + +# 保存到文件 +output = open("output.md", "w", encoding="utf-8") +content = """ +# 编码 +>>> '训练营'.encode("utf-8") +b'\xe8\xae\xad\xe7\xbb\x83\xe8\x90\xa5' + + +# 解码 +>>> a = '训练营'.encode("utf-8") +>>> a +b'\xe8\xae\xad\xe7\xbb\x83\xe8\x90\xa5' +>>> a.decode("utf") +'训练营' + + +# Create(创建) +>>> a = 'a' +>>> a += 'b' +>>> a +'ab' + + +# Retrieve(检索) +# 根据索引获取字符 +>>> a = 'hello, python' +>>> a[0] +'h' + + +# find和index +>>> a = 'hello, python' +>>> a.find("p") +7 +>>> a.find("@") +-1 +>>> a.index("h") +0 +>>> a.index("@") +Traceback (most recent call last): + File "", line 1, in +ValueError: substring not found + + +# startswith和endswith +>>> a = "2020-12-25.python.py" +>>> a +'2020-12-25.python.py' +>>> a.startwith("2020") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'str' object has no attribute 'startwith' +>>> a.startswith("2020") +True +>>> a.endswith("py") +True + + +# Update(更新) +# replace(替换) +>>> a = "hello, python" +>>> a.replace("on", "off") +'hello, pythoff' +>>> a +'hello, python' +>>> b = a.replace("on","off") +>>> b +'hello, pythoff' + + +# split(分割) +>>> a = "<>, <>, <>, <>" +>>> a.split(",") +['<>', ' <>', ' <>', ' <>'] +>>> + + +# join(拼接) +>>> b = a.split(",") +>>> b +['<>', ' <>', ' <>', ' <>'] +>>> b.join(",") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'list' object has no attribute 'join' +>>> ",".join(b) +'<>, <>, <>, <>' + + +# Delete(删除) +# strip, lstrip, rstrip +>>> a = " hello, python " +>>> a.lstrip() +'hello, python\t\t' +>>> a.rstrip() +'\thello, python' +>>> a = " hello, python " +>>> a.strip() +'hello, python' +>>> a.lstrip() +'hello, python ' + + +# format +# 按传入参数默认顺序 +>>> a = "ping" +>>> b = "pong" +>>> "play pingpong: {}, {}".format(a, b) +'play pingpong: ping, pong' + + +# 按指定参数索引 +>>> "play pingpong: {0}, {1}, {0}, {1}".format(b, a) +'play pingpong: pong, ping, pong, ping' + + +# 按关键词参数 +>>> "play pingpong: {a}, {b}, {a}, {b}".format(a = a, b = b) +'play pingpong: ping, pong, ping, pong' + + +# 按变量(推荐,但是只有3.6以上版本才可以使用) +>>> f"playing pingpong: {a}, {b}" +'playing pingpong: ping, pong' + + +# 小数的表示 +>>> "{:.2f}".format(3.1415926) +'3.14' + + +# %的用法 +>>> "playing %s %s" % ("ping","pong") +'playing ping pong' +""" +# 正式写入文件 +output.write(content) +# 关闭文件句柄 +output.close() + + +# 读取文件 +input = open("output.txt", "r", encoding="utf-8") +# 获取文件中的内容 +content = input.read() +print(content) +# 暂时理解为只能读取一遍 +content_2 = input.read() +print(content_2) + + +# 追加文件 +output = open("output.txt", "a", encoding="utf-8") +content_a = "\nhello, python" +# 正式写入文件 +output.write(content_a) output.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/crud.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/crud.py" index 9c0950608317a3f7997faf88e7dcb78ea1fb1522..438a72a8185490ee488b40129cfcea9cd2a6c9b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/crud.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/crud.py" @@ -1,207 +1,207 @@ -# list(列表) -# list中存的元素其实是引用 -l = [1, 1.0, 'hello', True, b'', None, [1, "x"], ("y", 1), {'q': 1, 'w': 2, 'e': 3, 'r': 6}, {'w', 's', 'a', 'd'}] - - -# Create(增加) -# append -l.append('h') -print(l) - - -# +和+= -# 拼接两个列表然后返回一个新列表 -l_1 = ['a'] -l_2 = l + l_1 -print(l_2) - - -# *和*= -l_3 = l_1 * 10 -print(l_3) - - -# insert -# 指定位置添加元素 -l.insert(5, 15) -print(l) - - -# Retrieve(检索) -# 索引取值 -# 所有序列都支持索引取值 -l_r = l[8] -print(l_r) - - -# 切片 -l_q = l[0:6] -print(l_q) - -# 取最后一个 -l_q1 = l_q[-1] -print(l_q1) - -# 间隔问题 -l_q2 = l_q[0:5:2] -print(l_q2) - - -# index -l.insert(l.index(15), 'test') - - -# Update(更新) -# 索引赋值 -l[6] = "3" -print(l) - -# 切片赋值 -l[5:7] = [57] -print(l) - - -# Delete(删除) -# pop() 从末尾删除元素并返回 -l.pop() -print(l) - -# clear -# 清除当前列表的元素,不会改变列表的内存地址 -l_q.clear() -print(l_q) - - -# sort()(排序) -l_q = [5, 8, 0, 1, 4, 7, 9, 6, 3, 2] -l_s = l_q -l_s.sort() -print(l_s) - -# sorted -l_d = sorted(l_q) -print(l_d) - -# reverse -l_d.reverse() -print(l_d) - -# reversed -# 倒序之后返回新列表 -print(list(reversed(l_s))) - - - -# tuple - -# Create 无 -# Update 无 -# Delete 无 - -# Retrieve -# 索引取值 -# index -# 切片 -t = tuple(l) -print(t, t[0], t.index(1), t[0:1]) - - - -# dict -# Create -# 键对值赋值 -d = {} -d['z'] = -1 - - -# update -# 提供合并字典的功能 -d2 = {'a': 1, 'b': 1.0, 'c': 'hello', 'd': True, 'e': b'', 'f': None} -d.update(d2) - - -# setdifault -# 如果字典中没有当前key,那么就设置默认值 -d.setdefault('y', 3.14) - - -# Retrieve -# 键对值访问 -print(d['a']) - - -# get -# 键对值访问缺失key会报错,而get可以指定默认值 -print(d.get('h', 0)) - - -# keys() -# 返回所有key -print(d.keys()) - - -# values() -# 返回所有value -print(d.values()) - - -# items() -# 返回所有键对值 -print(d.items()) - - -# Update -# 键对值赋值 -# update - - -# Delete -# pop(key) -# 删除当前元素并返回value -print(d.pop('z')) - - -# popitem() -# 对于人来说,相当于随机返回一个item -print(d.popitem()) - - -# clear() -d2.clear() -print(d2) - - -# set -# Create -# add -s = set(d.keys()) -s.add('h') - - -# update -s.update('x') - - -# Retrieve -# 运算符in -print('a' in s) - - -# Update -# union -s.union(set(d2.keys())) -print(s) - - -# Delete -# remove和discard -# discard缺失元素时不会报错,而remove会报错 -s.discard('j') -s.remove('c') -print(s) - - -# pop() -# 当成无序删除并返回元素 -s.pop() +# list(列表) +# list中存的元素其实是引用 +l = [1, 1.0, 'hello', True, b'', None, [1, "x"], ("y", 1), {'q': 1, 'w': 2, 'e': 3, 'r': 6}, {'w', 's', 'a', 'd'}] + + +# Create(增加) +# append +l.append('h') +print(l) + + +# +和+= +# 拼接两个列表然后返回一个新列表 +l_1 = ['a'] +l_2 = l + l_1 +print(l_2) + + +# *和*= +l_3 = l_1 * 10 +print(l_3) + + +# insert +# 指定位置添加元素 +l.insert(5, 15) +print(l) + + +# Retrieve(检索) +# 索引取值 +# 所有序列都支持索引取值 +l_r = l[8] +print(l_r) + + +# 切片 +l_q = l[0:6] +print(l_q) + +# 取最后一个 +l_q1 = l_q[-1] +print(l_q1) + +# 间隔问题 +l_q2 = l_q[0:5:2] +print(l_q2) + + +# index +l.insert(l.index(15), 'test') + + +# Update(更新) +# 索引赋值 +l[6] = "3" +print(l) + +# 切片赋值 +l[5:7] = [57] +print(l) + + +# Delete(删除) +# pop() 从末尾删除元素并返回 +l.pop() +print(l) + +# clear +# 清除当前列表的元素,不会改变列表的内存地址 +l_q.clear() +print(l_q) + + +# sort()(排序) +l_q = [5, 8, 0, 1, 4, 7, 9, 6, 3, 2] +l_s = l_q +l_s.sort() +print(l_s) + +# sorted +l_d = sorted(l_q) +print(l_d) + +# reverse +l_d.reverse() +print(l_d) + +# reversed +# 倒序之后返回新列表 +print(list(reversed(l_s))) + + + +# tuple + +# Create 无 +# Update 无 +# Delete 无 + +# Retrieve +# 索引取值 +# index +# 切片 +t = tuple(l) +print(t, t[0], t.index(1), t[0:1]) + + + +# dict +# Create +# 键对值赋值 +d = {} +d['z'] = -1 + + +# update +# 提供合并字典的功能 +d2 = {'a': 1, 'b': 1.0, 'c': 'hello', 'd': True, 'e': b'', 'f': None} +d.update(d2) + + +# setdifault +# 如果字典中没有当前key,那么就设置默认值 +d.setdefault('y', 3.14) + + +# Retrieve +# 键对值访问 +print(d['a']) + + +# get +# 键对值访问缺失key会报错,而get可以指定默认值 +print(d.get('h', 0)) + + +# keys() +# 返回所有key +print(d.keys()) + + +# values() +# 返回所有value +print(d.values()) + + +# items() +# 返回所有键对值 +print(d.items()) + + +# Update +# 键对值赋值 +# update + + +# Delete +# pop(key) +# 删除当前元素并返回value +print(d.pop('z')) + + +# popitem() +# 对于人来说,相当于随机返回一个item +print(d.popitem()) + + +# clear() +d2.clear() +print(d2) + + +# set +# Create +# add +s = set(d.keys()) +s.add('h') + + +# update +s.update('x') + + +# Retrieve +# 运算符in +print('a' in s) + + +# Update +# union +s.union(set(d2.keys())) +print(s) + + +# Delete +# remove和discard +# discard缺失元素时不会报错,而remove会报错 +s.discard('j') +s.remove('c') +print(s) + + +# pop() +# 当成无序删除并返回元素 +s.pop() print(s) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/my_calculator.py" index 1ff50f65a09fe0747b909e0eccdfb191572f7363..2d3b52fa28a5e1a5094642f5dfd9893cb2493011 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\214\345\221\250/my_calculator.py" @@ -1,58 +1,58 @@ -# 加法 -def add(a, b): - return int(a) + int(b) - - -# 减法 -def sub(a, b): - return int(a) - int(b) - - -# 乘法 -def mul(a, b): - return int(a) * int(b) - - -# 除法 -def div(a, b): - return int(a) / int(b) - - -# 整除 -def exa(a, b): - return int(a) // int(b) - - -# 取余 -def rem(a, b): - return int(a) % int(b) - - -# 开方 -def sqrt(a, b): - return int(a) ** (1 / int(b)) - - -if __name__ == "__main__": - result_add = add(1, 2) - print(result_add) - - - result_sub = sub(1, 2) - print(result_sub) - - - result_mul = mul(1, 2) - print(result_mul) - - result_div = div(1, 2) - print(result_div) - - result_exa = exa(1, 2) - print(result_exa) - - result_rem = rem(1, 2) - print(result_rem) - - result_sqrt = sqrt(1, 2) +# 加法 +def add(a, b): + return int(a) + int(b) + + +# 减法 +def sub(a, b): + return int(a) - int(b) + + +# 乘法 +def mul(a, b): + return int(a) * int(b) + + +# 除法 +def div(a, b): + return int(a) / int(b) + + +# 整除 +def exa(a, b): + return int(a) // int(b) + + +# 取余 +def rem(a, b): + return int(a) % int(b) + + +# 开方 +def sqrt(a, b): + return int(a) ** (1 / int(b)) + + +if __name__ == "__main__": + result_add = add(1, 2) + print(result_add) + + + result_sub = sub(1, 2) + print(result_sub) + + + result_mul = mul(1, 2) + print(result_mul) + + result_div = div(1, 2) + print(result_div) + + result_exa = exa(1, 2) + print(result_exa) + + result_rem = rem(1, 2) + print(result_rem) + + result_sqrt = sqrt(1, 2) print(result_sqrt) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson1.py" index 843caddbdd8f649d4c66c6f71e3acb9efc179a63..8d05a8a955d125f814b291c55e108196bf8d6ae0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson1.py" @@ -1,21 +1,21 @@ -import requests -from threading import Thread -from multiprocessing import Process -import time - - -def request_doge(index): - url = "https://www.dogedoge.com/" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(f'当前请求序号:{index}, 返回结果状态码:{response.status_code}') - - -if __name__ == "__main__": - for i in range(10): - t = Thread(target=request_doge, args=(i, )) - t.start() - p = Process(target=request_doge, args=(i, )) - p.start() +import requests +from threading import Thread +from multiprocessing import Process +import time + + +def request_doge(index): + url = "https://www.dogedoge.com/" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(f'当前请求序号:{index}, 返回结果状态码:{response.status_code}') + + +if __name__ == "__main__": + for i in range(10): + t = Thread(target=request_doge, args=(i, )) + t.start() + p = Process(target=request_doge, args=(i, )) + p.start() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson2.py" index 02fc2f66dbce19766cb4f9c655f53399854ce3b6..d9ac5ebbaec97f8d40f01b984598e92f696c0261 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson2.py" @@ -1,59 +1,59 @@ -from multiprocessing import Process, Queue -from multiprocessing import Lock as Lock_m -from threading import Thread, Lock -# 多进程锁 -def save_to_file(index, lock): - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + '\n') - - -# 多线程锁 -x = 0 -lock_t = Lock() -def foo(): - global x - for r in range(10**5): - with lock_t: - x += 1 - x -= 1 - - -# 消息队列 -def save_to_queue(index, my_queue): - my_queue.put(index) - - - -if __name__ == "__main__": - process_array = [] - lock = Lock_m() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("done!") - - - thread_array = [] - for w in range(2): - t = Thread(target=foo) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - print(x) - - - queque_array = [] - my_queque = Queue() - for e in range(10): - q = Process(target=save_to_queue, args=(e, my_queque)) - queque_array.append(q) - q.start() - for q in queque_array: - q.join() - print(my_queque.get()) - print("Done!") +from multiprocessing import Process, Queue +from multiprocessing import Lock as Lock_m +from threading import Thread, Lock +# 多进程锁 +def save_to_file(index, lock): + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + '\n') + + +# 多线程锁 +x = 0 +lock_t = Lock() +def foo(): + global x + for r in range(10**5): + with lock_t: + x += 1 + x -= 1 + + +# 消息队列 +def save_to_queue(index, my_queue): + my_queue.put(index) + + + +if __name__ == "__main__": + process_array = [] + lock = Lock_m() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!") + + + thread_array = [] + for w in range(2): + t = Thread(target=foo) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print(x) + + + queque_array = [] + my_queque = Queue() + for e in range(10): + q = Process(target=save_to_queue, args=(e, my_queque)) + queque_array.append(q) + q.start() + for q in queque_array: + q.join() + print(my_queque.get()) + print("Done!") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson3.py" index 45f187b9ee901b925cf11458cac5c47061a6fac1..0c0a3cbacf2b6a547b7c8e26c97679d26136bec5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\344\272\224\345\221\250/week5_lesson3.py" @@ -1,42 +1,42 @@ -import asyncio, time -# 用协程实现一个计算平均数的函数 -def coro_avg(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -my_avg = coro_avg() -print(next(my_avg)) -print(my_avg.send(5)) -print(my_avg.send(4)) -print(my_avg.send(3)) -print(my_avg.send(2)) -print(my_avg.send(1)) - - -# 编写一个asyncio异步程序 -class Response: - staus_code = 200 - -async def sim_request(index): - print(f"模拟发送请求 index:{index}") - response = Response() - await asyncio.sleep(1) - print(f"request index:{index}, response staus_code:{response.staus_code}") - return response.staus_code - -loop = asyncio.get_event_loop() -task_array = [] -for i in range(100): - task_array.append(sim_request(i)) - -# loop.run_until_complete((asyncio.wait(task_array))) -result = loop.run_until_complete(asyncio.gather(*task_array)) -print(result) -loop.close() +import asyncio, time +# 用协程实现一个计算平均数的函数 +def coro_avg(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +my_avg = coro_avg() +print(next(my_avg)) +print(my_avg.send(5)) +print(my_avg.send(4)) +print(my_avg.send(3)) +print(my_avg.send(2)) +print(my_avg.send(1)) + + +# 编写一个asyncio异步程序 +class Response: + staus_code = 200 + +async def sim_request(index): + print(f"模拟发送请求 index:{index}") + response = Response() + await asyncio.sleep(1) + print(f"request index:{index}, response staus_code:{response.staus_code}") + return response.staus_code + +loop = asyncio.get_event_loop() +task_array = [] +for i in range(100): + task_array.append(sim_request(i)) + +# loop.run_until_complete((asyncio.wait(task_array))) +result = loop.run_until_complete(asyncio.gather(*task_array)) +print(result) +loop.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\253\345\221\250/week8_lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\253\345\221\250/week8_lesson3.py" index e36c58a021209e6fd7ffdc1ea892b1d633ae4ef1..7ebddd5b49c13338acff5baf57107b886415294a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\253\345\221\250/week8_lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\253\345\221\250/week8_lesson3.py" @@ -1,73 +1,73 @@ -import pymysql -import time -import random - - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "zh123456", - "db": "week7" -} - -mysql_con = pymysql.connect(**MYSQL_CONF) - -mysql_cursor = mysql_con.cursor() - -def insert_one(): - for i in range(10**3): - store_name = f"店铺_{i}" - amount = format(random.uniform(10**3, 10**6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES ('{store_name}', {amount}, '{department}', '{sta_date}')""" - print(SQL) - mysql_cursor.execute(SQL) - mysql_con.commit() - - -def insert_many(): - values = [] - for i in range(10**3): - store_name = f"店铺_{i}" - amount = format(random.uniform(10**3, 10**6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - values.append((store_name, amount, department, sta_date)) - - SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES (%s, %s, %s, %s)""" - print(values) - mysql_cursor.executemany(SQL, values) - mysql_con.commit() - -def get_shops(): - SQL = "select store_name, amount, sta_date from store_perf where department='unknow'" - mysql_cursor.execute(SQL) - query_set = mysql_cursor.fetchall() - print(query_set) - - -def transaction(): - try: - #SQL = "DELETE FROM lesson3_2 where name='name_15'" - SQL = "DELETE FROM lesson3_2 where name='name0'" - mysql_cursor.execute(SQL) - SQL_2 = "INSERT INTO lesson3 VALUES(name)" - mysql_cursor.execute(SQL_2) - - except Exception as e: - print("raise Exceptions", e.args[0]) - print("rollback") - mysql_con.rollback() - finally: - mysql_con.commit() - - -if __name__ == "__main__": - #insert_one() - #insert_many() - #get_shops() - transaction() +import pymysql +import time +import random + + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "zh123456", + "db": "week7" +} + +mysql_con = pymysql.connect(**MYSQL_CONF) + +mysql_cursor = mysql_con.cursor() + +def insert_one(): + for i in range(10**3): + store_name = f"店铺_{i}" + amount = format(random.uniform(10**3, 10**6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES ('{store_name}', {amount}, '{department}', '{sta_date}')""" + print(SQL) + mysql_cursor.execute(SQL) + mysql_con.commit() + + +def insert_many(): + values = [] + for i in range(10**3): + store_name = f"店铺_{i}" + amount = format(random.uniform(10**3, 10**6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + values.append((store_name, amount, department, sta_date)) + + SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES (%s, %s, %s, %s)""" + print(values) + mysql_cursor.executemany(SQL, values) + mysql_con.commit() + +def get_shops(): + SQL = "select store_name, amount, sta_date from store_perf where department='unknow'" + mysql_cursor.execute(SQL) + query_set = mysql_cursor.fetchall() + print(query_set) + + +def transaction(): + try: + #SQL = "DELETE FROM lesson3_2 where name='name_15'" + SQL = "DELETE FROM lesson3_2 where name='name0'" + mysql_cursor.execute(SQL) + SQL_2 = "INSERT INTO lesson3 VALUES(name)" + mysql_cursor.execute(SQL_2) + + except Exception as e: + print("raise Exceptions", e.args[0]) + print("rollback") + mysql_con.rollback() + finally: + mysql_con.commit() + + +if __name__ == "__main__": + #insert_one() + #insert_many() + #get_shops() + transaction() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" index e06635880c40e6c0d148cc8c0bfefee986d1abe0..34347897c966d71ecbe489781ab0a4f24d15845a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" @@ -1,17 +1,17 @@ -- `TCP/IP`三次握手 - - 客户端向服务端发送带有`SYN`(同步序列编号)标识的数据包------服务端确认了客户端的发送能力正常 - - 服务端向客户端发送了带有`SYN-ACK`(确认字符)标识的数据包------服务端确认了自己接收能力是正常 - - 客户端向服务端返回带有`ACK`标识的数据包------服务端确认了自己发送能力,客户端接收正常 -- `TCP/IP`四次挥手 - - 客户端向服务端发送了一个FIN(finish)数据包------关闭客户端到服务端的连接通道 - - 服务端收到FIN后,返回了`ACK`数据包------服务端已经知道了客户端到服务端的连接通道已关闭 - - 服务端发送FIN数据包至客户端,关闭与客户端的连接------目的是关闭服务端到客户端的连接通道 - - 客户端返回`ACK`数据包确认------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关 -- `HTTPS`加密过程 - - 客户端向服务端发送通信请求 - - 服务端返回给客户端证书和秘钥 - - 客户端通过`CA`中心验证证书的真实性 - - 客户端完成认证之后,使用公钥对发送数据进行加密,发送给服务端 - - 服务端接收到加密后的请求数据后,使用私钥进行解密 - - 服务器和客户端使用**对称加密**进行通信 - +- `TCP/IP`三次握手 + - 客户端向服务端发送带有`SYN`(同步序列编号)标识的数据包------服务端确认了客户端的发送能力正常 + - 服务端向客户端发送了带有`SYN-ACK`(确认字符)标识的数据包------服务端确认了自己接收能力是正常 + - 客户端向服务端返回带有`ACK`标识的数据包------服务端确认了自己发送能力,客户端接收正常 +- `TCP/IP`四次挥手 + - 客户端向服务端发送了一个FIN(finish)数据包------关闭客户端到服务端的连接通道 + - 服务端收到FIN后,返回了`ACK`数据包------服务端已经知道了客户端到服务端的连接通道已关闭 + - 服务端发送FIN数据包至客户端,关闭与客户端的连接------目的是关闭服务端到客户端的连接通道 + - 客户端返回`ACK`数据包确认------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关 +- `HTTPS`加密过程 + - 客户端向服务端发送通信请求 + - 服务端返回给客户端证书和秘钥 + - 客户端通过`CA`中心验证证书的真实性 + - 客户端完成认证之后,使用公钥对发送数据进行加密,发送给服务端 + - 服务端接收到加密后的请求数据后,使用私钥进行解密 + - 服务器和客户端使用**对称加密**进行通信 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\212\202.md" index a2bbbaaf5ff0a45e7db99a2e4ae15f579d3597ad..878c2c71ee41395a21a6e856e8ca117e9bcce46d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250\347\254\254\344\270\200\350\212\202.md" @@ -1,47 +1,47 @@ -### 讲清楚浏览器地址敲下`url`后发生了什么? - -- 输入`url` -- `DNS`解析 - - `DNS`服务器根据域名返回真实的`IP`地址,通过`IP`地址访问服务器 -- 客户端与服务器建立连接 - - 客户端与服务端互相确认身份,建立发送数据的连接通道 -- 客户端向服务端发送请求 -- 服务端处理请求并返回结果 -- 浏览器接收到响应后,渲染出结果 - -### 五层协议有哪五层,举例说明 - -- 应用层 - - 为进程和进程之间提供服务 - - 浏览网页,网易云听歌 - -- 传输层 - - 向两个主机应用进程的通信提供服务 - - 文件传输 - - 直播 - -- 网络层 - - “快递的集散中心通过”,`IP`寻址建立两个节点的连接,决定了数据的转寄和路径选择,封装和分组运输层产生的报文段/用户数据段 - -- 数据链路层 - - 负责两台主机之间的数据传输,向网络层提供数据传输服务 - - 流量控制 - - 差错检测 - -- 物理层 - - “快递中的交通工具”,设备节点传输比特流 - - 物理层才是真正传输数据的,数据链路层是用来检查数据完整性的 - - - +### 讲清楚浏览器地址敲下`url`后发生了什么? + +- 输入`url` +- `DNS`解析 + - `DNS`服务器根据域名返回真实的`IP`地址,通过`IP`地址访问服务器 +- 客户端与服务器建立连接 + - 客户端与服务端互相确认身份,建立发送数据的连接通道 +- 客户端向服务端发送请求 +- 服务端处理请求并返回结果 +- 浏览器接收到响应后,渲染出结果 + +### 五层协议有哪五层,举例说明 + +- 应用层 + + 为进程和进程之间提供服务 + + 浏览网页,网易云听歌 + +- 传输层 + + 向两个主机应用进程的通信提供服务 + + 文件传输 + + 直播 + +- 网络层 + + “快递的集散中心通过”,`IP`寻址建立两个节点的连接,决定了数据的转寄和路径选择,封装和分组运输层产生的报文段/用户数据段 + +- 数据链路层 + + 负责两台主机之间的数据传输,向网络层提供数据传输服务 + + 流量控制 + + 差错检测 + +- 物理层 + + “快递中的交通工具”,设备节点传输比特流 + + 物理层才是真正传输数据的,数据链路层是用来检查数据完整性的 + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson1.py" index 0f01b620de28cec114fcac8959b79dfbdaaf1e74..68c39a7e302ddc9dba7e1d05641cf5abb3725c52 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson1.py" @@ -1,26 +1,26 @@ -import datetime - - -# 过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 -now = datetime.datetime.now(tz=None) -now_1 = now.strftime("%Y-%m-%d %H:%M:%S") -print(now) -print(now_1) - -now_1 = datetime.datetime.strptime(now_1, "%Y-%m-%d %H:%M:%S") - -now_2 = now.timestamp() -now_3 = datetime.datetime.fromtimestamp(now_2, tz=None) -print(now_2) -print(now_3) - - -# 封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. -from datetime import timedelta - -day_delta = int(input("输入你想要计算的日期,例如,一天前为-1,一天后为1")) -def get_date(day_delta): - day_c = datetime.datetime.now(tz=None) + timedelta(days=day_delta) - result = day_c.strftime("%Y-%m-%d %H:%M:%S") - return(result) -print(get_date(day_delta)) +import datetime + + +# 过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 +now = datetime.datetime.now(tz=None) +now_1 = now.strftime("%Y-%m-%d %H:%M:%S") +print(now) +print(now_1) + +now_1 = datetime.datetime.strptime(now_1, "%Y-%m-%d %H:%M:%S") + +now_2 = now.timestamp() +now_3 = datetime.datetime.fromtimestamp(now_2, tz=None) +print(now_2) +print(now_3) + + +# 封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. +from datetime import timedelta + +day_delta = int(input("输入你想要计算的日期,例如,一天前为-1,一天后为1")) +def get_date(day_delta): + day_c = datetime.datetime.now(tz=None) + timedelta(days=day_delta) + result = day_c.strftime("%Y-%m-%d %H:%M:%S") + return(result) +print(get_date(day_delta)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson2.py" index 897c07a046a525fa64cf9b7372b83245e2beb57d..4470d6dbe37109247013cde7e4aa1ed836abc16a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson2.py" @@ -1,50 +1,50 @@ -# 用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 -from math import sqrt - - -class MyMath(object): - def add(self, a, b): - return int(a) + int(b) - - - def sub(self, a, b): - return int(a) - int(b) - - - def mul(self, a, b): - return int(a) * int(b) - - - def div(self, a, b): - return int(a) / int(b) - - def sqrt(self, a): - return sqrt(a) - - -# 自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 -class p_language(object): - classification = 'language' - def __init__(self, obj): - self.l = obj - print(f"{self.l}是一种编程语言") - - -# 创建多个继承作业2父类的子类 -class i_language(p_language): - def __init__(self, obj): - self.c = obj - print(f"{self.c}是一种解释型语言") - - -class c_language(p_language): - def __init__(self, obj): - self.c = obj - print(f"{self.c}是一种编译型语言") - - -if __name__ == "__main__": - python = p_language('python') - go = p_language('go') - python = i_language('python') - go = c_language('go') +# 用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 +from math import sqrt + + +class MyMath(object): + def add(self, a, b): + return int(a) + int(b) + + + def sub(self, a, b): + return int(a) - int(b) + + + def mul(self, a, b): + return int(a) * int(b) + + + def div(self, a, b): + return int(a) / int(b) + + def sqrt(self, a): + return sqrt(a) + + +# 自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 +class p_language(object): + classification = 'language' + def __init__(self, obj): + self.l = obj + print(f"{self.l}是一种编程语言") + + +# 创建多个继承作业2父类的子类 +class i_language(p_language): + def __init__(self, obj): + self.c = obj + print(f"{self.c}是一种解释型语言") + + +class c_language(p_language): + def __init__(self, obj): + self.c = obj + print(f"{self.c}是一种编译型语言") + + +if __name__ == "__main__": + python = p_language('python') + go = p_language('go') + python = i_language('python') + go = c_language('go') diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson3.py" index d24a14c92bed568f4bf91826e2db8573e803c7dd..816fcdcb57b09f5b9f99f99fb1144a915f1ac338 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\345\260\217\351\243\236\344\276\240/\347\254\254\345\233\233\345\221\250/week4_lesson3.py" @@ -1,67 +1,67 @@ -# 将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. -from math import sqrt - - -class MyMath(object): - - @staticmethod - def add(a, b): - return int(a) + int(b) - - - @staticmethod - def sub(a, b): - return int(a) - int(b) - - - @staticmethod - def mul(a, b): - return int(a) * int(b) - - - @staticmethod - def div(a, b): - return int(a) / int(b) - - - @staticmethod - def sqrt(a): - return sqrt(a) - - -# 为上节课自定义类添加以下功能: -# 添加类属性 -# 添加类私有属性 -# 添加类方法或者类的私有属性 -# 在__init__方法中初始化实例属性 -# 在__init__方法中绑定私有实例属性 -# 在自定义类中实现__str__, 自定义输出格式 -class p_language(object): - hard_to_learn = True - classification = 'language' - __source_code = 'sss' - def __init__(self, obj): - self.l = obj - print(f"{self.l}是一种编程语言") - - -class i_language(p_language): - def __init__(self, name): - print(f"{name}是一种解释型语言") - self.__hide = 666 - - - def __str__(self): - return f'i_language:{self.__hide}' - - -class c_language(p_language): - def __init__(self, name): - print(f"{name}是一种编译型语言") - - -if __name__ == "__main__": - python = p_language('python') - go = p_language('go') - python = i_language('python') - go = c_language('go') +# 将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. +from math import sqrt + + +class MyMath(object): + + @staticmethod + def add(a, b): + return int(a) + int(b) + + + @staticmethod + def sub(a, b): + return int(a) - int(b) + + + @staticmethod + def mul(a, b): + return int(a) * int(b) + + + @staticmethod + def div(a, b): + return int(a) / int(b) + + + @staticmethod + def sqrt(a): + return sqrt(a) + + +# 为上节课自定义类添加以下功能: +# 添加类属性 +# 添加类私有属性 +# 添加类方法或者类的私有属性 +# 在__init__方法中初始化实例属性 +# 在__init__方法中绑定私有实例属性 +# 在自定义类中实现__str__, 自定义输出格式 +class p_language(object): + hard_to_learn = True + classification = 'language' + __source_code = 'sss' + def __init__(self, obj): + self.l = obj + print(f"{self.l}是一种编程语言") + + +class i_language(p_language): + def __init__(self, name): + print(f"{name}是一种解释型语言") + self.__hide = 666 + + + def __str__(self): + return f'i_language:{self.__hide}' + + +class c_language(p_language): + def __init__(self, name): + print(f"{name}是一种编译型语言") + + +if __name__ == "__main__": + python = p_language('python') + go = p_language('go') + python = i_language('python') + go = c_language('go') diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson1-\345\244\232\350\277\233\347\250\213\345\222\214\345\244\232\347\272\277\347\250\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson1-\345\244\232\350\277\233\347\250\213\345\222\214\345\244\232\347\272\277\347\250\213.py" index 839594b8f8642e9f8867e6f3ee2a304cc5908ffa..17957133da3699deb3888cf9dad7c729bcd18ffe 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson1-\345\244\232\350\277\233\347\250\213\345\222\214\345\244\232\347\272\277\347\250\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson1-\345\244\232\350\277\233\347\250\213\345\222\214\345\244\232\347\272\277\347\250\213.py" @@ -1,33 +1,33 @@ -import time -from threading import Thread -from multiprocessing import Process - -def song(n): - for i in range(n): - print("song") - time.sleep(0.5) - - -if __name__ == "__main__": - start_time = time.time() - song(5) - end_time = time.time() - print(f"正常执行时间为:{end_time - start_time}秒") - - -#创建多线程 -for i in range(5): - start_time = time.time() - t = Thread(target=song(5)) - # t = Process(target=song) - t.start() - end_time = time.time() - print(f"多线程执行时间为:{end_time-start_time}秒") - -#创建多进程 -for i in range(5): - start_time = time.time() - t = Process(target=song(5)) - t.start() - end_time = time.time() +import time +from threading import Thread +from multiprocessing import Process + +def song(n): + for i in range(n): + print("song") + time.sleep(0.5) + + +if __name__ == "__main__": + start_time = time.time() + song(5) + end_time = time.time() + print(f"正常执行时间为:{end_time - start_time}秒") + + +#创建多线程 +for i in range(5): + start_time = time.time() + t = Thread(target=song(5)) + # t = Process(target=song) + t.start() + end_time = time.time() + print(f"多线程执行时间为:{end_time-start_time}秒") + +#创建多进程 +for i in range(5): + start_time = time.time() + t = Process(target=song(5)) + t.start() + end_time = time.time() print(f"多进程执行时间为:{end_time-start_time}秒") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson2-\347\272\277\347\250\213\345\222\214\350\277\233\347\250\213\351\227\264\347\232\204\351\200\232\344\277\241.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson2-\347\272\277\347\250\213\345\222\214\350\277\233\347\250\213\351\227\264\347\232\204\351\200\232\344\277\241.py" index 315317f51769f7c2b9be9223ea453152a7014884..febc2f4a6694378c6a0bd7ffb9ca9804b5c34ad3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson2-\347\272\277\347\250\213\345\222\214\350\277\233\347\250\213\351\227\264\347\232\204\351\200\232\344\277\241.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2545\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/lesson2-\347\272\277\347\250\213\345\222\214\350\277\233\347\250\213\351\227\264\347\232\204\351\200\232\344\277\241.py" @@ -1,56 +1,56 @@ -from threading import Thread, Lock -from multiprocessing import Process, Lock -from multiprocessing import Queue - -def save_to_file(index, lock): - with lock: # 1.多进程互斥锁 - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - -if __name__ == "__main__": - process_array1 = [] - lock = Lock() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - process_array1.append(p) - p.start() - for p in process_array1: - p.join() - print("done!") - -# 2.线程加互斥锁 -zero = 0 -lock = Lock() -def foo(): - global zero - for i in range(10**6): - with lock: - zero += 1 - zero -= 1 - -process_array2 = [] -my_queue = Queue() -for i in range(2): - p = Thread(target=foo) - process_array2.append(p) - p.start() -for p in process_array2: - p.join() - -print(zero) - -# 3.多线程通过Queue来实现进程通信 -def save_to_queue(index, my_queue): - my_queue.put(index) - -process_array3 = [] -my_queue = Queue() -for i in range(10): - p = Process(target=save_to_queue,args=(i, my_queue)) - process_array3.append(p) - p.start() -for p in process_array3: - p.join() - -while True: +from threading import Thread, Lock +from multiprocessing import Process, Lock +from multiprocessing import Queue + +def save_to_file(index, lock): + with lock: # 1.多进程互斥锁 + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + +if __name__ == "__main__": + process_array1 = [] + lock = Lock() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + process_array1.append(p) + p.start() + for p in process_array1: + p.join() + print("done!") + +# 2.线程加互斥锁 +zero = 0 +lock = Lock() +def foo(): + global zero + for i in range(10**6): + with lock: + zero += 1 + zero -= 1 + +process_array2 = [] +my_queue = Queue() +for i in range(2): + p = Thread(target=foo) + process_array2.append(p) + p.start() +for p in process_array2: + p.join() + +print(zero) + +# 3.多线程通过Queue来实现进程通信 +def save_to_queue(index, my_queue): + my_queue.put(index) + +process_array3 = [] +my_queue = Queue() +for i in range(10): + p = Process(target=save_to_queue,args=(i, my_queue)) + process_array3.append(p) + p.start() +for p in process_array3: + p.join() + +while True: print(my_queue.get()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2541\350\212\202\344\272\224\345\261\202\345\215\217\350\256\256.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2541\350\212\202\344\272\224\345\261\202\345\215\217\350\256\256.md" index 7f5423de82b4e4a7561f4a5ed33e1daf8660fa7d..10103101a946ce8432c7a28dc315447517d1f8c6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2541\350\212\202\344\272\224\345\261\202\345\215\217\350\256\256.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2541\350\212\202\344\272\224\345\261\202\345\215\217\350\256\256.md" @@ -1,206 +1,206 @@ -# 第六周-第一节课:五层协议 - -``` -推荐书籍 <<图解TCP/IP>> -``` - -## 一. 输入网址后发生了什么 - -### 1. 输入`url` - -统一资源定位器`uniform resource locator` - -- `url`组成 - - ``` - https://www.baidu.com/ - 协议://域名[:端口]/路径 - - file:///H:/BaiduNetdiskDownload/ - ``` - -- `url`作用 - - 定位指定的资源. - - > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. - -### 2. DNS解析 - -域名系统`Domain Name System`, 将域名解析为`IP`地址 - -- 域名解析流程 - - 域名(www.baidu.com) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 - -### 3. 客户端与服务器建立连接. - -> 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 - -### 4. 客户端正式向服务端发送请求. - -### 5. 服务端处理请求并返回结果 - -### 6. 浏览器接收到响应后, 做相应的渲染 - -## 二.TCP/IP 五层协议 - -``` -文章链接 https://www.cnblogs.com/xjtu-lyh/p/12416763.html -``` - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223803915-1086885188.png) - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223816759-1375625683.png) - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223858705-1259511194.png) - -### 1. 应用层--使用的应用(网易云,网页等) - -> 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. -> - -``` -举例: -浏览网页 -网易云 -用python模拟请求 -``` - -#### 1.1 应用层协议 - -- HTTP/HTTPS(超文本传输协议) -- DNS(域名系统) -- FTP(文件传输协议,文件下载) -- SMTP(邮箱传输协议) - -### 2. 传输层--四层交换机 - -负责向两个主机应用进程的通信提供服务. - -> 一个主机可以开启不同的应用, 可以同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 - -``` -进程 <---> 进程 -``` - -#### 2.1 传输层协议 - -- TCP(传输控制协议)-- 一对一. - - > 提供面向连接, (尽可能)可靠的数据传输服务. - - ``` - 面向连接指的就是:客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. - ``` - - ``` - eg: - - 文件传输(FTP) - - 浏览网页(HTTP) - ``` - -- UDP(用户数据协议)--一对多, 一对一, 多对多... - - > 提供无连接的, 不保证数据传输的可靠性 - - ``` - eg: - - 直播 - - 实况游戏 - ``` - -### 3. 网络层--路由器 - -决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. - -``` -主机 <---> 主机 -``` - -#### 3.1 网络层协议 - -- IP协议 - - - 公网IP--百度IP - - 也就是指的传统IP地址, 是唯一的. - - ``` - 本机IP: 123.161.218.10河南省郑州市金水区 电信 - ``` - - - 局域网IP - - ``` - 命令行输入:ipconfig - 192.168.1.1 - ``` - -### 4. 数据链路层--网卡 - -负责两台主机之间的数据传输, 向网路层提供数据传输服务 - -``` -网卡 <---> 网卡 -``` - -#### 4.1 数据链路层的作用 - -比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是: 检错和纠错 - -- *流量控制(限速,限流量等) -- 差错检测 -- 差错控制 - -### 5. 物理层--光纤 - -物理层在局部局域网上传送数据帧, 在设备节点传输比特流(数据流). - -``` -光纤 <---> 光纤 -``` - -- 物理层和数据链路层 - - ``` - 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. - ``` - -## 三. 课后作业 - -### 1.讲清楚浏览器地址栏敲下`url`发生了什么? - -首先,域名系统DNS, 将域名(baidu.com)解析为`IP`地址 - -然后,客户端与服务器建立联系 - -其次,客户端正式向服务端发送请求 - -然后,服务端处理请求并返回加过 - -最后,浏览器收到响应后,做响应的渲染 - -### 2.五层协议有哪五层, 举例说明. - -1.应用层 - -举例:浏览网页,网易云,用python模拟请求 - -2.传输层 - -举例:-文件传输(FTP),浏览网页(HTTP) - -3.网络层 - -举例:主机与主机之间的通信,ip协议(公网ip和局域网ip) - -网络层就相当于快递公司庞大的快递网络,全国不同的集散中心,比如说,从深圳发往北京的顺丰快递(陆运为例啊,空运好像直接就飞到北京了),首先要到顺丰的深圳集散中心,从深圳集散中心再送到武汉集散中心,从武汉集散中心再寄到北京顺义集散中心。这个每个集散中心,就相当于网络中的一个IP节点。 - -4.数据链路程 - -举例:网卡与网卡之间的通信 - -5.物理层 - +# 第六周-第一节课:五层协议 + +``` +推荐书籍 <<图解TCP/IP>> +``` + +## 一. 输入网址后发生了什么 + +### 1. 输入`url` + +统一资源定位器`uniform resource locator` + +- `url`组成 + + ``` + https://www.baidu.com/ + 协议://域名[:端口]/路径 + + file:///H:/BaiduNetdiskDownload/ + ``` + +- `url`作用 + + 定位指定的资源. + + > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. + +### 2. DNS解析 + +域名系统`Domain Name System`, 将域名解析为`IP`地址 + +- 域名解析流程 + + 域名(www.baidu.com) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 + +### 3. 客户端与服务器建立连接. + +> 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 + +### 4. 客户端正式向服务端发送请求. + +### 5. 服务端处理请求并返回结果 + +### 6. 浏览器接收到响应后, 做相应的渲染 + +## 二.TCP/IP 五层协议 + +``` +文章链接 https://www.cnblogs.com/xjtu-lyh/p/12416763.html +``` + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223803915-1086885188.png) + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223816759-1375625683.png) + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223858705-1259511194.png) + +### 1. 应用层--使用的应用(网易云,网页等) + +> 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. +> + +``` +举例: +浏览网页 +网易云 +用python模拟请求 +``` + +#### 1.1 应用层协议 + +- HTTP/HTTPS(超文本传输协议) +- DNS(域名系统) +- FTP(文件传输协议,文件下载) +- SMTP(邮箱传输协议) + +### 2. 传输层--四层交换机 + +负责向两个主机应用进程的通信提供服务. + +> 一个主机可以开启不同的应用, 可以同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 + +``` +进程 <---> 进程 +``` + +#### 2.1 传输层协议 + +- TCP(传输控制协议)-- 一对一. + + > 提供面向连接, (尽可能)可靠的数据传输服务. + + ``` + 面向连接指的就是:客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. + ``` + + ``` + eg: + - 文件传输(FTP) + - 浏览网页(HTTP) + ``` + +- UDP(用户数据协议)--一对多, 一对一, 多对多... + + > 提供无连接的, 不保证数据传输的可靠性 + + ``` + eg: + - 直播 + - 实况游戏 + ``` + +### 3. 网络层--路由器 + +决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. + +``` +主机 <---> 主机 +``` + +#### 3.1 网络层协议 + +- IP协议 + + - 公网IP--百度IP + + 也就是指的传统IP地址, 是唯一的. + + ``` + 本机IP: 123.161.218.10河南省郑州市金水区 电信 + ``` + + - 局域网IP + + ``` + 命令行输入:ipconfig + 192.168.1.1 + ``` + +### 4. 数据链路层--网卡 + +负责两台主机之间的数据传输, 向网路层提供数据传输服务 + +``` +网卡 <---> 网卡 +``` + +#### 4.1 数据链路层的作用 + +比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是: 检错和纠错 + +- *流量控制(限速,限流量等) +- 差错检测 +- 差错控制 + +### 5. 物理层--光纤 + +物理层在局部局域网上传送数据帧, 在设备节点传输比特流(数据流). + +``` +光纤 <---> 光纤 +``` + +- 物理层和数据链路层 + + ``` + 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. + ``` + +## 三. 课后作业 + +### 1.讲清楚浏览器地址栏敲下`url`发生了什么? + +首先,域名系统DNS, 将域名(baidu.com)解析为`IP`地址 + +然后,客户端与服务器建立联系 + +其次,客户端正式向服务端发送请求 + +然后,服务端处理请求并返回加过 + +最后,浏览器收到响应后,做响应的渲染 + +### 2.五层协议有哪五层, 举例说明. + +1.应用层 + +举例:浏览网页,网易云,用python模拟请求 + +2.传输层 + +举例:-文件传输(FTP),浏览网页(HTTP) + +3.网络层 + +举例:主机与主机之间的通信,ip协议(公网ip和局域网ip) + +网络层就相当于快递公司庞大的快递网络,全国不同的集散中心,比如说,从深圳发往北京的顺丰快递(陆运为例啊,空运好像直接就飞到北京了),首先要到顺丰的深圳集散中心,从深圳集散中心再送到武汉集散中心,从武汉集散中心再寄到北京顺义集散中心。这个每个集散中心,就相当于网络中的一个IP节点。 + +4.数据链路程 + +举例:网卡与网卡之间的通信 + +5.物理层 + 举例:光纤与光纤之间的通信,快递寄送过程中的交通工具,就相当于我们的物理层,例如汽车,火车,飞机,船。 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2542\350\212\202\350\257\276-TCP\345\222\214IP.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2542\350\212\202\350\257\276-TCP\345\222\214IP.md" index ee1d683bb4060d5890c8db3c4088db19b293cefd..4fb6b65fe58c4a019e31dc985b6852436ae7bd5d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2542\350\212\202\350\257\276-TCP\345\222\214IP.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2542\350\212\202\350\257\276-TCP\345\222\214IP.md" @@ -1,90 +1,90 @@ -# 第六周-第二节课-TCP和IP - -## 一.理解TCP/IP协议 - -### 1.什么是TCP/IP协议 - -`TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. - -### 2.TCP/IP的作用 - -起到了应用和硬件的之间承上启下的作用. - -``` -手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 -``` - -## 二.TCP/IP三次握手 - -> 目的:为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. -> - -![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) - -### 1.三次握手的过程 - -- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 -- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 -- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 - -### 2.第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? - -为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. - -## 三.TCP/IP四次挥手 - -![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) - -### 1.四次挥手的过程 - -``` -我们以客户端作为主动关闭方来描述四次挥手过程 -``` - -- 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 -- 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 -- 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 -- 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 - -## 四.HTTPS - -![](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) - -### 1.https加密的过程 - -- 客户端向服务端发送通信请求 - -- 服务端返回给客户端证书和密钥 - -- 客户端通过CA中心验证证书的真实性 - -- 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. - - - 非对称加密 - - ``` - 16 = 2* 8 也可以是 4 * 4 - 公钥就是拿到了16这个结果 - 私钥就是某个因数2 - 通过这样的方式才可以得出唯一解8 - ``` - -- 服务端收到加密后的请求数据后, 使用私钥进行解密. - -- 服务器和客户端使用**对称加密**进行通信 - -### 2.中间人攻击 - -![](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) - -插入到客户端和服务端之间的通信, 对服务端伪造客户端, 对客户端伪造服务端, 拦截通信产生的数据. - -- 产生的条件 - - 我们的客户端要主动信任中间人的证书 - -## 五.课后作业 - -- 讲述TCP/IP三次握手 -- 讲述TCP/IP四次挥手 +# 第六周-第二节课-TCP和IP + +## 一.理解TCP/IP协议 + +### 1.什么是TCP/IP协议 + +`TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. + +### 2.TCP/IP的作用 + +起到了应用和硬件的之间承上启下的作用. + +``` +手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 +``` + +## 二.TCP/IP三次握手 + +> 目的:为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. +> + +![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) + +### 1.三次握手的过程 + +- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 +- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 +- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 + +### 2.第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? + +为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. + +## 三.TCP/IP四次挥手 + +![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) + +### 1.四次挥手的过程 + +``` +我们以客户端作为主动关闭方来描述四次挥手过程 +``` + +- 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 +- 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 +- 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 +- 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 + +## 四.HTTPS + +![](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) + +### 1.https加密的过程 + +- 客户端向服务端发送通信请求 + +- 服务端返回给客户端证书和密钥 + +- 客户端通过CA中心验证证书的真实性 + +- 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. + + - 非对称加密 + + ``` + 16 = 2* 8 也可以是 4 * 4 + 公钥就是拿到了16这个结果 + 私钥就是某个因数2 + 通过这样的方式才可以得出唯一解8 + ``` + +- 服务端收到加密后的请求数据后, 使用私钥进行解密. + +- 服务器和客户端使用**对称加密**进行通信 + +### 2.中间人攻击 + +![](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) + +插入到客户端和服务端之间的通信, 对服务端伪造客户端, 对客户端伪造服务端, 拦截通信产生的数据. + +- 产生的条件 + + 我们的客户端要主动信任中间人的证书 + +## 五.课后作业 + +- 讲述TCP/IP三次握手 +- 讲述TCP/IP四次挥手 - 讲述HTTPS加密的过程 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2543\350\212\202\350\257\276-\346\212\223\345\214\205\345\222\214\346\250\241\346\213\237\350\257\267\346\261\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2543\350\212\202\350\257\276-\346\212\223\345\214\205\345\222\214\346\250\241\346\213\237\350\257\267\346\261\202.md" index 75f4c78553f147d51f6fae27f0b88ac332d1394e..b3cb7dcb73b2b5d71a3948142a347e2e1e85c914 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2543\350\212\202\350\257\276-\346\212\223\345\214\205\345\222\214\346\250\241\346\213\237\350\257\267\346\261\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\346\231\223\345\256\201/\347\254\2546\345\221\250-\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\2546\345\221\250\347\254\2543\350\212\202\350\257\276-\346\212\223\345\214\205\345\222\214\346\250\241\346\213\237\350\257\267\346\261\202.md" @@ -1,106 +1,106 @@ -# 第6周-第3节课:抓包和模拟请求 - -## 一.抓包 - -> 抓包:其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. -> - -> 对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. -> - -### 1.抓包软件 - -- Fiddler - - ``` - https://www.telerik.com/fiddler - ``` - -- Charles - -- wireshark - -### 2.web端抓包--Fiddler - -> 现代互联网环境几乎都是https协议的网站 -> - -- 信任证书 - - ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) - - ``` - Rules -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -### 3. App端抓包 - -``` -下载夜神模拟器 -``` - -- 打开远程终端连接 - - ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) - - ``` -Rules -> Options -> Connections -> Allow remote computes to connect - ``` - -- 把手机/模拟器的代理指向fiddler - - ``` - - wifi调出设置的时候要长按 - - 查看当前fiddler所在pc本地局域网ip - - ipconfig/ifconfig - ``` -- 在代理项中填写ip地址和fiddler端口, 默认是8888 - -``` - - ``` - -- 信任证书 - -- App有一定的反爬措施, 第一件事就是修改请求协议 - - - 双向验证 - - 需要客户端也带上证书 - -- 解决请求协议上的反爬措施(先有root权限) - - - 安装VirtualXposed_0.18.2, JustTrustMe - -## 二.模拟请求 - -### 1.PostMan简单使用 - -> 软件在云盘保存 - -- GET - -- POST - - - form_data - - 参数表单 - - - x-www-form-urlencoded - - 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 - - - raw - - 请求的真实body内容. - -## 三.课后作业 - -### 1.学会用fiddler抓包https请求 - -### 2.学会用fiddler抓包手机app中的请求 - +# 第6周-第3节课:抓包和模拟请求 + +## 一.抓包 + +> 抓包:其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. +> + +> 对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. +> + +### 1.抓包软件 + +- Fiddler + + ``` + https://www.telerik.com/fiddler + ``` + +- Charles + +- wireshark + +### 2.web端抓包--Fiddler + +> 现代互联网环境几乎都是https协议的网站 +> + +- 信任证书 + + ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) + + ``` + Rules -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +### 3. App端抓包 + +``` +下载夜神模拟器 +``` + +- 打开远程终端连接 + + ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) + + ``` +Rules -> Options -> Connections -> Allow remote computes to connect + ``` + +- 把手机/模拟器的代理指向fiddler + + ``` + - wifi调出设置的时候要长按 + - 查看当前fiddler所在pc本地局域网ip + - ipconfig/ifconfig + ``` +- 在代理项中填写ip地址和fiddler端口, 默认是8888 + +``` + + ``` + +- 信任证书 + +- App有一定的反爬措施, 第一件事就是修改请求协议 + + - 双向验证 + + 需要客户端也带上证书 + +- 解决请求协议上的反爬措施(先有root权限) + + - 安装VirtualXposed_0.18.2, JustTrustMe + +## 二.模拟请求 + +### 1.PostMan简单使用 + +> 软件在云盘保存 + +- GET + +- POST + + - form_data + + 参数表单 + + - x-www-form-urlencoded + + 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 + + - raw + + 请求的真实body内容. + +## 三.课后作业 + +### 1.学会用fiddler抓包https请求 + +### 2.学会用fiddler抓包手机app中的请求 + ### 3.学会使用postman模拟GET, POST请求. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/deco.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/deco.py" index ae431d031d256be7c8741a21a3460e72c1c61467..133bdbc2c86f5f03c71619f161d932a4f04b000d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/deco.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/deco.py" @@ -1,98 +1,98 @@ -#作业先完成,才完美 -#练习作用域之间的转换 -a = 1 -b = [] -c = 5 - -def func1(): - a = 2 - b.append(1) - # UnboundLocalError: local variable 'b' referenced before assignment - # 如果开打下面注释,那么b在函数内赋值,b变成了局部变量。上一行代码就会报错:局部变量b在分配前被引用 - # b = 3 - global c - c = 7 - print(f'func1内的局部变量a = {a}') - print(f'func1内的全局变量b = {b}') - print(f'func1内的全局变量c = {c}') - -def func2(): - b = 3 - # AttributeError: 'int' object has no attribute 'append' - # b在函数内赋值,则b是局部变量且是int对象,int对象没有append属性 - # b.append(1) - print(f'func2内的局部变量b = {b}') - def func3(value): - nonlocal b - b = 10 + value - print(f'func3内的自由变量b = {b}') - return func3 - -func1() -f3 = func2() -f3(1) -print(f'函数体外的全局变量a = {a}') -print(f'函数体外的全局变量b = {b}') -print(f'函数体外的全局变量c = {c}') - - -# 默写一个装饰器, 用来输出函数的执行时间. -import time -# 没有闭包,func函数没法传参 -def func4(func): - start_time = time.time() - func() - end_time = time.time() - print(f"{func.__name__} 函数的执行时间:{format(end_time - start_time, '.2f')} s") - -@func4 -def chengfang(): - count = 0 - while True: - if count >= 20 ** 5: - break - else: - count += 1 -# 此时没有调用chengfang函数或者func4函数,但是依然有该函数执行的print,why? - -# 优化,加上闭包 -def func5(func): - def wrapper(*args, **kwargs): - start_time = time.time() - func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} 函数的执行时间:{format(end_time - start_time, '.2f')} s") - return wrapper - -@func5 -def chengfang1(a, b): - count = 0 - while True: - if count >= a ** b: - break - else: - count += 1 -chengfang1(20, 5) - -# 使用装饰器来为斐波那契函数添加缓存 -def cache_deco(func): - a = {} - def wrapper(n): - if n in a.keys(): - print('在缓存a字典中') - return a[n] - else: - a[n] = func(n) - print('不在缓存a字典中') - return a[n] - return wrapper - -@cache_deco -def fibo(n): - if n == 0 or n == 1: - return n - else: - res = fibo(n - 1) + fibo(n - 2) - return res -print(f"斐波那契函数:{fibo(1)}\n") +#作业先完成,才完美 +#练习作用域之间的转换 +a = 1 +b = [] +c = 5 + +def func1(): + a = 2 + b.append(1) + # UnboundLocalError: local variable 'b' referenced before assignment + # 如果开打下面注释,那么b在函数内赋值,b变成了局部变量。上一行代码就会报错:局部变量b在分配前被引用 + # b = 3 + global c + c = 7 + print(f'func1内的局部变量a = {a}') + print(f'func1内的全局变量b = {b}') + print(f'func1内的全局变量c = {c}') + +def func2(): + b = 3 + # AttributeError: 'int' object has no attribute 'append' + # b在函数内赋值,则b是局部变量且是int对象,int对象没有append属性 + # b.append(1) + print(f'func2内的局部变量b = {b}') + def func3(value): + nonlocal b + b = 10 + value + print(f'func3内的自由变量b = {b}') + return func3 + +func1() +f3 = func2() +f3(1) +print(f'函数体外的全局变量a = {a}') +print(f'函数体外的全局变量b = {b}') +print(f'函数体外的全局变量c = {c}') + + +# 默写一个装饰器, 用来输出函数的执行时间. +import time +# 没有闭包,func函数没法传参 +def func4(func): + start_time = time.time() + func() + end_time = time.time() + print(f"{func.__name__} 函数的执行时间:{format(end_time - start_time, '.2f')} s") + +@func4 +def chengfang(): + count = 0 + while True: + if count >= 20 ** 5: + break + else: + count += 1 +# 此时没有调用chengfang函数或者func4函数,但是依然有该函数执行的print,why? + +# 优化,加上闭包 +def func5(func): + def wrapper(*args, **kwargs): + start_time = time.time() + func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} 函数的执行时间:{format(end_time - start_time, '.2f')} s") + return wrapper + +@func5 +def chengfang1(a, b): + count = 0 + while True: + if count >= a ** b: + break + else: + count += 1 +chengfang1(20, 5) + +# 使用装饰器来为斐波那契函数添加缓存 +def cache_deco(func): + a = {} + def wrapper(n): + if n in a.keys(): + print('在缓存a字典中') + return a[n] + else: + a[n] = func(n) + print('不在缓存a字典中') + return a[n] + return wrapper + +@cache_deco +def fibo(n): + if n == 0 or n == 1: + return n + else: + res = fibo(n - 1) + fibo(n - 2) + return res +print(f"斐波那契函数:{fibo(1)}\n") print(f"斐波那契函数:{fibo(1)}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/function.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/function.py" index 788f2f8e9f82f56b5894583c0384c0a9de5c0aba..e28da8813986009ca37766726be7853d6eea95f1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/function.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/function.py" @@ -1,45 +1,45 @@ -#作业要先完成,才完美 -from pprint import pprint -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -classes.sort(key=lambda x: x.get('grade')) -pprint(f'根据grade来排序的classes={classes}') -print('\n') - -f = filter(lambda x: x.get('grade') == 'A', classes) -pprint(f'通过filter语句来筛选出Grade为A的同学:{list(f)}') -print('\n') - -def addAge(x): - x['age'] = x.get('age') + 1 - return x -m = map(addAge, classes) -pprint(f'通过map函数将上述同学的age + 1之后={list(m)}') -print('\n') - -# 使用递归函数重构斐波那契函数f(n) = f(n-1) + f(n-2) -def fibs(n): - if n == 0 or n == 1: - return n - else: - res = fibs(n - 1) + fibs(n - 2) - if res >= 100: - return None - else: - return res -l = [] -for i in range(100): - res = fibs(i) - if res == None: - break - else: - l.append(res) -print(f'使用递归函数重构100内的斐波那契函数:{l}') - +#作业要先完成,才完美 +from pprint import pprint +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +classes.sort(key=lambda x: x.get('grade')) +pprint(f'根据grade来排序的classes={classes}') +print('\n') + +f = filter(lambda x: x.get('grade') == 'A', classes) +pprint(f'通过filter语句来筛选出Grade为A的同学:{list(f)}') +print('\n') + +def addAge(x): + x['age'] = x.get('age') + 1 + return x +m = map(addAge, classes) +pprint(f'通过map函数将上述同学的age + 1之后={list(m)}') +print('\n') + +# 使用递归函数重构斐波那契函数f(n) = f(n-1) + f(n-2) +def fibs(n): + if n == 0 or n == 1: + return n + else: + res = fibs(n - 1) + fibs(n - 2) + if res >= 100: + return None + else: + return res +l = [] +for i in range(100): + res = fibs(i) + if res == None: + break + else: + l.append(res) +print(f'使用递归函数重构100内的斐波那契函数:{l}') + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/judgment.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/judgment.py" index 40e84e692e3cbd163ed45dae24c65c345a72d23a..9b7a446810955b50b317d652408f21faddd9d5f5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/judgment.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/judgment.py" @@ -1,142 +1,142 @@ -# 作业先完成,才完美 -# 第一题 for:简单计数 -print('第一题 for:简单计数') -l = [1, 2, 3, 4, 5] -for i in l: - print(f'value:{i}') -e = enumerate(l) -for i, e in e: - print(f'index = {i}, value = {e}') - -# 第一题 while:简单计数 -print('第一题 while:简单计数') -count = 0 -while count < 5: - count += 1 - if count == 2: - continue - print(f'count={count}') - -count = 0 -while True: - if count == 5: - break - count += 1 - print(f'count = {count}') - -#第二题 for实现斐波那契函数, 限制在100以内 -print('\n第二题 for实现斐波那契函数, 限制在100以内') -def for_method(n): - l = [0] - for i, e in enumerate(l): - if e >= n: - break - elif i == 0: - l.append(1) - else: - num = l[i] + l[i - 1] - if num >= n: - break - else: - l.append(num) - return l -data = for_method(100) -print(f'for实现100以内的斐波那契数组 = {data}') - -#第二题 while实现斐波那契函数, 限制在100以内 -print('第二题 while实现斐波那契函数, 限制在100以内') -def while_method(n): - l = [0] - while l[len(l) - 1] < n: - if len(l) == 1: - l.append(1) - else: - num = l[len(l) - 1] + l[len(l) - 2] - if num >= n: - break - else: - l.append(num) - return l -data = while_method(100) -print(f'while实现100以内的斐波那契数组 = {data}') - -# 第三题 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError -print('\n第三题:实现的简单计算器') -class ParamsError(Exception): - pass - -#加法 -def add(a, b): - return a + b; -#减法 -def deduce(a, b): - return a - b; -#乘法 -def multip(a, b): - return a * b; -#除法 -def division(a, b): - return a / b; -#整除 -def divide(a, b): - return a // b; -#取余 -def modulo(a, b): - return a % b; -#开方 -def sqrt(a, b): - return a ** (1/b); - -print('***********欢迎使用python简单计算器*********') -def calculator(): - while True: - a = input('请输入第一个数:') - try: - int(a) - except ValueError: - raise ParamsError('输入参数不合法') - b = input('请输入第二个数:') - try: - int(b) - except ValueError: - raise ParamsError('输入参数不合法') - print('请选择计算方法:1、加法; 2、减法; 3、乘法 4、除法 5、整除 6、取余 7、开方') - choose = input('请输入:') - try: - int(choose) - except ValueError: - raise ParamsError('请输入1-7之间的数') - if int(choose) == 1: - c = add(int(a), int(b)) - print(f'{a}+{b}={c}') - elif int(choose) == 2: - c = deduce(int(a), int(b)) - print(f'{a}-{b}={c}') - elif int(choose) == 3: - c = multip(int(a), int(b)) - print(f'{a}*{b}={c}') - elif int(choose) == 4: - try: - c = division(int(a), int(b)) - except ZeroDivisionError: - raise ParamsError('分母不可以为0') - print(f'{a}/{b}={c}') - elif int(choose) == 5: - c = divide(int(a), int(b)) - print(f'{a}//{b}={c}') - elif int(choose) == 6: - c = modulo(int(a), int(b)) - print(f'{a}%{b}={c}') - elif int(choose) == 7: - c = sqrt(int(a), int(b)) - print(f'{a}**{b}={c}') - else: - raise ParamsError('请输入1-7之间的数') - jixu = input('继续请按1,按其他键则程序终止\n') - try: - int(jixu) - except ValueError: - raise ParamsError('程序终止') - if int(jixu) != 1: - break +# 作业先完成,才完美 +# 第一题 for:简单计数 +print('第一题 for:简单计数') +l = [1, 2, 3, 4, 5] +for i in l: + print(f'value:{i}') +e = enumerate(l) +for i, e in e: + print(f'index = {i}, value = {e}') + +# 第一题 while:简单计数 +print('第一题 while:简单计数') +count = 0 +while count < 5: + count += 1 + if count == 2: + continue + print(f'count={count}') + +count = 0 +while True: + if count == 5: + break + count += 1 + print(f'count = {count}') + +#第二题 for实现斐波那契函数, 限制在100以内 +print('\n第二题 for实现斐波那契函数, 限制在100以内') +def for_method(n): + l = [0] + for i, e in enumerate(l): + if e >= n: + break + elif i == 0: + l.append(1) + else: + num = l[i] + l[i - 1] + if num >= n: + break + else: + l.append(num) + return l +data = for_method(100) +print(f'for实现100以内的斐波那契数组 = {data}') + +#第二题 while实现斐波那契函数, 限制在100以内 +print('第二题 while实现斐波那契函数, 限制在100以内') +def while_method(n): + l = [0] + while l[len(l) - 1] < n: + if len(l) == 1: + l.append(1) + else: + num = l[len(l) - 1] + l[len(l) - 2] + if num >= n: + break + else: + l.append(num) + return l +data = while_method(100) +print(f'while实现100以内的斐波那契数组 = {data}') + +# 第三题 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError +print('\n第三题:实现的简单计算器') +class ParamsError(Exception): + pass + +#加法 +def add(a, b): + return a + b; +#减法 +def deduce(a, b): + return a - b; +#乘法 +def multip(a, b): + return a * b; +#除法 +def division(a, b): + return a / b; +#整除 +def divide(a, b): + return a // b; +#取余 +def modulo(a, b): + return a % b; +#开方 +def sqrt(a, b): + return a ** (1/b); + +print('***********欢迎使用python简单计算器*********') +def calculator(): + while True: + a = input('请输入第一个数:') + try: + int(a) + except ValueError: + raise ParamsError('输入参数不合法') + b = input('请输入第二个数:') + try: + int(b) + except ValueError: + raise ParamsError('输入参数不合法') + print('请选择计算方法:1、加法; 2、减法; 3、乘法 4、除法 5、整除 6、取余 7、开方') + choose = input('请输入:') + try: + int(choose) + except ValueError: + raise ParamsError('请输入1-7之间的数') + if int(choose) == 1: + c = add(int(a), int(b)) + print(f'{a}+{b}={c}') + elif int(choose) == 2: + c = deduce(int(a), int(b)) + print(f'{a}-{b}={c}') + elif int(choose) == 3: + c = multip(int(a), int(b)) + print(f'{a}*{b}={c}') + elif int(choose) == 4: + try: + c = division(int(a), int(b)) + except ZeroDivisionError: + raise ParamsError('分母不可以为0') + print(f'{a}/{b}={c}') + elif int(choose) == 5: + c = divide(int(a), int(b)) + print(f'{a}//{b}={c}') + elif int(choose) == 6: + c = modulo(int(a), int(b)) + print(f'{a}%{b}={c}') + elif int(choose) == 7: + c = sqrt(int(a), int(b)) + print(f'{a}**{b}={c}') + else: + raise ParamsError('请输入1-7之间的数') + jixu = input('继续请按1,按其他键则程序终止\n') + try: + int(jixu) + except ValueError: + raise ParamsError('程序终止') + if int(jixu) != 1: + break calculator() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/list.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/list.py" index 27dfde3ee47fe67a5140bf9f16bc353c59826c0e..37e01f71cd30d2bba6cf9806b3ad791f56c04e93 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/list.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/list.py" @@ -1,87 +1,87 @@ -#List的create -l = [{'a': 1}] -print(l) -l.append((1,)) -print(l) -l += [{'a', 'b'}] -print(l) -l *= 2 -print(l) -l.insert(3, '分割一下') -print(l) -#List的retrieve -print(l[3]) -print(l[0:3]) -print(l[-1]) -print(l[0:len(l):1]) -#List的update -l[3] = ['分割一下下'] -print(l) -l[0:3]='换头部' -print(l) -l.pop() -print(l) -l.clear() -print(l) -#List的排序 -l = ['b', 'a', 'd', 'c'] -l.sort() -print(l) -l.reverse() -print(l) -sorted(l) -print(l) - -#tuple(不可更改,所以只能查) -t = (1, 2) -print(t[1]) - -#dict的create -d = {'a': 1} -print(d) -d['b'] = 2 -print(d) -d2 = {'c': 3} -d.update(d2) -print(d) -d.setdefault('a', 0) -d.setdefault('d', 0) -print(d) -#dict的retrieve -print(d['a']) -print(d.get('e', -1)) -print(list(d.keys())) -print(list(d.values())) -print(d.items()) -#dict的update -d.update({'a': 0,'e': 4}) -print(d) -#dict的delete -d.pop('e') -print(d) -d.popitem() -print(d) -d.clear() -print(d) - -#set的create -s = {'a'} -print(s) -s.add('b') -print(s) -s.update('c') -print(s) -#set的retrieve -print('a' in s) -#set的update -s_1 = {'d'} -s_2 = s.union(s_1) -print(s) -print(s_2) -#set的delete -# s.remove('a') -# print(s) -s.discard('b') -print(s) -s.pop() +#List的create +l = [{'a': 1}] +print(l) +l.append((1,)) +print(l) +l += [{'a', 'b'}] +print(l) +l *= 2 +print(l) +l.insert(3, '分割一下') +print(l) +#List的retrieve +print(l[3]) +print(l[0:3]) +print(l[-1]) +print(l[0:len(l):1]) +#List的update +l[3] = ['分割一下下'] +print(l) +l[0:3]='换头部' +print(l) +l.pop() +print(l) +l.clear() +print(l) +#List的排序 +l = ['b', 'a', 'd', 'c'] +l.sort() +print(l) +l.reverse() +print(l) +sorted(l) +print(l) + +#tuple(不可更改,所以只能查) +t = (1, 2) +print(t[1]) + +#dict的create +d = {'a': 1} +print(d) +d['b'] = 2 +print(d) +d2 = {'c': 3} +d.update(d2) +print(d) +d.setdefault('a', 0) +d.setdefault('d', 0) +print(d) +#dict的retrieve +print(d['a']) +print(d.get('e', -1)) +print(list(d.keys())) +print(list(d.values())) +print(d.items()) +#dict的update +d.update({'a': 0,'e': 4}) +print(d) +#dict的delete +d.pop('e') +print(d) +d.popitem() +print(d) +d.clear() +print(d) + +#set的create +s = {'a'} +print(s) +s.add('b') +print(s) +s.update('c') +print(s) +#set的retrieve +print('a' in s) +#set的update +s_1 = {'d'} +s_2 = s.union(s_1) +print(s) +print(s_2) +#set的delete +# s.remove('a') +# print(s) +s.discard('b') +print(s) +s.pop() print(s) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/my_calculator.py" index 932dc1850c6df6a86551938323f01d056975db86..e1f86073aeced6bbca093269798982a610beee5c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/my_calculator.py" @@ -1,35 +1,35 @@ -#加法 -def add(a, b): - return a + b; - -#减法 -def deduce(a, b): - return a - b; - -#乘法 -def multip(a, b): - return a * b; - -#除法 -def division(a, b): - return a / b; - -#整除 -def divide(a, b): - return a // b; - -#取余 -def modulo(a, b): - return a % b; - -#开方 -def sqrt(a, b): - return a ** (1/b); - -print('1+2=', add(1, 2)) -print('1-2=', deduce(1, 2)) -print('1*2=', multip(1, 2)) -print('1/2=', division(1, 2)) -print('1//2=', divide(1, 2)) -print('1%2=', modulo(1, 2)) +#加法 +def add(a, b): + return a + b; + +#减法 +def deduce(a, b): + return a - b; + +#乘法 +def multip(a, b): + return a * b; + +#除法 +def division(a, b): + return a / b; + +#整除 +def divide(a, b): + return a // b; + +#取余 +def modulo(a, b): + return a % b; + +#开方 +def sqrt(a, b): + return a ** (1/b); + +print('1+2=', add(1, 2)) +print('1-2=', deduce(1, 2)) +print('1*2=', multip(1, 2)) +print('1/2=', division(1, 2)) +print('1//2=', divide(1, 2)) +print('1%2=', modulo(1, 2)) print('27开3次方=', sqrt(27, 3)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/str_operation.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/str_operation.py" index 1d1c2b0c9432096b92a04676fcfe3a4bf9cd3ef9..6ab1a11d5a337a359dc1b2cb902458842b2981e7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/str_operation.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/str_operation.py" @@ -1,33 +1,33 @@ -content = ''' -a = 'hello世界'; b = a.encode('utf-8'); c = b.decode('utf-8'); print('a = {}, b = {}, c = {}'.format(a, b, c)) -a = hello世界, b = b'hello\xe4\xb8\x96\xe7\x95\x8c', c = hello世界 -a = '你好'; b = 'world'; c = a + b; print('a = {a}, b = {b}, c = {c}') -a = {a}, b = {b}, c = {c} -print(f'a = {a}, b = {b}, c = {c}') -a = 你好, b = world, c = 你好world -a += b;print('a = {0}, b = {1}'.format(a, b)) -a = 你好world, b = world -a[3] -'o' -a.find('o') -3 -b = a.replace('w', ',w');print('a = {0}, b = {1}'.format(a, b)) -a = 你好world, b = 你好,world -b = b.replace('你好', ' ,你好'); c = b.replace('world', 'world '); print('a = %s, b = %s'.format(a, b)) -a = %s, b = %s -b = b.replace('你好', ' ,你好'); c = b.replace('world', 'world '); print('a = %s, b = %s' % (a, b)) -a = 你好world, b = , ,你好,world -b.strip(); print(b) - , ,你好,world -b.split(','); print(b) - , ,你好,world -a = b.split(','); print('a = {a}, b = {b}') -a = {a}, b = {b} -print(f'a = {a}, b = {b}') -a = [' ', ' ', '你好', 'world'], b = , ,你好,world -a = ','.join(a); print(f'a = {a}') -a = , ,你好,world -''' -output = open('output.txt', 'w', encoding='utf-8') -output.write(content) +content = ''' +a = 'hello世界'; b = a.encode('utf-8'); c = b.decode('utf-8'); print('a = {}, b = {}, c = {}'.format(a, b, c)) +a = hello世界, b = b'hello\xe4\xb8\x96\xe7\x95\x8c', c = hello世界 +a = '你好'; b = 'world'; c = a + b; print('a = {a}, b = {b}, c = {c}') +a = {a}, b = {b}, c = {c} +print(f'a = {a}, b = {b}, c = {c}') +a = 你好, b = world, c = 你好world +a += b;print('a = {0}, b = {1}'.format(a, b)) +a = 你好world, b = world +a[3] +'o' +a.find('o') +3 +b = a.replace('w', ',w');print('a = {0}, b = {1}'.format(a, b)) +a = 你好world, b = 你好,world +b = b.replace('你好', ' ,你好'); c = b.replace('world', 'world '); print('a = %s, b = %s'.format(a, b)) +a = %s, b = %s +b = b.replace('你好', ' ,你好'); c = b.replace('world', 'world '); print('a = %s, b = %s' % (a, b)) +a = 你好world, b = , ,你好,world +b.strip(); print(b) + , ,你好,world +b.split(','); print(b) + , ,你好,world +a = b.split(','); print('a = {a}, b = {b}') +a = {a}, b = {b} +print(f'a = {a}, b = {b}') +a = [' ', ' ', '你好', 'world'], b = , ,你好,world +a = ','.join(a); print(f'a = {a}') +a = , ,你好,world +''' +output = open('output.txt', 'w', encoding='utf-8') +output.write(content) output.close(); \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/parser_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/parser_test.py" deleted file mode 100644 index e1ede806179eec2ecaac9ad348f7cd50efb74efa..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/parser_test.py" +++ /dev/null @@ -1,13 +0,0 @@ -# 作业先完成,再完美 -import sys -import os -print(f'os:{os.getcwd()}') -sys.path.append(os.getcwd()) -print(sys.path) -from jd_parser.search import parse_jd_item - - -with open(r"test\search.html", "r", encoding="utf-8") as f: - html = f.read() - result = parse_jd_item(html) - print(result) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\345\220\257\345\212\250\351\241\271\347\233\256.jpg" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\345\220\257\345\212\250\351\241\271\347\233\256.jpg" deleted file mode 100644 index 926ac474cc5b1385a6660471164910ee6aed23d6..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\345\220\257\345\212\250\351\241\271\347\233\256.jpg" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__init__.py" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/__init__.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/__init__.cpython-36.pyc" deleted file mode 100644 index d4a1ca5efb32428fb0852abd80ac94d91490bb52..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/__init__.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/items.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/items.cpython-36.pyc" deleted file mode 100644 index dbfa6959d1427148a244c378c0b4ebc01ed31401..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/items.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/middlewares.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/middlewares.cpython-36.pyc" deleted file mode 100644 index 30de2b0cf87c14b953daebfdcfa16c449a29dadb..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/middlewares.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/pipelines.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/pipelines.cpython-36.pyc" deleted file mode 100644 index 9480924d60047ba969eea67cc864471893e06e30..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/pipelines.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/settings.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/settings.cpython-36.pyc" deleted file mode 100644 index 3351c9260f5da9a02087056956172f84d0dfcd1b..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/__pycache__/settings.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/items.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/items.py" deleted file mode 100644 index 4fa4c7582ea77b48be3277b1e8f6c06d4b1ea0be..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/items.py" +++ /dev/null @@ -1,17 +0,0 @@ -# Define here the models for your scraped items -# -# See documentation in: -# https://docs.scrapy.org/en/latest/topics/items.html - -import scrapy - - -class JdCrawlerScrapyItem(scrapy.Item): - # define the fields for your item here like: - # name = scrapy.Field() - sku_id = scrapy.Field() - img = scrapy.Field() - price = scrapy.Field() - title = scrapy.Field() - shop = scrapy.Field() - icons = scrapy.Field() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/middlewares.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/middlewares.py" deleted file mode 100644 index adcb8603b62bd884290c16b447a6d0f5eda5be7e..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/middlewares.py" +++ /dev/null @@ -1,114 +0,0 @@ -# Define here the models for your spider middleware -# -# See documentation in: -# https://docs.scrapy.org/en/latest/topics/spider-middleware.html - -from scrapy import signals - -# useful for handling different item types with a single interface -from itemadapter import is_item, ItemAdapter - - -class JdCrawlerScrapySpiderMiddleware: - # Not all methods need to be defined. If a method is not defined, - # scrapy acts as if the spider middleware does not modify the - # passed objects. - - @classmethod - def from_crawler(cls, crawler): - # This method is used by Scrapy to create your spiders. - s = cls() - crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) - return s - - def process_spider_input(self, response, spider): - # Called for each response that goes through the spider - # middleware and into the spider. - - # Should return None or raise an exception. - return None - - def process_spider_output(self, response, result, spider): - # Called with the results returned from the Spider, after - # it has processed the response. - - # Must return an iterable of Request, or item objects. - for i in result: - yield i - - def process_spider_exception(self, response, exception, spider): - # Called when a spider or process_spider_input() method - # (from other spider middleware) raises an exception. - - # Should return either None or an iterable of Request or item objects. - pass - - def process_start_requests(self, start_requests, spider): - # Called with the start requests of the spider, and works - # similarly to the process_spider_output() method, except - # that it doesn’t have a response associated. - - # Must return only requests (not items). - for r in start_requests: - yield r - - def spider_opened(self, spider): - spider.logger.info('Spider opened: %s' % spider.name) - - -class JdCrawlerScrapyDownloaderMiddleware: - # Not all methods need to be defined. If a method is not defined, - # scrapy acts as if the downloader middleware does not modify the - # passed objects. - - @classmethod - def from_crawler(cls, crawler): - # This method is used by Scrapy to create your spiders. - s = cls() - crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) - return s - - def process_request(self, request, spider): - # Called for each request that goes through the downloader - # middleware. - - # Must either: - # - return None: continue processing this request - # - or return a Response object - # - or return a Request object - # - or raise IgnoreRequest: process_exception() methods of - # installed downloader middleware will be called - return None - - def process_response(self, request, response, spider): - # Called with the response returned from the downloader. - - # Must either; - # - return a Response object - # - return a Request object - # - or raise IgnoreRequest - return response - - def process_exception(self, request, exception, spider): - # Called when a download handler or a process_request() - # (from other downloader middleware) raises an exception. - - # Must either: - # - return None: continue processing this exception - # - return a Response object: stops process_exception() chain - # - return a Request object: stops process_exception() chain - pass - - def spider_opened(self, spider): - spider.logger.info('Spider opened: %s' % spider.name) - -class UAMiddleware: - # 添加请求头 - def process_request(self, request, spider): - request.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" - -class ProxyMiddleware: - # 代理中间件 - def process_request(self, request, spider): - request.proxies = spider.settings["PROXIES"] - diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/pipelines.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/pipelines.py" deleted file mode 100644 index fe4752839723b3c23e725e7f8690e0288f49307b..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/pipelines.py" +++ /dev/null @@ -1,30 +0,0 @@ -# Define your item pipelines here -# -# Don't forget to add your pipeline to the ITEM_PIPELINES setting -# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html - - -# useful for handling different item types with a single interface -from itemadapter import ItemAdapter -from jd_crawler_scrapy.items import JdCrawlerScrapyItem -import pymysql - - -class JdCrawlerScrapyPipeline: - def __init__(self): - self.mysql_con = None - - def process_item(self, item, spider): - if not self.mysql_con: - self.mysql_con = pymysql.connect(**spider.settings["DB_CONFIG"]) - - if isinstance(item, JdCrawlerScrapyItem): - cursor = self.mysql_con.cursor() - SQL = """insert into jd_search(sku_id, img, price, title, shop, icons) - VALUES ('{}', '{}', '{}', '{}', '{}', '{}')""".format( - item['sku_id'], item['img'],item['price'],item['title'],item['shop'],item['icons'] - ) - cursor.execute(SQL) - self.mysql_con.commit() - cursor.close() - return item diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/settings.py" deleted file mode 100644 index d59d78eccb80f07a0baf573ce4ed5c34953dcb85..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/settings.py" +++ /dev/null @@ -1,103 +0,0 @@ -# Scrapy settings for jd_crawler_scrapy project -# -# For simplicity, this file contains only settings considered important or -# commonly used. You can find more settings consulting the documentation: -# -# https://docs.scrapy.org/en/latest/topics/settings.html -# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html -# https://docs.scrapy.org/en/latest/topics/spider-middleware.html - -BOT_NAME = 'jd_crawler_scrapy' - -SPIDER_MODULES = ['jd_crawler_scrapy.spiders'] -NEWSPIDER_MODULE = 'jd_crawler_scrapy.spiders' - - -# Crawl responsibly by identifying yourself (and your website) on the user-agent -#USER_AGENT = 'jd_crawler_scrapy (+http://www.yourdomain.com)' - -# Obey robots.txt rules -ROBOTSTXT_OBEY = False - -# Configure maximum concurrent requests performed by Scrapy (default: 16) -#CONCURRENT_REQUESTS = 32 - -# Configure a delay for requests for the same website (default: 0) -# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay -# See also autothrottle settings and docs -#DOWNLOAD_DELAY = 3 -# The download delay setting will honor only one of: -#CONCURRENT_REQUESTS_PER_DOMAIN = 16 -#CONCURRENT_REQUESTS_PER_IP = 16 - -# Disable cookies (enabled by default) -#COOKIES_ENABLED = False - -# Disable Telnet Console (enabled by default) -#TELNETCONSOLE_ENABLED = False - -# Override the default request headers: -#DEFAULT_REQUEST_HEADERS = { -# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', -# 'Accept-Language': 'en', -#} - -# Enable or disable spider middlewares -# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html -#SPIDER_MIDDLEWARES = { -# 'jd_crawler_scrapy.middlewares.JdCrawlerScrapySpiderMiddleware': 543, -#} - -# Enable or disable downloader middlewares -# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html -DOWNLOADER_MIDDLEWARES = { - # 'jd_crawler_scrapy.middlewares.JdCrawlerScrapyDownloaderMiddleware': 543, - 'jd_crawler_scrapy.middlewares.UAMiddleware': 100, - 'jd_crawler_scrapy.middlewares.ProxyMiddleware': 101, -} - -# Enable or disable extensions -# See https://docs.scrapy.org/en/latest/topics/extensions.html -#EXTENSIONS = { -# 'scrapy.extensions.telnet.TelnetConsole': None, -#} - -# Configure item pipelines -# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html -ITEM_PIPELINES = { - 'jd_crawler_scrapy.pipelines.JdCrawlerScrapyPipeline': 300, -} - -# Enable and configure the AutoThrottle extension (disabled by default) -# See https://docs.scrapy.org/en/latest/topics/autothrottle.html -#AUTOTHROTTLE_ENABLED = True -# The initial download delay -#AUTOTHROTTLE_START_DELAY = 5 -# The maximum download delay to be set in case of high latencies -#AUTOTHROTTLE_MAX_DELAY = 60 -# The average number of requests Scrapy should be sending in parallel to -# each remote server -#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 -# Enable showing throttling stats for every response received: -#AUTOTHROTTLE_DEBUG = False - -# Enable and configure HTTP caching (disabled by default) -# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings -#HTTPCACHE_ENABLED = True -#HTTPCACHE_EXPIRATION_SECS = 0 -#HTTPCACHE_DIR = 'httpcache' -#HTTPCACHE_IGNORE_HTTP_CODES = [] -#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' -DB_CONFIG = { - 'host': 'localhost', - 'user': 'root', - 'password': 'chlbeyond', - 'database': 'tunan_class' -} - -LOG_FILE = "G:/log/jd_search.log" -LOG_LEVEL = "ERROR" - -PROXIES = [ - "http://165.225.210.96:10605" -] \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__init__.py" deleted file mode 100644 index ebd689ac51d69c5e1dbbe80083c2b20a39f8bb79..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__init__.py" +++ /dev/null @@ -1,4 +0,0 @@ -# This package will contain the spiders of your Scrapy project -# -# Please refer to the documentation for information on how to create and manage -# your spiders. diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/__init__.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/__init__.cpython-36.pyc" deleted file mode 100644 index f5cda7b53f9c27c349f9fec836452486eb467afd..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/__init__.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/js_search.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/js_search.cpython-36.pyc" deleted file mode 100644 index eecd1acf5e3569217de4c979032f70176d1edcb1..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/js_search.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/run.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/run.cpython-36.pyc" deleted file mode 100644 index 00ea3e640267491444864bc75104d00c9ccd0167..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/__pycache__/run.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/js_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/js_search.py" deleted file mode 100644 index 0128f778a9abadd9c67900db674c91df75b7f4a3..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/js_search.py" +++ /dev/null @@ -1,57 +0,0 @@ -# 作业先完成,再完美 -import scrapy -from bs4 import BeautifulSoup -import json - -from jd_crawler_scrapy.items import JdCrawlerScrapyItem - -# name是必须的,以name为依据来启动(这种命令行启动无法debug): -# 进入项目根目录:cd G:\PythonProject\second-python-bootcamp\第二期训练营\2班\2班_陈生\week10\第二节作业\jd_crawler_scrapy -# 输入:scrapy crawl jd_search -# 此处就是 jd_search 的作用 -class JdSearch(scrapy.Spider): - name = "jd_search" - - # 内置的方法,覆写 - def start_requests(self): - for keyword in ['鼠标', '键盘', '显示器', '硬盘']: - for page in range(1, 11): - url = f"https://search.jd.com/Search?keyword={keyword}&page={page}" - # FormRequest可以post和get,Request只能get - yield scrapy.FormRequest( - url=url, - method='GET', - # formdata=data, #post请求体 - callback=self.parse_search - ) - break - - def parse_search(self, response): - # print(response) - soup = BeautifulSoup(response.text, 'lxml') - item_array = soup.select('ul[class="gl-warp clearfix"] li[class="gl-item"]') - for item in item_array: - try: - sku_id = item.attrs['data-sku'] - img = item.select('div[class="p-img"] img[data-img="1"]') - price = item.select('div[class="p-price"] i') - title = item.select('div[class="p-name p-name-type-2"]') - shop = item.select('div[class="p-shop"] a') - icons = item.select('div[class="p-icons"] i') - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].text if price else "" - title = title[0].text if title else "" - shop = shop[0].attrs['title'] if shop else "" - icons = json.dumps([icon.text for icon in icons]) if icons else "[]" - - item = JdCrawlerScrapyItem() - item["sku_id"] = sku_id - item["img"] = img - item["price"] = price - item["title"] = title - item["shop"] = shop - item["icons"] = icons - yield item - except Exception as e: - print(e.args) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/run.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/run.py" deleted file mode 100644 index bf56bf033813be4446619ec1e06b3adc95e3eeb7..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/jd_crawler_scrapy/spiders/run.py" +++ /dev/null @@ -1,7 +0,0 @@ -# 作业先完成,再完美 -# 项目内使用cmdline不会有路径问题 -from scrapy import cmdline - -command = "scrapy crawl jd_search".split() - -cmdline.execute(command) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/scrapy.cfg" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/scrapy.cfg" deleted file mode 100644 index b6086855c9bbe4b6c4c9381fdc30da8031610cde..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week10/\347\254\254\344\272\214\344\270\211\350\212\202\344\275\234\344\270\232/jd_crawler_scrapy/scrapy.cfg" +++ /dev/null @@ -1,11 +0,0 @@ -# Automatically created by: scrapy startproject -# -# For more information about the [deploy] section see: -# https://scrapyd.readthedocs.io/en/latest/deploy.html - -[settings] -default = jd_crawler_scrapy.settings - -[deploy] -#url = http://localhost:6800/ -project = jd_crawler_scrapy diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/search.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/search.cpython-36.pyc" deleted file mode 100644 index 048dfb1d4b397ad1d650a2207c6dd9077ef25241..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/search.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/settings.cpython-36.pyc" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/settings.cpython-36.pyc" deleted file mode 100644 index 1f82a5dcafd05ace345761d2a4b8af5353890e5a..0000000000000000000000000000000000000000 Binary files "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/__pycache__/settings.cpython-36.pyc" and /dev/null differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" index b081365e6f1c11a816b0a94ccd5bbdd6c4ef6161..8b947e75aa1ec69c4902725028e301cf09b3a2d8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" @@ -1,60 +1,15 @@ # 作业先完成,再完美 import requests -import pymysql -from settings import HEADERS, DB_CONFIG -from search import parse_jd_item - -from threading import Thread -from multiprocessing import Process +# from search import parse_jd_item def saver(item_array): - cursor = db_con.cursor() - SQL = """insert into jd_search(sku_id, img, price, title, shop, icons) - VALUES (%s, %s, %s, %s, %s, %s)""" - cursor.executemany(SQL, item_array) - db_con.commit() - cursor.close() + pass -def downloader(task, result): - params = { - "url": "https://search.jd.com/Search", - "params": {"keyword": task}, - "headers": HEADERS, - } - response = requests.get(**params) - result.append(response) - # return response +def downloader(task): + pass def main(task_array): - result_thread = [] - result_process = [] - thread_list = [] - process_list = [] - - for task in task_array: - my_thread = Thread(target=downloader, args=(task, result_thread)) - thread_list.append(my_thread) - my_thread.start() - - my_process = Process(target=downloader, args=(task, result_process)) - process_list.append(my_process) - my_process.start() - - for i in thread_list: - i.join() - for response in result_thread: - item = parse_jd_item(response.text) - print(item) - saver(item) - - for i in process_list: - i.join() - for response in result_process: - item = parse_jd_item(response.text) - print(item) - saver(item) + pass if __name__ == '__main__': - db_con = pymysql.connect(**DB_CONFIG) - task_array = ['鼠标', '键盘', '显示器', '硬盘'] - main(task_array) + pass \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/search.py" index 1c1b911493fff743451cad37f6cc894beb988af9..f966c94b93f0cbb90267892a2217b3427d30dedd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/search.py" @@ -1,31 +1,4 @@ # 作业先完成,再完美 -from bs4 import BeautifulSoup -import json -# sku_id, img, price, title, shop, icons def parse_jd_item(html): - result = [] - html = html.replace('\r\n', '').replace('\n', '').replace('\t', '') - soup = BeautifulSoup(html, 'lxml') - item_array = soup.select('ul[class="gl-warp clearfix"] li[class="gl-item"]') - for item in item_array: - sku_id = item.attrs['data-sku'] - img = item.select('div[class="p-img"] img[data-img="1"]') - price = item.select('div[class="p-price"] i') - title = item.select('div[class="p-name p-name-type-2"]') - shop = item.select('div[class="p-shop"] a') - icons = item.select('div[class="p-icons"] i') - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].text if price else "" - title = title[0].text if title else "" - shop = shop[0].attrs['title'] if shop else "" - icons = json.dumps([icon.text for icon in icons]) if icons else "[]" - - result.append((sku_id, img, price, title, shop, icons)) - return result - -if __name__ == '__main__': - with open(r"F:\Python\pythonProject\second-python-bootcamp\第二期训练营\2班\2班_陈生\week9\第二节作业\jd_search.html", 'r', encoding='utf-8') as f: - result = parse_jd_item(f.read()) - print(result) + pass diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/settings.py" deleted file mode 100644 index 4c261e079333454fff05b1259f86d4eab7e4aa49..0000000000000000000000000000000000000000 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/week9/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/settings.py" +++ /dev/null @@ -1,11 +0,0 @@ -# 作业先完成,再完美 -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" -} - -DB_CONFIG = { - 'host': 'localhost', - 'user': 'root', - 'password': 'chlbeyond', - 'database': 'tunan_class' -} \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/\347\254\254\344\270\200\345\222\214\347\254\254\344\272\214\351\242\230" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/\347\254\254\344\270\200\345\222\214\347\254\254\344\272\214\351\242\230" index ae587b673f27b9d664f443882018770b15ac3fa6..f14fb40f33174c8409ebc522aea9623088024314 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/\347\254\254\344\270\200\345\222\214\347\254\254\344\272\214\351\242\230" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_\351\231\210\347\224\237/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/\347\254\254\344\270\200\345\222\214\347\254\254\344\272\214\351\242\230" @@ -1,5 +1,5 @@ -问:四大基本数据结构中哪些是可变的, 哪些是不可变的? -答:可变:list、dict、set; 不可变:tuple。 - -问:四大基本数据结构中哪些是有序的, 哪些是无序的? +问:四大基本数据结构中哪些是可变的, 哪些是不可变的? +答:可变:list、dict、set; 不可变:tuple。 + +问:四大基本数据结构中哪些是有序的, 哪些是无序的? 答:有序:list、tuple; 无序:dict、set。 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/work.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/work.py" index c58bfb60d51c459fe5398388db0a5462766aa716..853ec9bc31a67efbdfbf1453ce6612dee045c66d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/work.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202/work.py" @@ -1,8 +1,8 @@ -list1=[1,2.2,'Sunday',b'Hello World',True,None] -print(list1) -tuple1=(1,2.2,'Sunday',b'Hello World',True,None) -print(tuple1) -dict1={'a':1,'b':2.2,'c':'Sunday','d':b'Hello World','e':True,'f':None} -print(dict1) -set1={1,2.2,'Sunday',b'Hello World',True,None} -print(set1) +list1=[1,2.2,'Sunday',b'Hello World',True,None] +print(list1) +tuple1=(1,2.2,'Sunday',b'Hello World',True,None) +print(tuple1) +dict1={'a':1,'b':2.2,'c':'Sunday','d':b'Hello World','e':True,'f':None} +print(dict1) +set1={1,2.2,'Sunday',b'Hello World',True,None} +print(set1) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" index 8adf39abb02ce6df80e7c223aa91d6dd17ee8e04..1eb52abd5294255aab61315313da0bb4dcc08d78 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_DDDDian/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py" @@ -1,62 +1,62 @@ -def add(x, y): - return x + y - - -def subtract(x, y): - return x - y - - -def multiply(x, y): - return x * y - - -def devide(x, y): - return x/y - - -def devide_int(x, y): - return x//y - - -def sqrt(x): - return x**0.5 - - -print("欢迎使用计算器") -print("1、加法") -print("2、减法") -print("3、乘法") -print("4、除法") -print("5、整除") -print("6、开方") - - -choice=input("请选择您要进行的运算(输入数字1-6):") -print("开始计算") - - -num1=int(input("请输入第一个数字:")) -num2=int(input("请输入第二个数字:")) - - -if choice == '1': - print(num1, "+", num2, "=", add(num1, num2)) - -elif choice == '2': - print(num1, "-", num2, "=", subtract(num1, num2)) - -elif choice == '3': - print(num1, "*", num2, "=", multiply(num1, num2)) - -elif choice == '4': - print(num1, "/", num2, "=", devide(num1, num2)) - -elif choice == '5': - print(num1, "//", num2, "=", devide_int(num1, num2)) - -elif choice == '6': - print(num1, "**0.5", "=", sqrt(num1)) - print(num2, "**0.5", "=", sqrt(num2)) - -else: +def add(x, y): + return x + y + + +def subtract(x, y): + return x - y + + +def multiply(x, y): + return x * y + + +def devide(x, y): + return x/y + + +def devide_int(x, y): + return x//y + + +def sqrt(x): + return x**0.5 + + +print("欢迎使用计算器") +print("1、加法") +print("2、减法") +print("3、乘法") +print("4、除法") +print("5、整除") +print("6、开方") + + +choice=input("请选择您要进行的运算(输入数字1-6):") +print("开始计算") + + +num1=int(input("请输入第一个数字:")) +num2=int(input("请输入第二个数字:")) + + +if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + +elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + +elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + +elif choice == '4': + print(num1, "/", num2, "=", devide(num1, num2)) + +elif choice == '5': + print(num1, "//", num2, "=", devide_int(num1, num2)) + +elif choice == '6': + print(num1, "**0.5", "=", sqrt(num1)) + print(num2, "**0.5", "=", sqrt(num2)) + +else: print("Error") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/test crud.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/test crud.py" index 17f71e31f57976bd559c0a6f7adf969e141c7d3c..0771d53903aa0b6ee0e4dfce16dcccca66d30691 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/test crud.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/test crud.py" @@ -1,39 +1,39 @@ -#编码 -b = '名字'.encode("utf-8") -print(b) -#解码 -a = b.decode("utf-8") -print(a) -#Create -c = "c" -d = "d" -c = c+d -print(c) -#retrieve -F = "be careful" -print(F[1]) -print(F.find("b")) -print(F.startswith('be')) -print(F.endswith('careful')) -#update -E = "A,B,C,D" -print(E.replace('A','B')) -print(E.split(',')) -E = E.split(',') -print(','.join(E)) -#DELETE -G =' haha ' -print(G.strip()) -print(G.rstrip()) -#格式化输出 -H = '哈' -I = '喽' -print('say{}{}'.format(H,I)) -print('say{0}{1}'.format(H,I)) -print(f"say{H}{I}") -print("say %s%s" % (H, I)) -#小数表示 -print("{:.2f}".format(3.141121212121)) - - -output = open("output") +#编码 +b = '名字'.encode("utf-8") +print(b) +#解码 +a = b.decode("utf-8") +print(a) +#Create +c = "c" +d = "d" +c = c+d +print(c) +#retrieve +F = "be careful" +print(F[1]) +print(F.find("b")) +print(F.startswith('be')) +print(F.endswith('careful')) +#update +E = "A,B,C,D" +print(E.replace('A','B')) +print(E.split(',')) +E = E.split(',') +print(','.join(E)) +#DELETE +G =' haha ' +print(G.strip()) +print(G.rstrip()) +#格式化输出 +H = '哈' +I = '喽' +print('say{}{}'.format(H,I)) +print('say{0}{1}'.format(H,I)) +print(f"say{H}{I}") +print("say %s%s" % (H, I)) +#小数表示 +print("{:.2f}".format(3.141121212121)) + + +output = open("output") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\345\233\233\345\244\247\347\273\223\346\236\204CRUD.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\345\233\233\345\244\247\347\273\223\346\236\204CRUD.py" index 48352af5873acce89b5514cf07132bcc489c40ba..a19d88e7e9a5afc4652bbea57eaba620bf6b500b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\345\233\233\345\244\247\347\273\223\346\236\204CRUD.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\345\233\233\345\244\247\347\273\223\346\236\204CRUD.py" @@ -1,73 +1,73 @@ -#create -add = [] -add.append("a") -print(add) -add = add+["b"] -print(add) -add*=10 -print(add) -add.insert(0,"b") -print(add) -print(add[1],add[2]) -#R -R = list(range(100)) -print(R) -print(R[1:10]) -print(R[1:10:2]) -R = ['a', 'b', 'c'] -print(R.index('a')) -#U -U = list(range(10)) -U[1]= '2' -print(U) -U[0:5] = "3" -print(U) -#D -D = list(range(10)) -print(D.pop()) -print(D.clear()) - -#tuple -#Retrieve -R = tuple(range(10)) -print(R.index(1)) -print(R[1:5]) - -#dict -#C -C_1 = {"a":1} -C_2 = {"b":2,"c":3} -C_1.update(C_2) -print(C_1) -#R -R = {"a":1,"b":2,"c":3} -print(R.get('a')) -print(R.keys()) -print(R.values()) -print(R.items()) -#U -U ={"a":1,"b":2,"c":3} -U['a']=10 -print(U.get("a")) -U.update({"b":20,'c':30}) -print(U) -#D -D = {"a": 1, "b": 2, "c": 3} -print(D.pop("a")) -#set -#C -C = set() -C.add("a") -print(C) -#R -print("a" in C) -#U -C.update({"b","c"}) -print(C) -C_2 = {"d","e"} -C = C.union(C_2) -print(C) -C.remove("a") -print(C) -C.pop() -print(C) +#create +add = [] +add.append("a") +print(add) +add = add+["b"] +print(add) +add*=10 +print(add) +add.insert(0,"b") +print(add) +print(add[1],add[2]) +#R +R = list(range(100)) +print(R) +print(R[1:10]) +print(R[1:10:2]) +R = ['a', 'b', 'c'] +print(R.index('a')) +#U +U = list(range(10)) +U[1]= '2' +print(U) +U[0:5] = "3" +print(U) +#D +D = list(range(10)) +print(D.pop()) +print(D.clear()) + +#tuple +#Retrieve +R = tuple(range(10)) +print(R.index(1)) +print(R[1:5]) + +#dict +#C +C_1 = {"a":1} +C_2 = {"b":2,"c":3} +C_1.update(C_2) +print(C_1) +#R +R = {"a":1,"b":2,"c":3} +print(R.get('a')) +print(R.keys()) +print(R.values()) +print(R.items()) +#U +U ={"a":1,"b":2,"c":3} +U['a']=10 +print(U.get("a")) +U.update({"b":20,'c':30}) +print(U) +#D +D = {"a": 1, "b": 2, "c": 3} +print(D.pop("a")) +#set +#C +C = set() +C.add("a") +print(C) +#R +print("a" in C) +#U +C.update({"b","c"}) +print(C) +C_2 = {"d","e"} +C = C.union(C_2) +print(C) +C.remove("a") +print(C) +C.pop() +print(C) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\350\256\241\347\256\227\346\234\272.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\350\256\241\347\256\227\346\234\272.py" index 95a7b4b52a2bb023e6a7345c378ed64dd3fedabd..ee051bbb7ac73d04f64a16a6ea1efa62d71e404c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\350\256\241\347\256\227\346\234\272.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Flowey/\350\256\241\347\256\227\346\234\272.py" @@ -1,47 +1,47 @@ -a = int(input("输入你想计算的数字 ")) -print('加法,减法,乘法,除法,平方,开方分别对应1,2,3,4,5,6') -c = input("输入你想实现的算法 ") -if c == "6": - pass -else: - b = int(input("输入你想进行的运算大小 ")) - - -def add(a, b): - return a + b - - -def sub(a, b): - return a - b - - -def mul(a, b): - return a * b - - -def div(a, b): - return a / b - - -def squ(a, b): - return a ** b - - -def sqrt(a): - return float(a ** (1 / 2)) - - -if c == '1': - print(add(a, b)) -elif c == '2': - print(sub(a, b)) -elif c == "3": - print(mul(a, b)) -elif c == '4': - print(div(a, b)) -elif c == '5 ': - print(squ(a, b)) -elif c == '6': - print(sqrt(a)) -else: - print("请输入1-6") +a = int(input("输入你想计算的数字 ")) +print('加法,减法,乘法,除法,平方,开方分别对应1,2,3,4,5,6') +c = input("输入你想实现的算法 ") +if c == "6": + pass +else: + b = int(input("输入你想进行的运算大小 ")) + + +def add(a, b): + return a + b + + +def sub(a, b): + return a - b + + +def mul(a, b): + return a * b + + +def div(a, b): + return a / b + + +def squ(a, b): + return a ** b + + +def sqrt(a): + return float(a ** (1 / 2)) + + +if c == '1': + print(add(a, b)) +elif c == '2': + print(sub(a, b)) +elif c == "3": + print(mul(a, b)) +elif c == '4': + print(div(a, b)) +elif c == '5 ': + print(squ(a, b)) +elif c == '6': + print(sqrt(a)) +else: + print("请输入1-6") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson1.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson1.md" index 1732641e537c72c5efd996cccb1b23bcb5533538..9317600572eca198ee2425a4121d11cdfa60a152 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson1.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson1.md" @@ -1,47 +1,47 @@ -#什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. -- 关系型数据库是依据关系模型来创建的数据库。 -- 非数据型数据库是依据Nosql系统存储(键对值)基础上的数据库 -- 区别: - - 关系型数据库是用来存储结构化的数据,而非数据型数据库既可以存储结构化的数据, 也可以存储非结构化的数据。 - - 关系型数据库稳定且不会出现数据丢失风险但是运行速度相对较慢。 - - 非数据型数据库运行速度较快,但是会出现断电数据丢失的情况。 - - - 关系型数据库优点:1.易于维护:都是使用表结构,格式一致;2.使用方便:SQL语言通用,可用于复杂查询;3.复杂操作:支持SQL,可用于一个表及多个表之间非常复杂的查询; - - 关系型数据库缺点:1.读写性能比较差,尤其是海量数据的高效率读写;2.固定的表结构,灵活度稍欠;3.高并发读写需求,传统关系型数据库来说,硬盘I/O是一个很大的瓶颈。 - - - 非关系型数据库优点: - - 1.格式灵活:存储数据的格式可以是key,value形式、文档形式、图片形式等等,文档形式、图片形式等等,使用灵活,应用场景广泛,而关系型数据库则只支持基础类型。 - - 2.速度快:nosql可以使用硬盘或随机存储器作为载体,而关系型数据库只能使用硬盘; - - 3.高扩展性; - - 4.成本低:nosql数据库部署简单,基本都是开源软件 - - 非关系型数据库缺点:1.不支持sql语句,都有各自的api和语法,没有通用的语言;2.无事务处理,附加功能bi和报表等支持也不好;3.只适合存储一些较为简单的数据,对于需要进行较复杂查询的数据,关系型数据库显的更为合适。不适合持久存储海量数据 - - -- 应用场景: - -关系型数据库适用于关系特别复杂的数据库查询场景,非关系则反之。 - - -#什么是事务, 事务的特点. https://www.cnblogs.com/Kevin-ZhangCG/p/9038371.html -- 事务是指是程序中一系列严密的逻辑操作,而且所有操作必须全部成功完成,否则在每个操作中所作的所有更改都会被撤消。 -- 事务可以通俗理解为:就是把多件事情当做一件事情来处理,好比大家同在一条船上,要活一起活,要完一起完。 - -- 事务特点: ACID - - - Atomic(原子性) - - 指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 - - A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. - - Consistence(一致性) - - 事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. - - 集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. - 一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. - - Isolation(隔离性) - - 解决多个事务同时对数据进行读写和修改的能力. - - - Duration(持久性) - +#什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. +- 关系型数据库是依据关系模型来创建的数据库。 +- 非数据型数据库是依据Nosql系统存储(键对值)基础上的数据库 +- 区别: + - 关系型数据库是用来存储结构化的数据,而非数据型数据库既可以存储结构化的数据, 也可以存储非结构化的数据。 + - 关系型数据库稳定且不会出现数据丢失风险但是运行速度相对较慢。 + - 非数据型数据库运行速度较快,但是会出现断电数据丢失的情况。 + + - 关系型数据库优点:1.易于维护:都是使用表结构,格式一致;2.使用方便:SQL语言通用,可用于复杂查询;3.复杂操作:支持SQL,可用于一个表及多个表之间非常复杂的查询; + - 关系型数据库缺点:1.读写性能比较差,尤其是海量数据的高效率读写;2.固定的表结构,灵活度稍欠;3.高并发读写需求,传统关系型数据库来说,硬盘I/O是一个很大的瓶颈。 + + - 非关系型数据库优点: + - 1.格式灵活:存储数据的格式可以是key,value形式、文档形式、图片形式等等,文档形式、图片形式等等,使用灵活,应用场景广泛,而关系型数据库则只支持基础类型。 + - 2.速度快:nosql可以使用硬盘或随机存储器作为载体,而关系型数据库只能使用硬盘; + - 3.高扩展性; + - 4.成本低:nosql数据库部署简单,基本都是开源软件 + - 非关系型数据库缺点:1.不支持sql语句,都有各自的api和语法,没有通用的语言;2.无事务处理,附加功能bi和报表等支持也不好;3.只适合存储一些较为简单的数据,对于需要进行较复杂查询的数据,关系型数据库显的更为合适。不适合持久存储海量数据 + + +- 应用场景: + -关系型数据库适用于关系特别复杂的数据库查询场景,非关系则反之。 + + +#什么是事务, 事务的特点. https://www.cnblogs.com/Kevin-ZhangCG/p/9038371.html +- 事务是指是程序中一系列严密的逻辑操作,而且所有操作必须全部成功完成,否则在每个操作中所作的所有更改都会被撤消。 +- 事务可以通俗理解为:就是把多件事情当做一件事情来处理,好比大家同在一条船上,要活一起活,要完一起完。 + +- 事务特点: ACID + + - Atomic(原子性) + + 指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 + + A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. + - Consistence(一致性) + + 事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. + + 集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. + 一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. + - Isolation(隔离性) + + 解决多个事务同时对数据进行读写和修改的能力. + + - Duration(持久性) + 当某个事务一旦提交, 无论数据库崩溃还是其他原因, 该事务的结果都能够被持久化地保存下来. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson2.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson2.md" index 1f8575cd4842d891f08df21cf9a8286fa2603432..5af834960952b667006d972598d9104214968878 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson2.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson2.md" @@ -1,7 +1,7 @@ -- 通过navicat建表, 包含当前常用的数据类型. -- 通过INSERT录入信息 -- 常用的运算符及常用函数练习 - -![输入图片说明](https://images.gitee.com/uploads/images/2021/0128/231437_6dbad7ec_8448668.png "屏幕截图.png") -![输入图片说明](https://images.gitee.com/uploads/images/2021/0128/231412_8b34fa8b_8448668.png "屏幕截图.png") +- 通过navicat建表, 包含当前常用的数据类型. +- 通过INSERT录入信息 +- 常用的运算符及常用函数练习 + +![输入图片说明](https://images.gitee.com/uploads/images/2021/0128/231437_6dbad7ec_8448668.png "屏幕截图.png") +![输入图片说明](https://images.gitee.com/uploads/images/2021/0128/231412_8b34fa8b_8448668.png "屏幕截图.png") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0128/231504_96bdcc5c_8448668.png "屏幕截图.png") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson3.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson3.md" index 715550744b1aacc9ad93322ab5f9186c1c58c39f..df3a7de02d6cff3e3fd11a28a3a3952943a6ee38 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson3.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\232/wk7_lesson3.md" @@ -1,22 +1,22 @@ -### 练习CRUD操作 - -![CRUD](https://images.gitee.com/uploads/images/2021/0131/163501_af2e4b6d_8448668.png "屏幕截图.png") - -### 练习集合操作 - -- 并集 - - ![并集](https://images.gitee.com/uploads/images/2021/0131/163438_59905bf0_8448668.png "屏幕截图.png") - -- 交集 - - ![交集](https://images.gitee.com/uploads/images/2021/0131/163349_8afb070a_8448668.png "屏幕截图.png") - -- 差集 - - ![差集](https://images.gitee.com/uploads/images/2021/0131/163249_1fbe593d_8448668.png "屏幕截图.png") - -- 补集 - - ![补集](https://images.gitee.com/uploads/images/2021/0131/163107_3a04bd94_8448668.png "屏幕截图.png") - +### 练习CRUD操作 + +![CRUD](https://images.gitee.com/uploads/images/2021/0131/163501_af2e4b6d_8448668.png "屏幕截图.png") + +### 练习集合操作 + +- 并集 + + ![并集](https://images.gitee.com/uploads/images/2021/0131/163438_59905bf0_8448668.png "屏幕截图.png") + +- 交集 + + ![交集](https://images.gitee.com/uploads/images/2021/0131/163349_8afb070a_8448668.png "屏幕截图.png") + +- 差集 + + ![差集](https://images.gitee.com/uploads/images/2021/0131/163249_1fbe593d_8448668.png "屏幕截图.png") + +- 补集 + + ![补集](https://images.gitee.com/uploads/images/2021/0131/163107_3a04bd94_8448668.png "屏幕截图.png") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/lesson_1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/lesson_1.py" index 71c15c4b1a2d0dbe5281a5d5bec43625b37ae638..13505836a7d42b857c50eade45fa1ba2ef606fb2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/lesson_1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/lesson_1.py" @@ -1,49 +1,49 @@ - -l = [1, 3, 5] -print("for 循环如下——") -x = 0 -for i in l: - x += 1 - print (f"第{x}位数字为{i}") - -print("while 循环如下——") -y = 0 -while y < 3: - i = l[y] - y += 1 - print (f"第{y}位数字为{i}") - -print("100以内斐波那契数列while循环如下——") -a = 0 -b = 1 -print(a,b,end=" ") -while True: - if a+b > 100: - break - a, b = b, a+b - print(b,end=" ") -print() - -print("100以内斐波那契数列for循环如下——") -n1 = 0 -n2 = 1 -print(n1,n2,end=" ") -for i in range(100): - if n1+n2 > 100: - break - n1, n2 = n2, n1+n2 - print(n2, end=" ") -print() - -print("calculator自定义异常ParamsError——") -def div(x1,x2): - try: - return(x1/x2) - except ZeroDivisionError: - raise ParamsError("分母不能为0") - finally: - print("function my_sub end") -x1 = int(input("分子为:")) -x2 = int(input("分母为:")) -result = div(x1,x2) + +l = [1, 3, 5] +print("for 循环如下——") +x = 0 +for i in l: + x += 1 + print (f"第{x}位数字为{i}") + +print("while 循环如下——") +y = 0 +while y < 3: + i = l[y] + y += 1 + print (f"第{y}位数字为{i}") + +print("100以内斐波那契数列while循环如下——") +a = 0 +b = 1 +print(a,b,end=" ") +while True: + if a+b > 100: + break + a, b = b, a+b + print(b,end=" ") +print() + +print("100以内斐波那契数列for循环如下——") +n1 = 0 +n2 = 1 +print(n1,n2,end=" ") +for i in range(100): + if n1+n2 > 100: + break + n1, n2 = n2, n1+n2 + print(n2, end=" ") +print() + +print("calculator自定义异常ParamsError——") +def div(x1,x2): + try: + return(x1/x2) + except ZeroDivisionError: + raise ParamsError("分母不能为0") + finally: + print("function my_sub end") +x1 = int(input("分子为:")) +x2 = int(input("分母为:")) +result = div(x1,x2) print (result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202/lesson_3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202/lesson_3.py" index 396cc20eba96cbef323eed7a339e76f9f35e747b..fcbee6b71955d5c76272958b16f9359513697631 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202/lesson_3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202/lesson_3.py" @@ -1,64 +1,64 @@ -''' -#作用域转换 -sum_up = 10 -def sum(a,b): - #global sum_up - sum_up = a + b - print ("sum_up=",sum_up) -sum(10,20) -print("sum_up=",sum_up) - -def value(): - a = 5 - def value_2(): - nonlocal a - a = 3 - print (a) - value_2() - print(a) -value() - -#计时器 -import time -def clock_time_deco(func): - def wrapper(*arg,**kwargs): - start_time = time.time() - result = func(*arg,**kwargs) - end_time = time.time() - print(f"{func.__name__}耗时:{format(end_time - start_time,'.2f')}s") - return result - return wrapper - -@clock_time_deco -def foo(a,b): - count = 1 - while True: - if count > a**b: - break - count +=1 - -foo(12,5) -''' -#fibo缓存 -def cache_deco(func): - global a - a = {} - def wrapper(n): - if n in a: - pass - else: - a[n] = func(n) - return a[n] - return wrapper - -@cache_deco -def fibo(n): - if n == 0: - return 0 - if n == 1: - return 1 - else: - return fibo(n-1)+fibo(n-2) - -fibo(5) -print(a) +''' +#作用域转换 +sum_up = 10 +def sum(a,b): + #global sum_up + sum_up = a + b + print ("sum_up=",sum_up) +sum(10,20) +print("sum_up=",sum_up) + +def value(): + a = 5 + def value_2(): + nonlocal a + a = 3 + print (a) + value_2() + print(a) +value() + +#计时器 +import time +def clock_time_deco(func): + def wrapper(*arg,**kwargs): + start_time = time.time() + result = func(*arg,**kwargs) + end_time = time.time() + print(f"{func.__name__}耗时:{format(end_time - start_time,'.2f')}s") + return result + return wrapper + +@clock_time_deco +def foo(a,b): + count = 1 + while True: + if count > a**b: + break + count +=1 + +foo(12,5) +''' +#fibo缓存 +def cache_deco(func): + global a + a = {} + def wrapper(n): + if n in a: + pass + else: + a[n] = func(n) + return a[n] + return wrapper + +@cache_deco +def fibo(n): + if n == 0: + return 0 + if n == 1: + return 1 + else: + return fibo(n-1)+fibo(n-2) + +fibo(5) +print(a) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/lesson_2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/lesson_2.py" index 370599c3ac7c9ca0e8a384e240de460598b3a962..a2f58cde009f9dca99c0131a863c9ac4c0e98ddb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/lesson_2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/lesson_2.py" @@ -1,35 +1,35 @@ -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] - -# 以grade进行排序 -classes.sort(key=lambda x: x["grade"]) -print(classes) - -# 通过filter语句来筛选出Grade为A的同学 -f = filter(lambda x: x["grade"] == "A",classes) -list(f) - -# age加1 -def age_add(n): - n["age"] += 1 - return n -m = map(age_add,classes) -list(m) - -# 递归函数构造斐波那契数列 -def F(n): - if n == 0: - return 0 - elif n == 1: - return 1 - else: - return F(n-2)+ F(n-1) -for n in range(10): - print (F(n),end=" ") +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + +# 以grade进行排序 +classes.sort(key=lambda x: x["grade"]) +print(classes) + +# 通过filter语句来筛选出Grade为A的同学 +f = filter(lambda x: x["grade"] == "A",classes) +list(f) + +# age加1 +def age_add(n): + n["age"] += 1 + return n +m = map(age_add,classes) +list(m) + +# 递归函数构造斐波那契数列 +def F(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return F(n-2)+ F(n-1) +for n in range(10): + print (F(n),end=" ") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_caculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_caculator.py" index 29715e73a590e0e5f851227975bb1364b684351f..38db2034fa20c70c59aba774a4bf4d67a975654b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_caculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_caculator.py" @@ -1,29 +1,29 @@ -def add(a,b): - result = a + b - return (result) -def minus(a,b): - result = a - b - return(result) -def times(a,b): - result = a * b - return(result) -def divide(a,b): - result = a / b - return(result) -def exactdivide(a,b): - result = a // b - return(result) -def reminder(a,b): - result = a % b - return(result) -def sqrt(a): - result = a ** 2 - return(result) -a = 8 -b = 3 -print (add(a,b)) -print (minus(a,b)) -print (divide(a,b)) -print (exactdivide(a,b)) -print (reminder(a,b)) +def add(a,b): + result = a + b + return (result) +def minus(a,b): + result = a - b + return(result) +def times(a,b): + result = a * b + return(result) +def divide(a,b): + result = a / b + return(result) +def exactdivide(a,b): + result = a // b + return(result) +def reminder(a,b): + result = a % b + return(result) +def sqrt(a): + result = a ** 2 + return(result) +a = 8 +b = 3 +print (add(a,b)) +print (minus(a,b)) +print (divide(a,b)) +print (exactdivide(a,b)) +print (reminder(a,b)) print (sqrt(a)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/3_crud.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/3_crud.py" index 9249c8166fa339d80af586c34eb883f237089002..d709c8cdf5b36c5ea996efea87074b5c2da7b6e2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/3_crud.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/3_crud.py" @@ -1,163 +1,163 @@ -""" - #List Creat ->>> A = ["a",1, 1, 2, "b", "c"] ->>> B = ["d","e"] ->>> B.append("f") ->>> B -['d', 'e', 'f'] ->>> C = A + B ->>> C -['a', 1, 1, 2, 'b', 'c', 'd', 'e', 'f'] ->>> A += B ->>> A -['a', 1, 1, 2, 'b', 'c', 'd', 'e', 'f'] ->>> B = B*2 ->>> B -['d', 'e', 'f', 'd', 'e', 'f'] ->>> B.insert(1,"a") ->>> B -['d', 'a', 'e', 'f', 'd', 'e', 'f'] - - # List Rerieve, Update, Delete ->>> A = ["a",1, 1, 2, "b", "c"] ->>> B = ["d","e"] ->>> A[1] -1 ->>> A[2:5:2] -[1, 'b'] ->>> A.index(1) -1 ->>> A[1] = 3 ->>> A -['a', 3, 1, 2, 'b', 'c'] ->>> A[1:3] = "d" ->>> A -['a', 'd', 2, 'b', 'c'] ->>> A.pop() -'c' ->>> D = A ->>> D -['a', 'd', 2, 'b'] ->>> D.clear() ->>> D -[] - - #List sort, reverse ->>> A = [12, 3, 2, 6, 4, 3, 5, 9, 7, 5] ->>> A.sort() ->>> A -[2, 3, 3, 4, 5, 5, 6, 7, 9, 12] ->>> A.reverse() ->>> A -[12, 9, 7, 6, 5, 5, 4, 3, 3, 2] ->>> A = [12, 3, 2, 6, 4, 3, 5, 9, 7, 5] ->>> A.reverse() ->>> A -[5, 7, 9, 5, 3, 4, 6, 2, 3, 12] - - #Truple Retrieve ->>> A = tuple(range(10)) ->>> A -(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ->>> A[-2] -8 ->>> A[:-2:2] -(0, 2, 4, 6) ->>> A.index(2) -2 - -#Dict - #Creat ->>> A = {"a":1, "b":2, "c":3} ->>> A["d"]=1 ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 1} ->>> A["d"]=4 ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4} ->>> B = {"f":5} ->>> A.update(B) ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5} ->>> A.setdefault("g") ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': None} ->>> A.setdefault("a") -1 ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': None} - #Retireve ->>> A["b"] -2 ->>> A.get("c") -3 ->>> A.keys() -dict_keys(['a', 'b', 'c', 'd', 'f', 'g']) ->>> A.values() -dict_values([1, 2, 3, 4, 5, None]) ->>> A.items() -dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('f', 5), ('g', None)]) - #Update ->>> A["g"] = 6 ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6} ->>> A.update({"h":7}) ->>> A -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6, 'h': 7} - #Delete ->>> A.pop("a") -1 ->>> A -{'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6, 'h': 7} ->>> A.popitem() -('h', 7) ->>> A -{'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6} ->>> A.clear() ->>> A -{} - -#Set - #Creat ->>> A ={1,"d",3,4,"g",7,8,"h",0,"n","s"} ->>> A.add(11) ->>> A -{0, 1, 3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} ->>> A.update(10) -Traceback (most recent call last): - File "", line 1, in -TypeError: 'int' object is not iterable ->>> A.update("g") ->>> A -{0, 1, 3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} ->>> A.update("H") ->>> A -{0, 1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} - #Retrieve ->>> "h" in A -True ->>> 10 in A -False - #Update ->>> B= {"A","B"} ->>> A.union(B) -{0, 1, 3, 4, 'n', 7, 8, 'B', 11, 'H', 'A', 'g', 'd', 's', 'h'} ->>> A -{0, 1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} - #Delete ->>> A.pop() -0 ->>> A -{1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} ->>> A.remove(1) ->>> A.reomve(10) -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'set' object has no attribute 'reomve' ->>> A.discard("H") ->>> A -{3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} ->>> A.discard("A") ->>> A -{3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} +""" + #List Creat +>>> A = ["a",1, 1, 2, "b", "c"] +>>> B = ["d","e"] +>>> B.append("f") +>>> B +['d', 'e', 'f'] +>>> C = A + B +>>> C +['a', 1, 1, 2, 'b', 'c', 'd', 'e', 'f'] +>>> A += B +>>> A +['a', 1, 1, 2, 'b', 'c', 'd', 'e', 'f'] +>>> B = B*2 +>>> B +['d', 'e', 'f', 'd', 'e', 'f'] +>>> B.insert(1,"a") +>>> B +['d', 'a', 'e', 'f', 'd', 'e', 'f'] + + # List Rerieve, Update, Delete +>>> A = ["a",1, 1, 2, "b", "c"] +>>> B = ["d","e"] +>>> A[1] +1 +>>> A[2:5:2] +[1, 'b'] +>>> A.index(1) +1 +>>> A[1] = 3 +>>> A +['a', 3, 1, 2, 'b', 'c'] +>>> A[1:3] = "d" +>>> A +['a', 'd', 2, 'b', 'c'] +>>> A.pop() +'c' +>>> D = A +>>> D +['a', 'd', 2, 'b'] +>>> D.clear() +>>> D +[] + + #List sort, reverse +>>> A = [12, 3, 2, 6, 4, 3, 5, 9, 7, 5] +>>> A.sort() +>>> A +[2, 3, 3, 4, 5, 5, 6, 7, 9, 12] +>>> A.reverse() +>>> A +[12, 9, 7, 6, 5, 5, 4, 3, 3, 2] +>>> A = [12, 3, 2, 6, 4, 3, 5, 9, 7, 5] +>>> A.reverse() +>>> A +[5, 7, 9, 5, 3, 4, 6, 2, 3, 12] + + #Truple Retrieve +>>> A = tuple(range(10)) +>>> A +(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +>>> A[-2] +8 +>>> A[:-2:2] +(0, 2, 4, 6) +>>> A.index(2) +2 + +#Dict + #Creat +>>> A = {"a":1, "b":2, "c":3} +>>> A["d"]=1 +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 1} +>>> A["d"]=4 +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4} +>>> B = {"f":5} +>>> A.update(B) +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5} +>>> A.setdefault("g") +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': None} +>>> A.setdefault("a") +1 +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': None} + #Retireve +>>> A["b"] +2 +>>> A.get("c") +3 +>>> A.keys() +dict_keys(['a', 'b', 'c', 'd', 'f', 'g']) +>>> A.values() +dict_values([1, 2, 3, 4, 5, None]) +>>> A.items() +dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('f', 5), ('g', None)]) + #Update +>>> A["g"] = 6 +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6} +>>> A.update({"h":7}) +>>> A +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6, 'h': 7} + #Delete +>>> A.pop("a") +1 +>>> A +{'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6, 'h': 7} +>>> A.popitem() +('h', 7) +>>> A +{'b': 2, 'c': 3, 'd': 4, 'f': 5, 'g': 6} +>>> A.clear() +>>> A +{} + +#Set + #Creat +>>> A ={1,"d",3,4,"g",7,8,"h",0,"n","s"} +>>> A.add(11) +>>> A +{0, 1, 3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} +>>> A.update(10) +Traceback (most recent call last): + File "", line 1, in +TypeError: 'int' object is not iterable +>>> A.update("g") +>>> A +{0, 1, 3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} +>>> A.update("H") +>>> A +{0, 1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} + #Retrieve +>>> "h" in A +True +>>> 10 in A +False + #Update +>>> B= {"A","B"} +>>> A.union(B) +{0, 1, 3, 4, 'n', 7, 8, 'B', 11, 'H', 'A', 'g', 'd', 's', 'h'} +>>> A +{0, 1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} + #Delete +>>> A.pop() +0 +>>> A +{1, 3, 4, 'n', 7, 8, 11, 'H', 'g', 'd', 's', 'h'} +>>> A.remove(1) +>>> A.reomve(10) +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'set' object has no attribute 'reomve' +>>> A.discard("H") +>>> A +{3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} +>>> A.discard("A") +>>> A +{3, 4, 'n', 7, 8, 11, 'g', 'd', 's', 'h'} """ \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/stringpractice.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/stringpractice.py" index 4ceb1bbac0461bf843f38f1ae1fae5ec44965620..c46888834da7b25088114bcfd61486662d66bb6c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/stringpractice.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/stringpractice.py" @@ -1,88 +1,88 @@ -content = ''' - - #解码 ->>> a = "你好 Python".encode("utf-8") ->>> a -b'\xe4\xbd\xa0\xe5\xa5\xbd Python' - - #编码 ->>> a.decode("utf") -'你好 Python' - - #混合编码 ->>> b = "Python".encode("utf-8") + "你好".encode("gbk") ->>> b -b'Python\xc4\xe3\xba\xc3' - #解码错误 ->>> b.decode("utf") -Traceback (most recent call last): - File "", line 1, in - File "E:\Python\python 3.6.5\Lib\encodings\utf_8.py", line 16, in decode - return codecs.utf_8_decode(input, errors, True) -UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 6: invalid continuation byte - #忽略错误编码 ->>> b.decode("utf-8",errors="ignore") -'Python' - #利用鬼符来替换 ->>> b.decode("utf-8",errors="replace") -'Python���' - - #字符串CRUD - #Create(创建) ->>> a = "hello" ->>> b = "python" ->>> a = a + b ->>> print(a) -hellopython ->>> a += "hellopython" ->>> print(a) -hellopythonhellopython - - #Retrieve(检索) ->>> c = "hello python, hello word" ->>> c[3] -'l' ->>> c.find("o") -4 ->>> c.index("o") -4 ->>> c.startswith("hello") -True ->>> c.endswith("world") -False - - #Update(更新) ->>> d = "this is a test, hello pythen" ->>> d.replace("hen","hon") -'this is a test, hello python' ->>> d.split(",") -['this is a test', ' hello pythen'] ->>> d.split(" ") -['this', 'is', 'a', 'test,', 'hello', 'pythen'] ->>> " ".join(d) -'t h i s i s a t e s t , h e l l o p y t h e n' - - #Delete(删除) ->>> f = " this is a test " ->>> f.strip() -'this is a test' ->>> f.lstrip() -'this is a test ' ->>> f.rstrip() -' this is a test' - - #格式化 ->>> a = 3 ->>> b = 7 ->>> print ("21={}*{}".format(a,b) ) -21=3*7 ->>> print("?={1}+{0}*{0}+{1}-{0}".format(a,b)) -?=7+3*3+7-3 ->>> print("?={b}+{a}*{a}+{b}-{a}".format(a=3,b=7)) -?=7+3*3+7-3 ->>> print(f"?={b}+{a}*{a}+{b}-{a}") -?=7+3*3+7-3 ->>> print("{:.1f}".format(0.618)) -0.6 - +content = ''' + + #解码 +>>> a = "你好 Python".encode("utf-8") +>>> a +b'\xe4\xbd\xa0\xe5\xa5\xbd Python' + + #编码 +>>> a.decode("utf") +'你好 Python' + + #混合编码 +>>> b = "Python".encode("utf-8") + "你好".encode("gbk") +>>> b +b'Python\xc4\xe3\xba\xc3' + #解码错误 +>>> b.decode("utf") +Traceback (most recent call last): + File "", line 1, in + File "E:\Python\python 3.6.5\Lib\encodings\utf_8.py", line 16, in decode + return codecs.utf_8_decode(input, errors, True) +UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 6: invalid continuation byte + #忽略错误编码 +>>> b.decode("utf-8",errors="ignore") +'Python' + #利用鬼符来替换 +>>> b.decode("utf-8",errors="replace") +'Python���' + + #字符串CRUD + #Create(创建) +>>> a = "hello" +>>> b = "python" +>>> a = a + b +>>> print(a) +hellopython +>>> a += "hellopython" +>>> print(a) +hellopythonhellopython + + #Retrieve(检索) +>>> c = "hello python, hello word" +>>> c[3] +'l' +>>> c.find("o") +4 +>>> c.index("o") +4 +>>> c.startswith("hello") +True +>>> c.endswith("world") +False + + #Update(更新) +>>> d = "this is a test, hello pythen" +>>> d.replace("hen","hon") +'this is a test, hello python' +>>> d.split(",") +['this is a test', ' hello pythen'] +>>> d.split(" ") +['this', 'is', 'a', 'test,', 'hello', 'pythen'] +>>> " ".join(d) +'t h i s i s a t e s t , h e l l o p y t h e n' + + #Delete(删除) +>>> f = " this is a test " +>>> f.strip() +'this is a test' +>>> f.lstrip() +'this is a test ' +>>> f.rstrip() +' this is a test' + + #格式化 +>>> a = 3 +>>> b = 7 +>>> print ("21={}*{}".format(a,b) ) +21=3*7 +>>> print("?={1}+{0}*{0}+{1}-{0}".format(a,b)) +?=7+3*3+7-3 +>>> print("?={b}+{a}*{a}+{b}-{a}".format(a=3,b=7)) +?=7+3*3+7-3 +>>> print(f"?={b}+{a}*{a}+{b}-{a}") +?=7+3*3+7-3 +>>> print("{:.1f}".format(0.618)) +0.6 + ''' \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_1.py" index 169ed2e50d8ea61fcf8b9899a8232fc96356ae07..4f34b02b46a45fd32b4d73378f3e5c03ad99845d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_1.py" @@ -1,41 +1,41 @@ -import time -from threading import Thread -from multiprocessing import Process - -def count(n): - for i in range(n): - print(f"count{i}") - time.sleep(0.1) - -def hello(name): - for i in range(5): - print(f"hello,{name}") - time.sleep(0.1) - -#逐个运行 -if __name__ == "__main__": - start_time = time.time() - count(10) - hello("lili") - end_time = time.time() - print(f"单独运行总耗时{end_time-start_time}s") - -#多线程运行 -if __name__ == "__main__": - start_time = time.time() - c = Thread(target=count(10),) - h = Thread(target=hello("lili"),) - c.start() - h.start() - end_time = time.time() - print(f"多线程运行总耗时{end_time-start_time}s") - -#多进程运行 -if __name__ == "__main__": - start_time = time.time() - c = Process(target=count(10),) - h = Process(target=hello("lili"),) - c.start() - h.start() - end_time = time.time() +import time +from threading import Thread +from multiprocessing import Process + +def count(n): + for i in range(n): + print(f"count{i}") + time.sleep(0.1) + +def hello(name): + for i in range(5): + print(f"hello,{name}") + time.sleep(0.1) + +#逐个运行 +if __name__ == "__main__": + start_time = time.time() + count(10) + hello("lili") + end_time = time.time() + print(f"单独运行总耗时{end_time-start_time}s") + +#多线程运行 +if __name__ == "__main__": + start_time = time.time() + c = Thread(target=count(10),) + h = Thread(target=hello("lili"),) + c.start() + h.start() + end_time = time.time() + print(f"多线程运行总耗时{end_time-start_time}s") + +#多进程运行 +if __name__ == "__main__": + start_time = time.time() + c = Process(target=count(10),) + h = Process(target=hello("lili"),) + c.start() + h.start() + end_time = time.time() print(f"多进程运行总耗时{end_time-start_time}s") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_2.py" index 23edea7e6f3c14e70d3105a4ce38aec9b3fcb1c9..40887746beff3699d4a48765ac8bef32622c5d65 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_2.py" @@ -1,58 +1,58 @@ - -from threading import Thread,Lock -from multiprocessing import Process,Lock,Queue - -''' -#进程锁 -def my_file(index,Lock): - with Lock: - with open("lesson2_test_file","a",encoding="utf-8") as f: - f.write(str(index) + "\n") - -if __name__ == "__main__": - lock = Lock() - f_array = [] - for i in range(12): - p = Process(target = my_file,args=(i,lock)) - f_array.append(p) - p.start() - for p in f_array: - p.join() - -#线程锁 -zero = 0 -lock = Lock() -def foo(): - global zero - for i in range(10**5): - with lock: - zero += 1 - zero -= 1 - -if __name__ == "__main__": - f_array = [] - for i in range(12): - t = Thread(target = foo) - f_array.append(t) - t.start() - for t in f_array: - t.join() - - print(zero) -''' -#多进程通过Queue来实现进程通信 -def save_to_queue(index, my_queue): - my_queue.put(index) - -if __name__ == "__main__": - f_array = [] - my_queue = Queue() - for i in range(12): - p = Process(target = save_to_queue,args=(i,my_queue)) - f_array.append(p) - p.start() - for p in f_array: - p.join() - - while True: - print(my_queue.get()) + +from threading import Thread,Lock +from multiprocessing import Process,Lock,Queue + +''' +#进程锁 +def my_file(index,Lock): + with Lock: + with open("lesson2_test_file","a",encoding="utf-8") as f: + f.write(str(index) + "\n") + +if __name__ == "__main__": + lock = Lock() + f_array = [] + for i in range(12): + p = Process(target = my_file,args=(i,lock)) + f_array.append(p) + p.start() + for p in f_array: + p.join() + +#线程锁 +zero = 0 +lock = Lock() +def foo(): + global zero + for i in range(10**5): + with lock: + zero += 1 + zero -= 1 + +if __name__ == "__main__": + f_array = [] + for i in range(12): + t = Thread(target = foo) + f_array.append(t) + t.start() + for t in f_array: + t.join() + + print(zero) +''' +#多进程通过Queue来实现进程通信 +def save_to_queue(index, my_queue): + my_queue.put(index) + +if __name__ == "__main__": + f_array = [] + my_queue = Queue() + for i in range(12): + p = Process(target = save_to_queue,args=(i,my_queue)) + f_array.append(p) + p.start() + for p in f_array: + p.join() + + while True: + print(my_queue.get()) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_3.py" index d12f051d5f221fcd504c21a45d4b5615eaa24add..c91c54f152d79743f7ed8f117aa874f11de36340 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/wk5_lesson_3.py" @@ -1,34 +1,34 @@ - -# 协程实现计算平均数 -def coro_averange(): - total = 0 - length = 0 - while True: - try: - result = yield total/length - except ZeroDivisionError: - result = yield 0 - total += result - length += 1 - -my_avg = coro_averange() -print(f"初始化:{next(my_avg)}") -while True: - temp = int(input("请输入一个数字:")) - print(f"此时已输入值的平均数为:{my_avg.send(temp)}") - - -#编写一个asyncio异步程序 -import asyncio - -async def count(index) : - print(f"first counting_{index}") - await asyncio.sleep(1) - print(f"second counting_{index}") - -loop = asyncio.get_event_loop() -task_array = [] -for i in range(5): - task_array.append(count(i)) -loop.run_until_complete(asyncio.wait(task_array)) -loop.close() + +# 协程实现计算平均数 +def coro_averange(): + total = 0 + length = 0 + while True: + try: + result = yield total/length + except ZeroDivisionError: + result = yield 0 + total += result + length += 1 + +my_avg = coro_averange() +print(f"初始化:{next(my_avg)}") +while True: + temp = int(input("请输入一个数字:")) + print(f"此时已输入值的平均数为:{my_avg.send(temp)}") + + +#编写一个asyncio异步程序 +import asyncio + +async def count(index) : + print(f"first counting_{index}") + await asyncio.sleep(1) + print(f"second counting_{index}") + +loop = asyncio.get_event_loop() +task_array = [] +for i in range(5): + task_array.append(count(i)) +loop.run_until_complete(asyncio.wait(task_array)) +loop.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_1.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_1.md" index 79b822fd2e0d4fbab3c269416edcd12a3d327b06..9dbc6bcaddeeaf5a3f1e86339639cf3a3a4ff1ca 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_1.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_1.md" @@ -1,11 +1,11 @@ -一、讲清楚浏览器地址栏敲下url发生了什么? - 客户端输入URL(域名)--> DNS服务器解析真实的IP地址 --> 通过IP地址访问服务器 --> 客户端与服务端建立联系 --> 客户端正式向 --> -服务端发送请求 --> 服务端通过请求返回结果 --> 浏览器收到结果后进行相应渲染 - - -二、五层协议有哪五层, 举例说明. - 应用层:网页界面,客户端进程 - 传输层:进程(客户端)<--> 进程(服务端) - 网络层:主机 - 数据链路层:网卡/路由器 - 物理层:字节流/比特流 +一、讲清楚浏览器地址栏敲下url发生了什么? + 客户端输入URL(域名)--> DNS服务器解析真实的IP地址 --> 通过IP地址访问服务器 --> 客户端与服务端建立联系 --> 客户端正式向 --> +服务端发送请求 --> 服务端通过请求返回结果 --> 浏览器收到结果后进行相应渲染 + + +二、五层协议有哪五层, 举例说明. + 应用层:网页界面,客户端进程 + 传输层:进程(客户端)<--> 进程(服务端) + 网络层:主机 + 数据链路层:网卡/路由器 + 物理层:字节流/比特流 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_3.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_3.md" index 3d58ec23c65bb2b9e6ebc1acec8b1b8f04688d76..4c4a151e0942a6017bc85b78f46c084c2d3e01b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_3.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\232/wk6_lesson_3.md" @@ -1,89 +1,89 @@ -# 第六周-第三节课 抓包及模拟请求 - -## 抓包 - -抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. - -对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. - -- 抓包软件 - - - Fiddler - - ``` - https://www.telerik.com/fiddler - ``` - - - Charles - - - wireshark - -- web端抓包 - - 现代互联网环境几乎都是https协议的网站 - - - 信任证书 - - ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) - - ``` - Rules -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -- App端抓包 - - ``` - 下载夜神模拟器 - ``` - - - 打开远程终端连接 - - ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) - - ``` - Rules -> Options -> Connections -> Allow remote computes to connect - ``` - - - 把手机/模拟器的代理指向fiddler - - ``` - - wifi调出设置的时候要长按 - - 查看当前fiddler所在pc本地局域网ip - - ipconfig/ifconfig - - 在代理项中填写ip地址和fiddler端口, 默认是8888 - ``` - - - 信任证书 - - - App有一定的反爬措施, 第一件事就是修改请求协议 - - - 双向验证 - - 需要客户端也带上证书 - - - 解决请求协议上的反爬措施 - - - 安装VirtualXposed_0.18.2, JustTrustMe - -## 模拟请求 - -- PostMan简单使用 - - - GET - - - POST - - - form_data - - 参数表单 - - - x-www-form-urlencoded - - 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 - - - raw - - 请求的真实body内容. +# 第六周-第三节课 抓包及模拟请求 + +## 抓包 + +抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. + +对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. + +- 抓包软件 + + - Fiddler + + ``` + https://www.telerik.com/fiddler + ``` + + - Charles + + - wireshark + +- web端抓包 + + 现代互联网环境几乎都是https协议的网站 + + - 信任证书 + + ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) + + ``` + Rules -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +- App端抓包 + + ``` + 下载夜神模拟器 + ``` + + - 打开远程终端连接 + + ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) + + ``` + Rules -> Options -> Connections -> Allow remote computes to connect + ``` + + - 把手机/模拟器的代理指向fiddler + + ``` + - wifi调出设置的时候要长按 + - 查看当前fiddler所在pc本地局域网ip + - ipconfig/ifconfig + - 在代理项中填写ip地址和fiddler端口, 默认是8888 + ``` + + - 信任证书 + + - App有一定的反爬措施, 第一件事就是修改请求协议 + + - 双向验证 + + 需要客户端也带上证书 + + - 解决请求协议上的反爬措施 + + - 安装VirtualXposed_0.18.2, JustTrustMe + +## 模拟请求 + +- PostMan简单使用 + + - GET + + - POST + + - form_data + + 参数表单 + + - x-www-form-urlencoded + + 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 + + - raw + + 请求的真实body内容. diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/wk4_lesson_1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/wk4_lesson_1.py" index 9f01cbfc25947285a9566c41d210ee7cb43dcdf8..bae16530527ecaa5ca2947361029c0de71c4ca79 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/wk4_lesson_1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202/wk4_lesson_1.py" @@ -1,31 +1,31 @@ -#时间格式的转换 -from datetime import datetime as dt -import time -from datetime import timedelta - -now = dt.now(tz=None) -print(now.strftime("%Y-%m-%d %H:%M:%S")) #datetime -> str -print(now.timestamp()) #datetime -> timestamp - -now_1 = "2021-01-05 22:33:29" -temp_1 = dt.strptime(now_1,"%Y-%m-%d %H:%M:%S") -print(temp_1) #str -> datetime -print(temp_1.timestamp()) #str -> timestamp - -now_2 = time.time() -temp_2 = dt.fromtimestamp(now_2) -print(temp_2) #timestamp -> datetime -print(temp_2.strftime("%Y-%m-%d %H:%M:%S")) #timestamp -> str - -#输出相差的对应日期 -while True: - today = dt.today() - a = dt.strftime(today,"%Y-%m-%d") - print(f"今天的日期为:{a}") - d = int(input("请输入相差的天数:")) - if d == 0: - print("程序结束") - break - gap_day = dt.strftime((today + timedelta(days=d)),"%Y-%m-%d") - print(f"相差的日期为:{gap_day}") - print() +#时间格式的转换 +from datetime import datetime as dt +import time +from datetime import timedelta + +now = dt.now(tz=None) +print(now.strftime("%Y-%m-%d %H:%M:%S")) #datetime -> str +print(now.timestamp()) #datetime -> timestamp + +now_1 = "2021-01-05 22:33:29" +temp_1 = dt.strptime(now_1,"%Y-%m-%d %H:%M:%S") +print(temp_1) #str -> datetime +print(temp_1.timestamp()) #str -> timestamp + +now_2 = time.time() +temp_2 = dt.fromtimestamp(now_2) +print(temp_2) #timestamp -> datetime +print(temp_2.strftime("%Y-%m-%d %H:%M:%S")) #timestamp -> str + +#输出相差的对应日期 +while True: + today = dt.today() + a = dt.strftime(today,"%Y-%m-%d") + print(f"今天的日期为:{a}") + d = int(input("请输入相差的天数:")) + if d == 0: + print("程序结束") + break + gap_day = dt.strftime((today + timedelta(days=d)),"%Y-%m-%d") + print(f"相差的日期为:{gap_day}") + print() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/wk4_lesson_2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/wk4_lesson_2.py" index 3f50d9e7c142787955138540bb53630e1afd2c3c..dfbd9ed135e6e467d6e2bf0cf7540c879c0c89c6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/wk4_lesson_2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\345\237\271\345\230\211/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202/wk4_lesson_2.py" @@ -1,39 +1,39 @@ -''' -# MyMath类封装 -class MyMath: - def add(a,b): - return a + b - def minus(a,b): - return a - b - def times(a,b): - return a * b - def divide(a,b): - return a / b - def power(a,b): - return a ** b - def radic(self): - return self ** (1/2) -print (MyMath.radic(4)) -''' -#父类 -class Person(object): - def __init__(self,name,age): - self.name = name - self.age = age - def speak(self): - print(f"Hello, my name is {self.name}") - print(f"I am {self.age} years old") - -lily = Person("lily",12) -lily.speak() - -#子类 -class Caculate(Person): - def add(self,a,b): - self.a = a - self.b = b - print(f"I know {self.a}+{self.b}={self.a+self.b}") - -robin = Caculate("Robin",3) -robin.speak() -robin.add(2,4) +''' +# MyMath类封装 +class MyMath: + def add(a,b): + return a + b + def minus(a,b): + return a - b + def times(a,b): + return a * b + def divide(a,b): + return a / b + def power(a,b): + return a ** b + def radic(self): + return self ** (1/2) +print (MyMath.radic(4)) +''' +#父类 +class Person(object): + def __init__(self,name,age): + self.name = name + self.age = age + def speak(self): + print(f"Hello, my name is {self.name}") + print(f"I am {self.age} years old") + +lily = Person("lily",12) +lily.speak() + +#子类 +class Caculate(Person): + def add(self,a,b): + self.a = a + self.b = b + print(f"I know {self.a}+{self.b}={self.a+self.b}") + +robin = Caculate("Robin",3) +robin.speak() +robin.add(2,4) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/images" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/images" index 139597f9cb07c5d48bed18984ec4747f4b4f3438..99a8091366e2ac7f301452706d5cfdff5e320a0d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/images" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/images" @@ -1,2 +1,2 @@ - - + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index e7a023152a9b76b5b048a156984c6536ca1548be..d6a2dc34fcee9378df2aac7e4ed7144a89fe8907 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,90 +1,90 @@ -## 第一周-第三节作业 课后作业 -##- 四大基本数据结构中哪些是可变的, 哪些是不可变的? -##- 四大基本数据结构中哪些是有序的, 哪些是无序的? -##- 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. - - -##- 四大基本数据结构中哪些是可变的, 哪些是不可变的? - ## 可变的 list set - ## 不可变的 tuple dict - -##- 四大基本数据结构中哪些是有序的, 哪些是无序的? - ##有序的 list tuple - ##无序的 dict set - -##- 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. -## 基本数据类型 -# - `int` (整数) -# - `float`(浮点数) -# - `string`(字符串, 字符序列) -# - 转义字符 -# - `boolean`(布尔值) -# - `bytes`(二进制序列) -###################list############################## -print("-------------------list----------------------------") -print(list([1,2,3,4])) ## int - -print(list([float(1.2),float(2.2)])) # float - -print(list('hello,world')) #string - -print(list("2\\n")) #转义字符 - -print(list([bool(2),bool(2.2),bool(0)])) #boolean - -print(list(bytes(4))) #bytes -print("-------------------list----------------------------") - -###################list############################## - -print("-------------------tuple----------------------------") -###################tuple############################## -print(tuple([1,2,3,4])) ## int - -print(tuple([float(1.2),float(2.2)])) # float - -print(tuple('hello,world')) #string - -print(tuple("2\\n")) #转义字符 - -print(tuple([bool(2),bool(2.2),bool(0)])) #boolean - -print(tuple(bytes(4))) #bytes - -print("-------------------tuple----------------------------") - - -###################tuple############################## - -print("-------------------dict----------------------------") -###################dict############################## -print(dict(a=1,b=2)) ## int - -print(dict(a=1.2,b=2.2) ) # float - -print(dict(a='hello,world')) #string - -print(dict(a="2\\n")) #转义字符 - -print(dict(a=bool(2),b=bool(2.2),c=bool(0))) #boolean - -print(dict(a=bytes(4))) #bytes -print("-------------------dict----------------------------") - -###################dict############################## - -###################set############################## -print("-------------------set----------------------------") -print(set({1,2,3,4,5})) ## int - -print(set([float(1.2),float(2.2)])) # float - -print(set('hello,world')) #string - -print(set("2\n")) #转义字符 - -print(set([bool(2),bool(2.2),bool(0)])) #boolean - -print(set(bytes(4))) #bytes -print("-------------------set----------------------------") +## 第一周-第三节作业 课后作业 +##- 四大基本数据结构中哪些是可变的, 哪些是不可变的? +##- 四大基本数据结构中哪些是有序的, 哪些是无序的? +##- 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. + + +##- 四大基本数据结构中哪些是可变的, 哪些是不可变的? + ## 可变的 list set + ## 不可变的 tuple dict + +##- 四大基本数据结构中哪些是有序的, 哪些是无序的? + ##有序的 list tuple + ##无序的 dict set + +##- 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. +## 基本数据类型 +# - `int` (整数) +# - `float`(浮点数) +# - `string`(字符串, 字符序列) +# - 转义字符 +# - `boolean`(布尔值) +# - `bytes`(二进制序列) +###################list############################## +print("-------------------list----------------------------") +print(list([1,2,3,4])) ## int + +print(list([float(1.2),float(2.2)])) # float + +print(list('hello,world')) #string + +print(list("2\\n")) #转义字符 + +print(list([bool(2),bool(2.2),bool(0)])) #boolean + +print(list(bytes(4))) #bytes +print("-------------------list----------------------------") + +###################list############################## + +print("-------------------tuple----------------------------") +###################tuple############################## +print(tuple([1,2,3,4])) ## int + +print(tuple([float(1.2),float(2.2)])) # float + +print(tuple('hello,world')) #string + +print(tuple("2\\n")) #转义字符 + +print(tuple([bool(2),bool(2.2),bool(0)])) #boolean + +print(tuple(bytes(4))) #bytes + +print("-------------------tuple----------------------------") + + +###################tuple############################## + +print("-------------------dict----------------------------") +###################dict############################## +print(dict(a=1,b=2)) ## int + +print(dict(a=1.2,b=2.2) ) # float + +print(dict(a='hello,world')) #string + +print(dict(a="2\\n")) #转义字符 + +print(dict(a=bool(2),b=bool(2.2),c=bool(0))) #boolean + +print(dict(a=bytes(4))) #bytes +print("-------------------dict----------------------------") + +###################dict############################## + +###################set############################## +print("-------------------set----------------------------") +print(set({1,2,3,4,5})) ## int + +print(set([float(1.2),float(2.2)])) # float + +print(set('hello,world')) #string + +print(set("2\n")) #转义字符 + +print(set([bool(2),bool(2.2),bool(0)])) #boolean + +print(set(bytes(4))) #bytes +print("-------------------set----------------------------") ###################set############################## \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" index fcacd0ecb01318c781305148b65c103a3dd25bb4..522fdba721d9f15b744ae060f25c39c22a552e90 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" @@ -1,63 +1,63 @@ -课后作业 -什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. -什么是事务, 事务的特点. -完成Mysql服务端和Navicat的安装. -完成数据库和数据表的基础操作 - - -1.什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. -关系型数据库 -创建在 关系型模型基础上的数据库,用来存储和管理结构化的数据 - -应用---》适用场景 - -考虑到事务和日志 - -对数据完整性有要求. - -存储的数据结构化完整. - -单个数据库服务实例可以满足需求. - -建立集群方案, 大多需要适用企业版, 企业版收费高昂. - -读表操作远远大于写表操作. - -非关系型数据库(Nosql,not noly sql) -创建在 NoSQL系统存储(键对值)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 - - -2.什么是事务, 事务的特点. -关系型数据库的特点(也就是事务的特点) -Atomic(原子性) - -指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 - -A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. -Consistence(一致性) - -事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. - -集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. -一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. -Isolation(隔离性) - -解决多个事务同时对数据进行读写和修改的能力. - -Duration(持久性) - -当某个事务一旦提交, 无论数据库崩溃还是其他原因, 该事务的结果都能够被持久化地保存下来. - -事务的所有操作都是有记录的, 即使数据库中途崩溃, 仍然可以通过记录恢复 - -3.完成Mysql服务端和Navicat的安装. -Mysql服务端 - - - -Navicat安装 - - - -4.完成数据库和数据表的基础操作 - +课后作业 +什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. +什么是事务, 事务的特点. +完成Mysql服务端和Navicat的安装. +完成数据库和数据表的基础操作 + + +1.什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. +关系型数据库 +创建在 关系型模型基础上的数据库,用来存储和管理结构化的数据 + +应用---》适用场景 + +考虑到事务和日志 + +对数据完整性有要求. + +存储的数据结构化完整. + +单个数据库服务实例可以满足需求. + +建立集群方案, 大多需要适用企业版, 企业版收费高昂. + +读表操作远远大于写表操作. + +非关系型数据库(Nosql,not noly sql) +创建在 NoSQL系统存储(键对值)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 + + +2.什么是事务, 事务的特点. +关系型数据库的特点(也就是事务的特点) +Atomic(原子性) + +指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 + +A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. +Consistence(一致性) + +事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. + +集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. +一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. +Isolation(隔离性) + +解决多个事务同时对数据进行读写和修改的能力. + +Duration(持久性) + +当某个事务一旦提交, 无论数据库崩溃还是其他原因, 该事务的结果都能够被持久化地保存下来. + +事务的所有操作都是有记录的, 即使数据库中途崩溃, 仍然可以通过记录恢复 + +3.完成Mysql服务端和Navicat的安装. +Mysql服务端 + + + +Navicat安装 + + + +4.完成数据库和数据表的基础操作 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index ec706605130e871cb96c89bd959bf2b68acdbaad..9ebd447a6570098e86e73ed768aeac7fa1e2a4bf 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,89 +1,89 @@ -##id int PRIMARY KEY auto_increment; - -## CRUD操作 -### 创建表的时候尽量加上create_time字段, 为create_time设置默认值CURRENT_TIMESTAMP -alter table week07_03 add create_time TIMESTAMP not null default CURRENT_TIMESTAMP; - -#创建ID -ALTER table week07_03 add id int(255) PRIMARY key auto_increment FIRST - -## 单条插入数据 -ALTER table week07_03 add name VARCHAR(100) - -## 查询数据 -select age from week07_03 - -select * from week07_03 where name='王霞' and id =1 - -#排序 -## 升序操作(ASC) -select * from week07_03 ORDER BY age asc - -## 降序操作(DESC) -select * from week07_03 ORDER BY age desc - -## 获取查询结果的条数(COUNT) -select COUNT(*) from week07_03 ORDER BY age desc - -##更新字段数据 -update week07_03 set name='王001' where id=1 - -## 删除数据 -delete from week07_03 where name='王001' - - -## 集合操作 - -#并集 -select age from week07_03 where age is not null -union - -select age from test where age is not null - -## 交集 -select s1.age from -(select age from week07_03 where age is not null ) as s1 - -JOIN - -(select age from test where age is not null) as s2 - -ON s1.age=s2.age - - -## A对B的差集(left join) -select *from //s1对s2的差集,select就可以使用s1.age -(select age from test where age is not null)as s1 -left join - -(select age from week07_03 where age is not null)as s2 -on s1.age=s2.age - -where s2.age is null //限定s1有,s2没有的记录 - - -##B对A 的差集(right join) -select *from -(select age from test where age is not null)as s1 -right join - -(select age from week07_03 where age is not null)as s2 -on s1.age=s2.age - -where s1.age is null - -##补集 -select s1.age from -(select age from test where age is not null) as s1 -left join -(select age from week07_03 where age is not null) as s2 -On s1.age=s2.age -where s2.age is null -union -select s2.age from -(select age from test where age is not null )as s1 -right join - -(select age from week07_03 where age is not null)as s2 -on s1.age=s2.age +##id int PRIMARY KEY auto_increment; + +## CRUD操作 +### 创建表的时候尽量加上create_time字段, 为create_time设置默认值CURRENT_TIMESTAMP +alter table week07_03 add create_time TIMESTAMP not null default CURRENT_TIMESTAMP; + +#创建ID +ALTER table week07_03 add id int(255) PRIMARY key auto_increment FIRST + +## 单条插入数据 +ALTER table week07_03 add name VARCHAR(100) + +## 查询数据 +select age from week07_03 + +select * from week07_03 where name='王霞' and id =1 + +#排序 +## 升序操作(ASC) +select * from week07_03 ORDER BY age asc + +## 降序操作(DESC) +select * from week07_03 ORDER BY age desc + +## 获取查询结果的条数(COUNT) +select COUNT(*) from week07_03 ORDER BY age desc + +##更新字段数据 +update week07_03 set name='王001' where id=1 + +## 删除数据 +delete from week07_03 where name='王001' + + +## 集合操作 + +#并集 +select age from week07_03 where age is not null +union + +select age from test where age is not null + +## 交集 +select s1.age from +(select age from week07_03 where age is not null ) as s1 + +JOIN + +(select age from test where age is not null) as s2 + +ON s1.age=s2.age + + +## A对B的差集(left join) +select *from //s1对s2的差集,select就可以使用s1.age +(select age from test where age is not null)as s1 +left join + +(select age from week07_03 where age is not null)as s2 +on s1.age=s2.age + +where s2.age is null //限定s1有,s2没有的记录 + + +##B对A 的差集(right join) +select *from +(select age from test where age is not null)as s1 +right join + +(select age from week07_03 where age is not null)as s2 +on s1.age=s2.age + +where s1.age is null + +##补集 +select s1.age from +(select age from test where age is not null) as s1 +left join +(select age from week07_03 where age is not null) as s2 +On s1.age=s2.age +where s2.age is null +union +select s2.age from +(select age from test where age is not null )as s1 +right join + +(select age from week07_03 where age is not null)as s2 +on s1.age=s2.age where s1.age is null \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" index f4e19ccde99a49e429f66d88c2ceeadbf594fe54..7ea7deeced84d9f40dd4368ba1d1108bc6be1a68 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" @@ -1,129 +1,129 @@ -作业 -1.通过navicat建表, 包含当前常用的数据类型. - -INSERT INTO test(float_field, double_field) values(123.22, 123123.22) -2练习常用的运算符 - -3练习常用的函数 - -1.表中test 添加字段 -## int -ALTER table test add int_field int(10); - -## BIGINT -ALTER table test add bigint_field BIGINT(100); - -## FLOAT -ALTER table test add float_field FLOAT; - -## double -ALTER table test add double_field DOUBLE; - -##decimal -ALTER table test add decimal_field decimal; - -#char -ALTER table test add char_field char(255); - - -#varchar -ALTER table test add varchar_field VARCHAR(1000); - -# text -ALTER table test add text_field LONGTEXT; - -#DATETIME -ALTER table test add datetime_field DATETIME; - - -##----------------------------------------- -添加数据 -##int -insert into test (int_field)values (122) - -## bigint -insert into test (bigint_field)values (1223333) - -## float -insert into test (float_field)values (12.88) - -#double -insert into test (double_field)values (12.88) - -#decimal -insert into test (decimal_field) values (12.88) - - -#char -insert into test (char_field) values ('python') - -#varchar -insert into test (varchar_field) values ('python niubi') - - -#text -insert into test (text_field) values ('python niubi666') - -#datetime -insert into test (datetime_field) values ('2020-01-29') - -查询全部数据 -select * from test - - -2.练习常用的运算符 -#算术运算符 -SELECT 1+1 -SELECT 1-1 -SELECT 1*1 -SELECT 10/4 -SELECT 10 div 4 -SELECT 10 mod 4 - -#比较运算符 -SELECT 10=4 - -SELECT 10!=4 -SELECT 10>4 -SELECT 10>=4 -SELECT 10<=4 - -SELECT 10 between 4 and 100 #答案是1,也就是正确 -SELECT 10 not between 4 and 100 - - - -3.函数运算符 -SUM -MySql 中 sum() 函数用于计算某一字段中所有行的数值之和 -( sum 求和时会对 null 进行过滤,不计算),例如如下查询 - -查询表中所有的年龄总和 -SELECT SUM(age) from test - -SELECT SUM(id) from test - -SELECT AVG(id) from test - -SELECT MAX(id) from test - -SELECT MIN(id) from test - -SELECT count(id) from test - - -字符处理 -select char_length("test") #答案是 4 - -SELECT FORMAT(0.333333,2) 答案是0.33 - -SELECT right("abcdefg", 2) 答案是 fg - -SELECT left("abcdefg", 2) 答案是 ab - -SELECT trim("abcdefg ") 答案是abcdefg - - - - - +作业 +1.通过navicat建表, 包含当前常用的数据类型. + +INSERT INTO test(float_field, double_field) values(123.22, 123123.22) +2练习常用的运算符 + +3练习常用的函数 + +1.表中test 添加字段 +## int +ALTER table test add int_field int(10); + +## BIGINT +ALTER table test add bigint_field BIGINT(100); + +## FLOAT +ALTER table test add float_field FLOAT; + +## double +ALTER table test add double_field DOUBLE; + +##decimal +ALTER table test add decimal_field decimal; + +#char +ALTER table test add char_field char(255); + + +#varchar +ALTER table test add varchar_field VARCHAR(1000); + +# text +ALTER table test add text_field LONGTEXT; + +#DATETIME +ALTER table test add datetime_field DATETIME; + + +##----------------------------------------- +添加数据 +##int +insert into test (int_field)values (122) + +## bigint +insert into test (bigint_field)values (1223333) + +## float +insert into test (float_field)values (12.88) + +#double +insert into test (double_field)values (12.88) + +#decimal +insert into test (decimal_field) values (12.88) + + +#char +insert into test (char_field) values ('python') + +#varchar +insert into test (varchar_field) values ('python niubi') + + +#text +insert into test (text_field) values ('python niubi666') + +#datetime +insert into test (datetime_field) values ('2020-01-29') + +查询全部数据 +select * from test + + +2.练习常用的运算符 +#算术运算符 +SELECT 1+1 +SELECT 1-1 +SELECT 1*1 +SELECT 10/4 +SELECT 10 div 4 +SELECT 10 mod 4 + +#比较运算符 +SELECT 10=4 + +SELECT 10!=4 +SELECT 10>4 +SELECT 10>=4 +SELECT 10<=4 + +SELECT 10 between 4 and 100 #答案是1,也就是正确 +SELECT 10 not between 4 and 100 + + + +3.函数运算符 +SUM +MySql 中 sum() 函数用于计算某一字段中所有行的数值之和 +( sum 求和时会对 null 进行过滤,不计算),例如如下查询 + +查询表中所有的年龄总和 +SELECT SUM(age) from test + +SELECT SUM(id) from test + +SELECT AVG(id) from test + +SELECT MAX(id) from test + +SELECT MIN(id) from test + +SELECT count(id) from test + + +字符处理 +select char_length("test") #答案是 4 + +SELECT FORMAT(0.333333,2) 答案是0.33 + +SELECT right("abcdefg", 2) 答案是 fg + +SELECT left("abcdefg", 2) 答案是 ab + +SELECT trim("abcdefg ") 答案是abcdefg + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\344\275\234\344\270\232.py" index 999d9cdd1cec33de0d07b4869c9f1d6a63c7109a..e9b19db1a5ae37972d38bbe62bc0041640e04d4f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\344\275\234\344\270\232.py" @@ -1,56 +1,56 @@ - -#for 循环两种方式来实现斐波那契函数 -def fib_recur(n): - assert n>=0,"n>0" - if n<=1: - return n - elif n>100: - print("不可输入大于100") - return fib_recur(n-1)+fib_recur(n-2) - -print(fib_recur(3)) - -# while 循环两种方式来实现斐波那契函数 -nterms=int(input("你需要几项?")) -n1=0 -n2=1 -count=2 - -if nterms<=0: - print("请输入一个正数") -elif nterms==1: - print("斐波那契数列:") - print(n1) -elif nterms>100: - print("请输入小于100的数字") -else: - print("斐波那契数列:") - print(n1,",",n2,end=" ,") - while count=0,"n>0" + if n<=1: + return n + elif n>100: + print("不可输入大于100") + return fib_recur(n-1)+fib_recur(n-2) + +print(fib_recur(3)) + +# while 循环两种方式来实现斐波那契函数 +nterms=int(input("你需要几项?")) +n1=0 +n2=1 +count=2 + +if nterms<=0: + print("请输入一个正数") +elif nterms==1: + print("斐波那契数列:") + print(n1) +elif nterms>100: + print("请输入小于100的数字") +else: + print("斐波那契数列:") + print(n1,",",n2,end=" ,") + while count - - - - - - - - - - - - - - - - - - - -鼠标 - 商品搜索 - 京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - -
- -
- -
- -
- -
- - - -
- -
- -
    - -
    - - - - - -
    - -
    - -
    - -
    - - - - - - 我的购物车 - -
    - -
    - -
    - -
    - - - -
    - -
    - -
    - -
    - - - -
    - - - - -
    - - -
    -
    -
    -
    - -
    - > -
    - "鼠标" -
    -
    -
    -
    - -
    - -
    - -
    -
    -
    品牌:
    -
    -
      -
    • 所有品牌
    • -
    • A
    • -
    • B
    • -
    • C
    • -
    • D
    • -
    • E
    • -
    • F
    • -
    • G
    • -
    • H
    • -
    • I
    • -
    • J
    • -
    • K
    • -
    • L
    • -
    • M
    • -
    • N
    • -
    • O
    • -
    • P
    • -
    • Q
    • -
    • R
    • -
    • S
    • -
    • T
    • -
    • U
    • -
    • W
    • -
    • X
    • -
    • Y
    • -
    • Z
    • -
    -
    -
    - -
    -
    已选条件:
      -
      - 确定 - 取消 -
      -
      -
      - 更多 - 多选 -
      -
      -
      -
      -
      -
      外设产品:
      -
      -
      - -
      -
      - 确定 - 取消 -
      -
      -
      - 更多 - -
      -
      -
      - -
      -
      -
      电脑整机:
      -
      -
      - -
      -
      - 确定 - 取消 -
      -
      -
      - 更多 - -
      -
      -
      - -
      -
      -
      连接方式:
      -
      -
      - -
      -
      - 确定 - 取消 -
      -
      -
      - 更多 - 多选 -
      -
      -
      -
      -
      -
      适用场景:
      -
      -
      - -
      -
      - 确定 - 取消 -
      -
      -
      - 更多 - 多选 -
      -
      -
      -
      -
      -
      高级选项:
      - -
      - - - - - - - - - - - -
      -
      -
      -
      -
      -
      - -
      -
      - -
      - - - - - -
      -
      -
      -
      - - -
      -
      -
      - - 清空 - 确定 -
      -
      -
      - - 1/100 - - < - > -
      -
      71万+件商品
      - -
      -
      -
      -
      配送至
      -
      -
      -
      北京
      - -
      -
      -
      -
      -
      -
      -
      - - -
      -
      - - -
      - - - -
      -
      正在加载中,请稍后~~
      -
      -
      -
      -
      -
      -
      - -

      商品精选

      -
      -
        -
      -
      -
      -

      精品推荐

      - -
      -
      - -
      - - -
      -
      -
      -
      -
      - -
      商品精选
      -
      -
      -
      -
      - -
      -
      -
      -
      - - -
      - -
      - -
        - -
      1. - - 品类齐全,轻松购物 - -
      2. - -
      3. - - 多仓直发,极速配送 - -
      4. - -
      5. - - 正品行货,精致服务 - -
      6. - -
      7. - - 天天低价,畅选无忧 - -
      8. - -
      - -
      - -
      - -
      - -
      - -
      - -
      购物指南
      - -
      - - 购物流程 - -
      - -
      - - 会员介绍 - -
      - -
      - - 生活旅行/团购 - -
      - -
      - - 常见问题 - -
      - -
      - - 大家电 - -
      - -
      - - 联系客服 - -
      - -
      - -
      - -
      配送方式
      - -
      - - 上门自提 - -
      - -
      - - 211限时达 - -
      - -
      - - 配送服务查询 - -
      - -
      - - 配送费收取标准 - -
      - -
      - - 海外配送 - -
      - -
      - -
      - -
      支付方式
      - -
      - - 货到付款 - -
      - -
      - - 在线支付 - -
      - -
      - - 分期付款 - -
      - -
      - - 公司转账 - -
      - -
      - -
      - -
      售后服务
      - -
      - - 售后政策 - -
      - -
      - - 价格保护 - -
      - -
      - - 退款说明 - -
      - -
      - - 返修/退换货 - -
      - -
      - - 取消订单 - -
      - -
      - -
      - -
      特色服务
      - -
      - - 夺宝岛 - -
      - -
      - - DIY装机 - -
      - -
      - - 延保服务 - -
      - -
      - - 京东E卡 - -
      - -
      - - 京东通信 - -
      - -
      - - 京鱼座智能 - -
      - -
      - - - -
      - -
      - -
      - -
      - - - - - -
      - - - - - - - + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      + +
      + + + + + + + +
      + +
      + +
      + +
      + +
      + + + +
      + +
      + +
        + +
        + + + + + +
        + +
        + +
        + +
        + + + + + + 我的购物车 + +
        + +
        + +
        + +
        + + + +
        + +
        + +
        + +
        + + + +
        + + + + +
        + + +
        +
        +
        +
        + +
        + > +
        + "鼠标" +
        +
        +
        +
        + +
        + +
        + +
        +
        +
        品牌:
        +
        +
          +
        • 所有品牌
        • +
        • A
        • +
        • B
        • +
        • C
        • +
        • D
        • +
        • E
        • +
        • F
        • +
        • G
        • +
        • H
        • +
        • I
        • +
        • J
        • +
        • K
        • +
        • L
        • +
        • M
        • +
        • N
        • +
        • O
        • +
        • P
        • +
        • Q
        • +
        • R
        • +
        • S
        • +
        • T
        • +
        • U
        • +
        • W
        • +
        • X
        • +
        • Y
        • +
        • Z
        • +
        +
        +
        + +
        +
        已选条件:
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + 多选 +
          +
          +
          +
          +
          +
          外设产品:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + +
          +
          +
          + +
          +
          +
          电脑整机:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + +
          +
          +
          + +
          +
          +
          连接方式:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + 多选 +
          +
          +
          +
          +
          +
          适用场景:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + 多选 +
          +
          +
          +
          +
          +
          高级选项:
          + +
          + + + + + + + + + + + +
          +
          +
          +
          +
          +
          + +
          +
          + +
          + + + + + +
          +
          +
          +
          + - +
          +
          +
          + + 清空 + 确定 +
          +
          +
          + + 1/100 + + < + > +
          +
          71万+件商品
          + +
          +
          +
          +
          配送至
          +
          +
          +
          北京
          + +
          +
          +
          +
          +
          +
          +
          + + +
          +
          + + +
          + + + +
          +
          正在加载中,请稍后~~
          +
          +
          +
          +
          +
          +
          + +

          商品精选

          +
          +
            +
          +
          +
          +

          精品推荐

          + +
          +
          + +
          + + +
          +
          +
          +
          +
          + +
          商品精选
          +
          +
          +
          +
          + +
          +
          +
          +
          + + +
          + +
          + +
            + +
          1. + + 品类齐全,轻松购物 + +
          2. + +
          3. + + 多仓直发,极速配送 + +
          4. + +
          5. + + 正品行货,精致服务 + +
          6. + +
          7. + + 天天低价,畅选无忧 + +
          8. + +
          + +
          + +
          + +
          + +
          + +
          + +
          购物指南
          + +
          + + 购物流程 + +
          + +
          + + 会员介绍 + +
          + +
          + + 生活旅行/团购 + +
          + +
          + + 常见问题 + +
          + +
          + + 大家电 + +
          + +
          + + 联系客服 + +
          + +
          + +
          + +
          配送方式
          + +
          + + 上门自提 + +
          + +
          + + 211限时达 + +
          + +
          + + 配送服务查询 + +
          + +
          + + 配送费收取标准 + +
          + +
          + + 海外配送 + +
          + +
          + +
          + +
          支付方式
          + +
          + + 货到付款 + +
          + +
          + + 在线支付 + +
          + +
          + + 分期付款 + +
          + +
          + + 公司转账 + +
          + +
          + +
          + +
          售后服务
          + +
          + + 售后政策 + +
          + +
          + + 价格保护 + +
          + +
          + + 退款说明 + +
          + +
          + + 返修/退换货 + +
          + +
          + + 取消订单 + +
          + +
          + +
          + +
          特色服务
          + +
          + + 夺宝岛 + +
          + +
          + + DIY装机 + +
          + +
          + + 延保服务 + +
          + +
          + + 京东E卡 + +
          + +
          + + 京东通信 + +
          + +
          + + 京鱼座智能 + +
          + +
          + + + +
          + +
          + +
          + +
          + + + + + +
          + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" index e1ed738fd28ce66164ab5bae0bac0c7587898416..a2a9e56053d81abacb71018e99595539e865584f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" @@ -1,96 +1,96 @@ - -import pymysql -import requests -from bs4 import BeautifulSoup -import json - -import threading -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36", - "upgrade-insecure-requests": "1" -} -conf= { - "host": "127.0.0.1", - "user": "root", - "password": "root", - "db": "tunan_class" -} - -def saver(item_array): - """ - 持久化爬取结果 - :param item_array: - :return: - """ - cursor = mysql_con.cursor() - SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) - VALUES (%s, %s, %s, %s, %s, %s)""" - cursor.executemany(SQL, item_array) - mysql_con.commit() - cursor.close() - -def parse_jd_item(html): - result = [] - - soup = BeautifulSoup(html, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' - - result.append((sku_id, img, price, title, shop, icons)) - - return result - - -def downloader(task): - """ - 请求目标网址的组件 - :param task: - :return: - """ - url = "https://search.jd.com/Search" - params = { - "keyword": task - } - res = requests.get(url=url, params=params, headers=HEADERS, timeout=5, proxies={ - "https": f"https:144.255.48.62", - "http": f"http:144.255.48.62" - }) - return res - - -def main(task_array): - """ - 爬虫任务的调度 - :return: - """ - for task in task_array: - result = downloader(task) - - item_array = parse_jd_item(result.text) - print("GET ITEMS", item_array) - saver(item_array) - - - -if __name__ == "__main__": - #用来代替生产者 - mysql_con = pymysql.connect(**conf) - task_array = ["鼠标", "键盘", "显卡", "耳机"] - main(task_array) - for i in range(1, 5): - t = threading.Thread(target=main(task_array)) - t.start() - - + +import pymysql +import requests +from bs4 import BeautifulSoup +import json + +import threading +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36", + "upgrade-insecure-requests": "1" +} +conf= { + "host": "127.0.0.1", + "user": "root", + "password": "root", + "db": "tunan_class" +} + +def saver(item_array): + """ + 持久化爬取结果 + :param item_array: + :return: + """ + cursor = mysql_con.cursor() + SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) + VALUES (%s, %s, %s, %s, %s, %s)""" + cursor.executemany(SQL, item_array) + mysql_con.commit() + cursor.close() + +def parse_jd_item(html): + result = [] + + soup = BeautifulSoup(html, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' + + result.append((sku_id, img, price, title, shop, icons)) + + return result + + +def downloader(task): + """ + 请求目标网址的组件 + :param task: + :return: + """ + url = "https://search.jd.com/Search" + params = { + "keyword": task + } + res = requests.get(url=url, params=params, headers=HEADERS, timeout=5, proxies={ + "https": f"https:144.255.48.62", + "http": f"http:144.255.48.62" + }) + return res + + +def main(task_array): + """ + 爬虫任务的调度 + :return: + """ + for task in task_array: + result = downloader(task) + + item_array = parse_jd_item(result.text) + print("GET ITEMS", item_array) + saver(item_array) + + + +if __name__ == "__main__": + #用来代替生产者 + mysql_con = pymysql.connect(**conf) + task_array = ["鼠标", "键盘", "显卡", "耳机"] + main(task_array) + for i in range(1, 5): + t = threading.Thread(target=main(task_array)) + t.start() + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/search.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/search.html" index 219cc7085db38b4da894d9cc4abbb06c3112f92a..d587a4f072369822700ec0a700e323b1c48335e4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/search.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/search.html" @@ -1,6653 +1,6653 @@ - - - - - - - - - - - - - - - - - - - - -鼠标 - 商品搜索 - 京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          -
          - - - -
          -
          -
          -
          -
          - -
          -
          -
            -
            - - -
            -
            -
            -
            - - - 我的购物车 -
            -
            -
            -
            - -
            -
            -
            -
            - -
            - - -
            - - -
            -
            -
            -
            - -
            - > -
            - "鼠标" -
            -
            -
            -
            - -
            - -
            - -
            -
            -
            品牌:
            -
            -
              -
            • 所有品牌
            • -
            • A
            • -
            • B
            • -
            • C
            • -
            • D
            • -
            • E
            • -
            • F
            • -
            • G
            • -
            • H
            • -
            • I
            • -
            • J
            • -
            • K
            • -
            • L
            • -
            • M
            • -
            • N
            • -
            • O
            • -
            • P
            • -
            • Q
            • -
            • R
            • -
            • S
            • -
            • T
            • -
            • U
            • -
            • W
            • -
            • X
            • -
            • Y
            • -
            • Z
            • -
            -
            -
            - -
            -
            已选条件:
              -
              - 确定 - 取消 -
              -
              -
              - 更多 - 多选 -
              -
              -
              -
              -
              -
              外设产品:
              -
              -
              - -
              -
              - 确定 - 取消 -
              -
              -
              - 更多 - -
              -
              -
              - -
              -
              -
              电脑整机:
              -
              -
              - -
              -
              - 确定 - 取消 -
              -
              -
              - 更多 - -
              -
              -
              - -
              -
              -
              连接方式:
              -
              -
              - -
              -
              - 确定 - 取消 -
              -
              -
              - 更多 - 多选 -
              -
              -
              -
              -
              -
              适用场景:
              -
              -
              - -
              -
              - 确定 - 取消 -
              -
              -
              - 更多 - 多选 -
              -
              -
              -
              -
              -
              高级选项:
              - -
              - - - - - - - - - - - - - - - -
              -
              -
              -
              -
              -
              - -
              -
              - -
              - - - - - -
              -
              -
              -
              - - -
              -
              -
              - - 清空 - 确定 -
              -
              -
              - - 1/100 - - < - > -
              -
              63万+件商品
              - -
              -
              -
              -
              配送至
              -
              -
              -
              北京
              - -
              -
              -
              -
              -
              -
              -
              - - -
              -
              - - -
              - - - -
              -
              正在加载中,请稍后~~
              -
              -
              -
              -
              -
              -
              - -

              商品精选

              -
              -
                -
              -
              -
              -

              精品推荐

              - -
              -
              - -
              - - -
              -
              -
              -
              -
              - -
              商品精选
              -
              -
              -
              -
              - -
              -
              -
              -
              - -
              -
              -
                -
              1. - 品类齐全,轻松购物 -
              2. -
              3. - 多仓直发,极速配送 -
              4. -
              5. - 正品行货,精致服务 -
              6. -
              7. - 天天低价,畅选无忧 -
              8. -
              -
              -
              -
              -
              -
              -
              购物指南
              -
              - 购物流程 -
              -
              - 会员介绍 -
              -
              - 生活旅行/团购 -
              -
              - 常见问题 -
              -
              - 大家电 -
              -
              - 联系客服 -
              -
              -
              -
              配送方式
              -
              - 上门自提 -
              -
              - 211限时达 -
              -
              - 配送服务查询 -
              -
              - 配送费收取标准 -
              -
              - 海外配送 -
              -
              -
              -
              支付方式
              -
              - 货到付款 -
              -
              - 在线支付 -
              -
              - 分期付款 -
              -
              - 公司转账 -
              -
              -
              -
              售后服务
              -
              - 售后政策 -
              -
              - 价格保护 -
              -
              - 退款说明 -
              -
              - 返修/退换货 -
              -
              - 取消订单 -
              -
              -
              -
              特色服务
              -
              - 夺宝岛 -
              -
              - DIY装机 -
              -
              - 延保服务 -
              -
              - 京东E卡 -
              -
              - 京东通信 -
              -
              - 京鱼座智能 -
              -
              - -
              -
              -
              -
              - - -
              - - - - - + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              +
              + + + +
              +
              +
              +
              +
              + +
              +
              +
                +
                + + +
                +
                +
                +
                + + + 我的购物车 +
                +
                +
                +
                + +
                +
                +
                +
                + +
                + + +
                + + +
                +
                +
                +
                + +
                + > +
                + "鼠标" +
                +
                +
                +
                + +
                + +
                + +
                +
                +
                品牌:
                +
                +
                  +
                • 所有品牌
                • +
                • A
                • +
                • B
                • +
                • C
                • +
                • D
                • +
                • E
                • +
                • F
                • +
                • G
                • +
                • H
                • +
                • I
                • +
                • J
                • +
                • K
                • +
                • L
                • +
                • M
                • +
                • N
                • +
                • O
                • +
                • P
                • +
                • Q
                • +
                • R
                • +
                • S
                • +
                • T
                • +
                • U
                • +
                • W
                • +
                • X
                • +
                • Y
                • +
                • Z
                • +
                +
                +
                + +
                +
                已选条件:
                  +
                  + 确定 + 取消 +
                  +
                  +
                  + 更多 + 多选 +
                  +
                  +
                  +
                  +
                  +
                  外设产品:
                  +
                  +
                  + +
                  +
                  + 确定 + 取消 +
                  +
                  +
                  + 更多 + +
                  +
                  +
                  + +
                  +
                  +
                  电脑整机:
                  +
                  +
                  + +
                  +
                  + 确定 + 取消 +
                  +
                  +
                  + 更多 + +
                  +
                  +
                  + +
                  +
                  +
                  连接方式:
                  +
                  +
                  + +
                  +
                  + 确定 + 取消 +
                  +
                  +
                  + 更多 + 多选 +
                  +
                  +
                  +
                  +
                  +
                  适用场景:
                  +
                  +
                  + +
                  +
                  + 确定 + 取消 +
                  +
                  +
                  + 更多 + 多选 +
                  +
                  +
                  +
                  +
                  +
                  高级选项:
                  + +
                  + + + + + + + + + + + + + + + +
                  +
                  +
                  +
                  +
                  +
                  + +
                  +
                  + +
                  + + + + + +
                  +
                  +
                  +
                  + - +
                  +
                  +
                  + + 清空 + 确定 +
                  +
                  +
                  + + 1/100 + + < + > +
                  +
                  63万+件商品
                  + +
                  +
                  +
                  +
                  配送至
                  +
                  +
                  +
                  北京
                  + +
                  +
                  +
                  +
                  +
                  +
                  +
                  + + +
                  +
                  + + +
                  + + + +
                  +
                  正在加载中,请稍后~~
                  +
                  +
                  +
                  +
                  +
                  +
                  + +

                  商品精选

                  +
                  +
                    +
                  +
                  +
                  +

                  精品推荐

                  + +
                  +
                  + +
                  + + +
                  +
                  +
                  +
                  +
                  + +
                  商品精选
                  +
                  +
                  +
                  +
                  + +
                  +
                  +
                  +
                  + +
                  +
                  +
                    +
                  1. + 品类齐全,轻松购物 +
                  2. +
                  3. + 多仓直发,极速配送 +
                  4. +
                  5. + 正品行货,精致服务 +
                  6. +
                  7. + 天天低价,畅选无忧 +
                  8. +
                  +
                  +
                  +
                  +
                  +
                  +
                  购物指南
                  +
                  + 购物流程 +
                  +
                  + 会员介绍 +
                  +
                  + 生活旅行/团购 +
                  +
                  + 常见问题 +
                  +
                  + 大家电 +
                  +
                  + 联系客服 +
                  +
                  +
                  +
                  配送方式
                  +
                  + 上门自提 +
                  +
                  + 211限时达 +
                  +
                  + 配送服务查询 +
                  +
                  + 配送费收取标准 +
                  +
                  + 海外配送 +
                  +
                  +
                  +
                  支付方式
                  +
                  + 货到付款 +
                  +
                  + 在线支付 +
                  +
                  + 分期付款 +
                  +
                  + 公司转账 +
                  +
                  +
                  +
                  售后服务
                  +
                  + 售后政策 +
                  +
                  + 价格保护 +
                  +
                  + 退款说明 +
                  +
                  + 返修/退换货 +
                  +
                  + 取消订单 +
                  +
                  +
                  +
                  特色服务
                  +
                  + 夺宝岛 +
                  +
                  + DIY装机 +
                  +
                  + 延保服务 +
                  +
                  + 京东E卡 +
                  +
                  + 京东通信 +
                  +
                  + 京鱼座智能 +
                  +
                  + +
                  +
                  +
                  +
                  + + +
                  + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" index 9f29a44f83a2dbaff50bc1392bd8cfa9aef39956..fa6d793eb4edc5e8998a598aee1e94b37e9f88eb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" @@ -1,21 +1,21 @@ -##练习css-selector -##练习用beautifulsoup进行页面解析 - -from bs4 import BeautifulSoup - -def jd_search_parse(html): - html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") - soup = BeautifulSoup(html, 'lxml') - item = soup.select("li[data-sku='6039832']")[0] - print(item.next_sibling.next_sibling) - print(item.previous_sibling) - print(item.parent) - print(item.children) - content = item.text.strip() - value = item.attrs["data-sku"] - - -if __name__ == "__main__": - with open("jd_search.html","r",encoding="utf-8") as f: - html=f.read() +##练习css-selector +##练习用beautifulsoup进行页面解析 + +from bs4 import BeautifulSoup + +def jd_search_parse(html): + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") + soup = BeautifulSoup(html, 'lxml') + item = soup.select("li[data-sku='6039832']")[0] + print(item.next_sibling.next_sibling) + print(item.previous_sibling) + print(item.parent) + print(item.children) + content = item.text.strip() + value = item.attrs["data-sku"] + + +if __name__ == "__main__": + with open("jd_search.html","r",encoding="utf-8") as f: + html=f.read() jd_search_parse(html) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276.py" index d97a4366e3c5019a32aa5c3e6a6b555470130e5e..6b660bee5a6a0933720c165b5c020d08f4dca643 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276.py" @@ -1,65 +1,65 @@ -## 课后作业 -#- `+` 加法 -# `-` 减法 -#- `*` 乘法 -## - ` / ` 除法 -## - ` // ` 整除 -#- ` % ` 取余数 -## - ` ** ` x的y次幂 -# - 开方(没有提供直接的运算符) x ** (1 / 2) -#- abs() 取绝对值 - - -#- 用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 - ##my_calculator.py - - ## def add(a, b): - ## ... - ##def sqrt(a, b): - -# 加法 -def add(a,b): - return a+b; -print("-------------------加法----------------->a+b=",add(2,3)) - -# 减法 -def jian(a,b): - return a-b; -print("-------------------减法----------------->a-b=",jian(3,2)) - -# 乘法 -def cheng(a,b): - return a*b; -print("-------------------乘法-----------------a*b=>",cheng(2,3)) - -# 除法 -def chu(a,b): - return a/b; -print("-------------------除法-----------------a/b=>",chu(2,3)) - -# 整除 -def zhengchu(a,b): - return a//b; -print("-------------------整除-----------------a//b=>",zhengchu(3,2)) - -#取余数 -def quyushu(a,b): - return a%b; -print("-------------------取余数-----------------a%b=>",quyushu(3,2)) - -#x的y次幂 -def ycimi(a,b): - return a**b; -print("-------------------x的y次幂-----------------x**y=>",ycimi(2,3)) - - -# 开方(没有提供直接的运算符) x ** (1 / 2) -def kaifang(a): - return a**(1/2); -print("-------------------x的y次幂-----------------x**(1/2)=>",kaifang(4)) - - -#- abs() 取绝对值 -def qujueduizhi(a): - return abs(a); +## 课后作业 +#- `+` 加法 +# `-` 减法 +#- `*` 乘法 +## - ` / ` 除法 +## - ` // ` 整除 +#- ` % ` 取余数 +## - ` ** ` x的y次幂 +# - 开方(没有提供直接的运算符) x ** (1 / 2) +#- abs() 取绝对值 + + +#- 用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 + ##my_calculator.py + + ## def add(a, b): + ## ... + ##def sqrt(a, b): + +# 加法 +def add(a,b): + return a+b; +print("-------------------加法----------------->a+b=",add(2,3)) + +# 减法 +def jian(a,b): + return a-b; +print("-------------------减法----------------->a-b=",jian(3,2)) + +# 乘法 +def cheng(a,b): + return a*b; +print("-------------------乘法-----------------a*b=>",cheng(2,3)) + +# 除法 +def chu(a,b): + return a/b; +print("-------------------除法-----------------a/b=>",chu(2,3)) + +# 整除 +def zhengchu(a,b): + return a//b; +print("-------------------整除-----------------a//b=>",zhengchu(3,2)) + +#取余数 +def quyushu(a,b): + return a%b; +print("-------------------取余数-----------------a%b=>",quyushu(3,2)) + +#x的y次幂 +def ycimi(a,b): + return a**b; +print("-------------------x的y次幂-----------------x**y=>",ycimi(2,3)) + + +# 开方(没有提供直接的运算符) x ** (1 / 2) +def kaifang(a): + return a**(1/2); +print("-------------------x的y次幂-----------------x**(1/2)=>",kaifang(4)) + + +#- abs() 取绝对值 +def qujueduizhi(a): + return abs(a); print("-------------------abs(a)----------------abs(a)=>",qujueduizhi(-4)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" index 2ea90eb1cf0d31e8127a975e3637778569028281..8275667ef744aec15998719791d475e1799379c9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232.py" @@ -1,230 +1,230 @@ -#############课后作业 -#完成四大基础数据结构的CRUD操作 -#List(列表) -#list中存的元素是引用 - -## Create(增加)#append() - -l=[] -print(id(l)) # id 4379634688 -l.append("a") -print(id(l)) # id 4379634688 - -# + 和+= -l_1=['a'] -l_2=['b'] -l_3=l_1+l_2 -print("------------- ",l_3) - -l_3+=l_1 -print("-------+=------ ",l_3) - -# *和*= -a='a' -print(id(a)) # 4452342320 -l=[a]*10 -print("--------*-----",l) -print(id(l[0])) # 4563065520 -print(id(l[9])) #4563065520 - -## 赋值语句之后, a已经是一个新的对象了 -a='b' -print(l) -print(id(a)) #4538688240 - - -#insert 指定位置添加元素 - -l.insert(0,"love") -print("-----insert--------",l) - -###Retrieve(检索) -##索引取值 -#所有序列都支持索引取值 - -#切片 -#your_list[start:end:step] -print(l[0:9:2]) -# 取一段区间 -#your_list[start:end] -print(l[0:8]) -# 取最后一个值 -#your_list[-1] -print(l[-1]) -# 间隔问题 -#your_list[1:20:2] -print(l[1:20:2]) - -#index -print(l) -print("------index-----",l.index('love')) - -##Update(更新) -#索引赋值 -l[1]='a_1' -print(l) - -#切片赋值 -print(l) -l[0:2]="a" -print(l) -l[0:2]='11' -print(l) - - -###DELETE(删除) - -##pop() -#从末尾删除元素并返回 - -print(l) -x=l.pop() -print(l) -print(x) - -##clear() 清楚当前列表的元素, 不会改变列表的内存地址. -print(l) -#l.clear() -print(l) - -# ★SORT(排序) -#sort() -l=[1,3,4,2,5,8,6] -l.sort() -print(l) - -# sorted 排序后返回新列表 -l2=sorted(l) -print(l2) - -#reverse -l2.reverse() -print("---reverse----",l2) - -#reversed 倒序之后返回新列表 (这个有问题) -#print(l) -#list(reversed(l)) -#print(l) - - -###tuple - -##Create - -##无 - -##Retrieve - -#索引取值 -#index -#切片 -#Update 无 -#Delete 无 - -## dict -#create 键对值赋值 -#update 提供合并字典的功能 -d={"a":1} -print(d) -d2={"b":2,"c":3} -d.update(d2) -print("---update---",d) - -#setdefault -#如果字典中没有当前key, 那么就设置默认值 - -d.setdefault('b',0) -print(d) -d.setdefault('d',0) -print(d) - - -##Retrieve - -#键对值访问 - -#get -#键对值访问缺失key会报错, 而get可以指定默认值 - - -#print(d['e']) -# print(d['e']) -# KeyError: 'e' -c=d.get('f',0) -print(c) - -##keys() 返回所有key - -print("-----keys----",d.keys()) - -##values() 返回所有value -print(d.values()) - -##items() 返回所有键对值 -print(d.items()) - -#Update 键对值赋值 - -d['a']=100 -print(d) - -#update -d.update({"b":200,"c":300}) -print(d) - -###Delete - -##pop(key) 删除当前元素并返回value - -##popitem() 对于人来说, 相当于随机返回一个item - -##clear() - - -##set - -#Create -s=set({1,2,3,4}) -print(s) - - -#add -s.add(5) -print(s) -#update -#s.update(66) -print(s) - -##Retrieve - -#运算符in -print( 1 in s) - - -#update - -#union 合并两个set, 并返回一个新的set - -s1=set({1}) -s2=set({2}) -s3=s1.union(s2) -print("set.union",s3) - -##delete - -#remove 和discard - -#discard缺失元素时不会报错, 而remove会报错 - -s=set({'a','b','c'}) -print(s) -s.remove('a') -print(s) -s.discard("e") -print(s) -#s.remove('a') #s.remove('a') KeyError: 'a' -print(s) - -#pop() 当成无序删除并返回元素 -s.pop() -print(s) +#############课后作业 +#完成四大基础数据结构的CRUD操作 +#List(列表) +#list中存的元素是引用 + +## Create(增加)#append() + +l=[] +print(id(l)) # id 4379634688 +l.append("a") +print(id(l)) # id 4379634688 + +# + 和+= +l_1=['a'] +l_2=['b'] +l_3=l_1+l_2 +print("------------- ",l_3) + +l_3+=l_1 +print("-------+=------ ",l_3) + +# *和*= +a='a' +print(id(a)) # 4452342320 +l=[a]*10 +print("--------*-----",l) +print(id(l[0])) # 4563065520 +print(id(l[9])) #4563065520 + +## 赋值语句之后, a已经是一个新的对象了 +a='b' +print(l) +print(id(a)) #4538688240 + + +#insert 指定位置添加元素 + +l.insert(0,"love") +print("-----insert--------",l) + +###Retrieve(检索) +##索引取值 +#所有序列都支持索引取值 + +#切片 +#your_list[start:end:step] +print(l[0:9:2]) +# 取一段区间 +#your_list[start:end] +print(l[0:8]) +# 取最后一个值 +#your_list[-1] +print(l[-1]) +# 间隔问题 +#your_list[1:20:2] +print(l[1:20:2]) + +#index +print(l) +print("------index-----",l.index('love')) + +##Update(更新) +#索引赋值 +l[1]='a_1' +print(l) + +#切片赋值 +print(l) +l[0:2]="a" +print(l) +l[0:2]='11' +print(l) + + +###DELETE(删除) + +##pop() +#从末尾删除元素并返回 + +print(l) +x=l.pop() +print(l) +print(x) + +##clear() 清楚当前列表的元素, 不会改变列表的内存地址. +print(l) +#l.clear() +print(l) + +# ★SORT(排序) +#sort() +l=[1,3,4,2,5,8,6] +l.sort() +print(l) + +# sorted 排序后返回新列表 +l2=sorted(l) +print(l2) + +#reverse +l2.reverse() +print("---reverse----",l2) + +#reversed 倒序之后返回新列表 (这个有问题) +#print(l) +#list(reversed(l)) +#print(l) + + +###tuple + +##Create + +##无 + +##Retrieve + +#索引取值 +#index +#切片 +#Update 无 +#Delete 无 + +## dict +#create 键对值赋值 +#update 提供合并字典的功能 +d={"a":1} +print(d) +d2={"b":2,"c":3} +d.update(d2) +print("---update---",d) + +#setdefault +#如果字典中没有当前key, 那么就设置默认值 + +d.setdefault('b',0) +print(d) +d.setdefault('d',0) +print(d) + + +##Retrieve + +#键对值访问 + +#get +#键对值访问缺失key会报错, 而get可以指定默认值 + + +#print(d['e']) +# print(d['e']) +# KeyError: 'e' +c=d.get('f',0) +print(c) + +##keys() 返回所有key + +print("-----keys----",d.keys()) + +##values() 返回所有value +print(d.values()) + +##items() 返回所有键对值 +print(d.items()) + +#Update 键对值赋值 + +d['a']=100 +print(d) + +#update +d.update({"b":200,"c":300}) +print(d) + +###Delete + +##pop(key) 删除当前元素并返回value + +##popitem() 对于人来说, 相当于随机返回一个item + +##clear() + + +##set + +#Create +s=set({1,2,3,4}) +print(s) + + +#add +s.add(5) +print(s) +#update +#s.update(66) +print(s) + +##Retrieve + +#运算符in +print( 1 in s) + + +#update + +#union 合并两个set, 并返回一个新的set + +s1=set({1}) +s2=set({2}) +s3=s1.union(s2) +print("set.union",s3) + +##delete + +#remove 和discard + +#discard缺失元素时不会报错, 而remove会报错 + +s=set({'a','b','c'}) +print(s) +s.remove('a') +print(s) +s.discard("e") +print(s) +#s.remove('a') #s.remove('a') KeyError: 'a' +print(s) + +#pop() 当成无序删除并返回元素 +s.pop() +print(s) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276.py" index 7093f3d3bb65c9bbecbc43404e0971d5a9ca7ae7..4845384ef9c0b5650dd7b26dac65b4d9dedaf027 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276.py" @@ -1,123 +1,123 @@ -# 1.练习字符串的编码和解码 -#2.练习字符串的CRUD -#3.练习字符串的格式化 -#4.将 content内容保存到本地 - -# 1.练习字符串的编码和解码 -#编码 -a="你好".encode("utf-8") -print("编码-----------a=>",a) -#---------------------结果为 b'\xe4\xbd\xa0\xe5\xa5\xbd'-------------- - - -#解码 -print("解码-------------->b=>",a.decode("utf")) - -## 字符串的CRUD -#Create(创建) -# + -a="hello" -b=a+"world" -print(b) -# += -# a+=b 就是 a=a+b - -#Retrieve(检索) -#根据索引获取字符串 -# 在计算机语言中,索引值是从0开始的 -#a="hello ,world" a[1] - -# find(获取目标字符串的索引值) -# a.find("a") - -# index 找不到目标值会报错 - -#startswith() 和 endwith() - -a="2020-12-26-xxxx" -print("------startswith-------->",a.startswith("2020-12-26")) -print("-------endswith--------->",a.endswith("xxxx")) - - -# UPDATE(更新) - #replace(替换) 返回一个新的字符串 - -a="hello werld,hello werld" -print("----------replace----》",a.replace("wer","wor")) - -# split(分割) -a="<>,<>,<>" -print("--------split-------split>",a.split(",")) - -# join(拼接) -b=a.split(",") -print("-----join--->",",".join(b)) - - -# DELETE() - # strip -a = " hello,world " -print("--------------strip----------->",a.strip()) - # lstrip -print("--------------lstrip----------->",a.lstrip()) - #rstrip -print("--------------rstrip----------->",a.rstrip()) - - # dir("") 查看命令和方法 - - - ### 字符串的输入和输出 - #保存到文件 -#open 函数打开一个文件,没有文件会创建,但是路径不对会报错 -# 制定文件名,方法(读,写,追加),编码格式 -# -output=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","w",encoding="utf-8") -content="hello,world" -#正式写入文件 -output.write(content) -#关闭文件句柄 -output.close() - - -### 读取文件 -input=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","r",encoding="utf-8") -content=input.read(); -print("-------------文件读取------》",content); - - -##追加模式 -output=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","a",encoding="utf-8") -content="\npython" -#正式写入文件 -output.write(content) -#关闭文件句柄 -output.close() - - -### 字符串的格式化输出 -# format 按照传入的参数默认顺序 -a="ping" -b="pang" -print("-----按照传入的参数默认顺序------>play pingpong:{},{}".format(a,b)) - -#按照制定的参数索引 -print("-----按照制定的参数索引------ >play pingpong:{0},{1},{0},{1}".format(a,b,a,b)) - -# 按照关键词参数 -print("-----按照关键词参数------ >play pingpong:{a},{b},{a},{b}".format(a='ping',b='pong')) - -# 按照变量 只有Python3.6以上版本才有 -print("-----按照变量------》"f"play pingpang:{a},{b}") -# 小数的表示 -a="{:.2f}".format(3.1415926) -print("------小数的表示--->",a) - -# %进行格式化 -a="playing %s %s" %("ping","pong") -print("-----%进行格式化---",a) - - - - - - +# 1.练习字符串的编码和解码 +#2.练习字符串的CRUD +#3.练习字符串的格式化 +#4.将 content内容保存到本地 + +# 1.练习字符串的编码和解码 +#编码 +a="你好".encode("utf-8") +print("编码-----------a=>",a) +#---------------------结果为 b'\xe4\xbd\xa0\xe5\xa5\xbd'-------------- + + +#解码 +print("解码-------------->b=>",a.decode("utf")) + +## 字符串的CRUD +#Create(创建) +# + +a="hello" +b=a+"world" +print(b) +# += +# a+=b 就是 a=a+b + +#Retrieve(检索) +#根据索引获取字符串 +# 在计算机语言中,索引值是从0开始的 +#a="hello ,world" a[1] + +# find(获取目标字符串的索引值) +# a.find("a") + +# index 找不到目标值会报错 + +#startswith() 和 endwith() + +a="2020-12-26-xxxx" +print("------startswith-------->",a.startswith("2020-12-26")) +print("-------endswith--------->",a.endswith("xxxx")) + + +# UPDATE(更新) + #replace(替换) 返回一个新的字符串 + +a="hello werld,hello werld" +print("----------replace----》",a.replace("wer","wor")) + +# split(分割) +a="<>,<>,<>" +print("--------split-------split>",a.split(",")) + +# join(拼接) +b=a.split(",") +print("-----join--->",",".join(b)) + + +# DELETE() + # strip +a = " hello,world " +print("--------------strip----------->",a.strip()) + # lstrip +print("--------------lstrip----------->",a.lstrip()) + #rstrip +print("--------------rstrip----------->",a.rstrip()) + + # dir("") 查看命令和方法 + + + ### 字符串的输入和输出 + #保存到文件 +#open 函数打开一个文件,没有文件会创建,但是路径不对会报错 +# 制定文件名,方法(读,写,追加),编码格式 +# +output=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","w",encoding="utf-8") +content="hello,world" +#正式写入文件 +output.write(content) +#关闭文件句柄 +output.close() + + +### 读取文件 +input=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","r",encoding="utf-8") +content=input.read(); +print("-------------文件读取------》",content); + + +##追加模式 +output=open("/Users/booboomx/Documents/python_job/python_01/week02/output.txt","a",encoding="utf-8") +content="\npython" +#正式写入文件 +output.write(content) +#关闭文件句柄 +output.close() + + +### 字符串的格式化输出 +# format 按照传入的参数默认顺序 +a="ping" +b="pang" +print("-----按照传入的参数默认顺序------>play pingpong:{},{}".format(a,b)) + +#按照制定的参数索引 +print("-----按照制定的参数索引------ >play pingpong:{0},{1},{0},{1}".format(a,b,a,b)) + +# 按照关键词参数 +print("-----按照关键词参数------ >play pingpong:{a},{b},{a},{b}".format(a='ping',b='pong')) + +# 按照变量 只有Python3.6以上版本才有 +print("-----按照变量------》"f"play pingpang:{a},{b}") +# 小数的表示 +a="{:.2f}".format(3.1415926) +print("------小数的表示--->",a) + +# %进行格式化 +a="playing %s %s" %("ping","pong") +print("-----%进行格式化---",a) + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" index 5310c1b29833b8031afe475a7309f027b3c6a141..649c9e0d095805f52726c0369245cf59cba57b1c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" @@ -1,128 +1,128 @@ -import requests -from threading import Thread -import time -from multiprocessing import Process -## 定义CPU 秘籍的计算函数 -def count(x,y): - c=0 - while c<10000: - c+=1 - x+=1 - y+=1 - -#使用多线程 并发执行CPU秘籍操作所需要的时间 -def MultiThread_Cpu(): - counts = [] - t = time.time() - for i in range(10): - ts = Thread(target=count, args=(1, 1)) - #打印 多线程的名字 - print(ts.getName(),ts.is_alive()) - counts.append(ts) - ts.start() - for tt in counts: - tt.join() - e = counts.__len__() - while True: - for th in counts: - if not th.is_alive(): - e -= 1 - if e <= 0: - break - print("MultiThread cpu",time.time() - t) - - -#多线程测试 网路请求 -def MultiThread_Http(): - counts = [] - t = time.time() - for i in range(10): - ts = Thread(target=http_request) - #打印 多线程的名字 - print(ts.getName(),ts.is_alive()) - counts.append(ts) - ts.start() - for tt in counts: - tt.join() - e = counts.__len__() - while True: - for th in counts: - if not th.is_alive(): - e -= 1 - if e <= 0: - break - print("MultiThread Http",time.time() - t) - - -#使用多进程 并发执行CPU秘籍操作所需要的时间 -def Multiprocess_cpu(): - process = [] - t = time.time() - for i in range(10): - p = Process(target=count, args=(1, 1)) - # 打印 多进程的名字 - print(p.name) - process.append(p) - p.start() - for pp in process: - pp.join() - - e = process.__len__() - while True: - for th in process: - if not th.is_alive(): - e -= 1 - if e <= 0: - break - - print("Multiprocess cpu", time.time() - t) - - -def http_request(): - url = "https://www.baidu.com/" - # body="" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - try: - request= requests.get(url,headers=headers) - html=request.text - return {"context":html} - except Exception as e: - return {"error":e} - - - -# 多进程测试 网路请求 -def Multiprocess_Http(): - process = [] - t = time.time() - for i in range(10): - p = Process(target=http_request) - # 打印 多进程的名字 - print(p.name) - process.append(p) - p.start() - for pp in process: - pp.join() - e = process.__len__() - while True: - for th in process: - if not th.is_alive(): - e -= 1 - if e <= 0: - break - - print("Multiprocess Http", time.time() - t) - - -# 主线程 -if __name__ == '__main__': - #print("-----------Cpu--------") - # print(Multiprocess_cpu()) - - #print(MultiThread_Cpu()) - - print("--------------http--------") - print(Multiprocess_Http()) +import requests +from threading import Thread +import time +from multiprocessing import Process +## 定义CPU 秘籍的计算函数 +def count(x,y): + c=0 + while c<10000: + c+=1 + x+=1 + y+=1 + +#使用多线程 并发执行CPU秘籍操作所需要的时间 +def MultiThread_Cpu(): + counts = [] + t = time.time() + for i in range(10): + ts = Thread(target=count, args=(1, 1)) + #打印 多线程的名字 + print(ts.getName(),ts.is_alive()) + counts.append(ts) + ts.start() + for tt in counts: + tt.join() + e = counts.__len__() + while True: + for th in counts: + if not th.is_alive(): + e -= 1 + if e <= 0: + break + print("MultiThread cpu",time.time() - t) + + +#多线程测试 网路请求 +def MultiThread_Http(): + counts = [] + t = time.time() + for i in range(10): + ts = Thread(target=http_request) + #打印 多线程的名字 + print(ts.getName(),ts.is_alive()) + counts.append(ts) + ts.start() + for tt in counts: + tt.join() + e = counts.__len__() + while True: + for th in counts: + if not th.is_alive(): + e -= 1 + if e <= 0: + break + print("MultiThread Http",time.time() - t) + + +#使用多进程 并发执行CPU秘籍操作所需要的时间 +def Multiprocess_cpu(): + process = [] + t = time.time() + for i in range(10): + p = Process(target=count, args=(1, 1)) + # 打印 多进程的名字 + print(p.name) + process.append(p) + p.start() + for pp in process: + pp.join() + + e = process.__len__() + while True: + for th in process: + if not th.is_alive(): + e -= 1 + if e <= 0: + break + + print("Multiprocess cpu", time.time() - t) + + +def http_request(): + url = "https://www.baidu.com/" + # body="" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + try: + request= requests.get(url,headers=headers) + html=request.text + return {"context":html} + except Exception as e: + return {"error":e} + + + +# 多进程测试 网路请求 +def Multiprocess_Http(): + process = [] + t = time.time() + for i in range(10): + p = Process(target=http_request) + # 打印 多进程的名字 + print(p.name) + process.append(p) + p.start() + for pp in process: + pp.join() + e = process.__len__() + while True: + for th in process: + if not th.is_alive(): + e -= 1 + if e <= 0: + break + + print("Multiprocess Http", time.time() - t) + + +# 主线程 +if __name__ == '__main__': + #print("-----------Cpu--------") + # print(Multiprocess_cpu()) + + #print(MultiThread_Cpu()) + + print("--------------http--------") + print(Multiprocess_Http()) print(MultiThread_Http()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index 2714d78d5e7676f046923c5a2b24621b9b5873ae..511d496ad319a0e062ecb36c896b6ba9cb6b9349 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,238 +1,238 @@ -#作业一 -""" -什么是迭代器?什么是生成器?两者有什么区别? -""" - -#迭代器 -""" -概念上:迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有我们主动去使用next方法调用,才会返回值) -实现上:实现了 __next__接口的对象 -1.传统生命一个列表,里面的元素会立即写进内存当中,占用大量内存 -迭代器可以一次只返回一个元素,占用的内存非常小,在读取大文件和大的数据集合的时候特别有用 -""" - -### 程序讲话 -#两者实现的功能是一模一样的 -# 通过 iter方法返回一个迭代器对象 -l=list(range(10)) -l2=iter(range(10)) - -#print(l,"\n") -#print("l2=",l2,"\n") - -#通过next 方法主动获取迭代器中的值 -""" -当 迭代器中没有值了以后,会抛出 StopIteration的异常,需要自行处理一下 -""" -try: - iter = iter(range(5)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) - print(next(iter)) -except StopIteration: - print("没 数据了 ") -#生成器 -""" -生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上,提供了额外的功能,实现了程序的暂停 -声明一个生成器 -只要在函数体重有 yield 关键字,它既是一个生成器 -yield 翻译为 让渡,我们可以简单理解为暂停并返回右边的值 -""" - -#让程序 代表 一切 -def my_range_gen(n): - for i in range(n): - yield i*i - print(f"current index:{i}") - -try: - my_range=my_range_gen(3) - #print(my_range) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) -except StopIteration: - print("no data") - - - -#生成器和迭代器的区别? -""" -同样提供了惰性返回的功能,迭代器 侧重于 提供 数据的惰性返回功能,生成器侧重于 指令的惰性返回功能 -""" - - -#协程 -""" -协程的实现原理就是生成器的实现原理,在生成器的基础上又提供了传递值的功能 -通过 send 方法 向生成器传递值, -对生成器进行 send 操作,一定要调用next 方法预激,使其停留在第一个 yield位置 - -""" - -## 不懂就用代码 拉出来溜溜 - -def simple_coro(a): - print("初始值a=",a) - b=yield a - print("传递值 b=",b) - c=yield a+b - print("传递值 c=",c) - -try: - coro=simple_coro(1) - print(next(coro)) - print(coro.send(2)) - print(coro.send(3)) -except StopIteration: - print("no data") - -## 用协程 来实现 计算平均数的函数 -print("--------用协程 来实现 计算平均数的函数-----------") -def coro_avg(): - total=0 - length=0 - while True: - try: - value=yield total/length - except ZeroDivisionError: - value=yield 0 - total+=value - length+=1 - -my_avg=coro_avg() -print(next(my_avg)) -print(my_avg.send(2)) -print(my_avg.send(3)) -print(my_avg.send(4)) - -# yield 和 yield from的区别 -## yield from 用来驱动 子程序中的循环并返回最终值 - -print("--------------yield from----------") -def return_triple(): - while True: - value=yield - if value%2==0: - return value - -triple_array=[] -def triple_recorder(): - while True: - result=yield from return_triple() - triple_array.append(result) - -coro=triple_recorder() -next(coro) -for i in range(20): - coro.send(i) -print(triple_array) - - -##异步 -# asyncio(异步) -## Python3.4 引入的标准库,替代 yield from 实现协程异步IO,可以更好地实现异步程序 -## 实现原理:自动维护了一个事件队列,然后循环访问 事件来完成异步的消息维护 -import asyncio -import time -print("-----------asyncio(异步)-------") -""" -class Response: - status_code=200 - -async def sim_request(index): - print(f"模拟发送请求:Index:{index}") - response=Response() - ##模拟 网络延迟 - ## 当前是单线程 运行的,如果调用的是 time.sleep(1) 那么这个线程会被阻塞 - ## 当前线程被阻塞之后,不会让渡 CPU资源,异步的效率就不会体现 - - await asyncio.sleep(1) - print(f"requst index {index},response status_code:{response.status_code}") - return response.status_code - -#获取 消息队列 -loop=asyncio.get_event_loop() - -#包装任务 -task_array=[] -for i in range(5): - task_array.append(sim_request(i)) - -#循环访问事件 来完成异步的消息维护 -#loop.run_until_complete(asyncio.wait(task_array)) - -#小技巧::: 获取异步完成之后的所有返回值 -result=loop.run_until_complete(asyncio.gather(*task_array)) -print("----result--->,",result) -#关闭事件循环 -loop.close() -""" - - - -## 编写一个asyncio异步程序 -# 自定义 异步函数 -""" -print("---------自定义 异步函数----------") -async def hello(): - await asyncio.sleep(2) - print("hello,world:%s"%time.time()) - -def run(): - for i in range(5): - loop.run_until_complete(hello()) - -loop=asyncio.get_event_loop() -if __name__=='__main__': - run() -""" - -###扩展: 了解aiohttp异步请求网址 -import aiohttp -print("-----------aiohttp异步请求网址-----------") -#目标协程 -async def run(): - print("start get:") - print(time.time()) - res=await get() - print("finish get:") - print(time.time()) - -# 异步请求 -async def get(): - url='htpp://baidu.com' - async with aiohttp.ClientSession() as session: - async with session.get(url) as response: - # return await response.read() - #假设 请求返回时间 - return await asyncio.sleep(2) - -async def creat_task(event_loop): - while True: - asyncio.run_coroutine_threadsafe(run(),event_loop) - await asyncio.sleep(1)# 设置定时时间 - -# 启动一个 loop -def start_loop(loop): - asyncio.set_event_loop(loop) - loop.run_forever() - -from threading import Thread -if __name__=='__main__': - # 子线程 loop - tread_loop=asyncio.new_event_loop() - - run_loop_thread=Thread(target=start_loop,args=(tread_loop,)) - run_loop_thread.start() - - main_loop=asyncio.new_event_loop() - - #在主线程loop里面 - main_loop.run_until_complete(creat_task(tread_loop)) +#作业一 +""" +什么是迭代器?什么是生成器?两者有什么区别? +""" + +#迭代器 +""" +概念上:迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有我们主动去使用next方法调用,才会返回值) +实现上:实现了 __next__接口的对象 +1.传统生命一个列表,里面的元素会立即写进内存当中,占用大量内存 +迭代器可以一次只返回一个元素,占用的内存非常小,在读取大文件和大的数据集合的时候特别有用 +""" + +### 程序讲话 +#两者实现的功能是一模一样的 +# 通过 iter方法返回一个迭代器对象 +l=list(range(10)) +l2=iter(range(10)) + +#print(l,"\n") +#print("l2=",l2,"\n") + +#通过next 方法主动获取迭代器中的值 +""" +当 迭代器中没有值了以后,会抛出 StopIteration的异常,需要自行处理一下 +""" +try: + iter = iter(range(5)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) + print(next(iter)) +except StopIteration: + print("没 数据了 ") +#生成器 +""" +生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上,提供了额外的功能,实现了程序的暂停 +声明一个生成器 +只要在函数体重有 yield 关键字,它既是一个生成器 +yield 翻译为 让渡,我们可以简单理解为暂停并返回右边的值 +""" + +#让程序 代表 一切 +def my_range_gen(n): + for i in range(n): + yield i*i + print(f"current index:{i}") + +try: + my_range=my_range_gen(3) + #print(my_range) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) +except StopIteration: + print("no data") + + + +#生成器和迭代器的区别? +""" +同样提供了惰性返回的功能,迭代器 侧重于 提供 数据的惰性返回功能,生成器侧重于 指令的惰性返回功能 +""" + + +#协程 +""" +协程的实现原理就是生成器的实现原理,在生成器的基础上又提供了传递值的功能 +通过 send 方法 向生成器传递值, +对生成器进行 send 操作,一定要调用next 方法预激,使其停留在第一个 yield位置 + +""" + +## 不懂就用代码 拉出来溜溜 + +def simple_coro(a): + print("初始值a=",a) + b=yield a + print("传递值 b=",b) + c=yield a+b + print("传递值 c=",c) + +try: + coro=simple_coro(1) + print(next(coro)) + print(coro.send(2)) + print(coro.send(3)) +except StopIteration: + print("no data") + +## 用协程 来实现 计算平均数的函数 +print("--------用协程 来实现 计算平均数的函数-----------") +def coro_avg(): + total=0 + length=0 + while True: + try: + value=yield total/length + except ZeroDivisionError: + value=yield 0 + total+=value + length+=1 + +my_avg=coro_avg() +print(next(my_avg)) +print(my_avg.send(2)) +print(my_avg.send(3)) +print(my_avg.send(4)) + +# yield 和 yield from的区别 +## yield from 用来驱动 子程序中的循环并返回最终值 + +print("--------------yield from----------") +def return_triple(): + while True: + value=yield + if value%2==0: + return value + +triple_array=[] +def triple_recorder(): + while True: + result=yield from return_triple() + triple_array.append(result) + +coro=triple_recorder() +next(coro) +for i in range(20): + coro.send(i) +print(triple_array) + + +##异步 +# asyncio(异步) +## Python3.4 引入的标准库,替代 yield from 实现协程异步IO,可以更好地实现异步程序 +## 实现原理:自动维护了一个事件队列,然后循环访问 事件来完成异步的消息维护 +import asyncio +import time +print("-----------asyncio(异步)-------") +""" +class Response: + status_code=200 + +async def sim_request(index): + print(f"模拟发送请求:Index:{index}") + response=Response() + ##模拟 网络延迟 + ## 当前是单线程 运行的,如果调用的是 time.sleep(1) 那么这个线程会被阻塞 + ## 当前线程被阻塞之后,不会让渡 CPU资源,异步的效率就不会体现 + + await asyncio.sleep(1) + print(f"requst index {index},response status_code:{response.status_code}") + return response.status_code + +#获取 消息队列 +loop=asyncio.get_event_loop() + +#包装任务 +task_array=[] +for i in range(5): + task_array.append(sim_request(i)) + +#循环访问事件 来完成异步的消息维护 +#loop.run_until_complete(asyncio.wait(task_array)) + +#小技巧::: 获取异步完成之后的所有返回值 +result=loop.run_until_complete(asyncio.gather(*task_array)) +print("----result--->,",result) +#关闭事件循环 +loop.close() +""" + + + +## 编写一个asyncio异步程序 +# 自定义 异步函数 +""" +print("---------自定义 异步函数----------") +async def hello(): + await asyncio.sleep(2) + print("hello,world:%s"%time.time()) + +def run(): + for i in range(5): + loop.run_until_complete(hello()) + +loop=asyncio.get_event_loop() +if __name__=='__main__': + run() +""" + +###扩展: 了解aiohttp异步请求网址 +import aiohttp +print("-----------aiohttp异步请求网址-----------") +#目标协程 +async def run(): + print("start get:") + print(time.time()) + res=await get() + print("finish get:") + print(time.time()) + +# 异步请求 +async def get(): + url='htpp://baidu.com' + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + # return await response.read() + #假设 请求返回时间 + return await asyncio.sleep(2) + +async def creat_task(event_loop): + while True: + asyncio.run_coroutine_threadsafe(run(),event_loop) + await asyncio.sleep(1)# 设置定时时间 + +# 启动一个 loop +def start_loop(loop): + asyncio.set_event_loop(loop) + loop.run_forever() + +from threading import Thread +if __name__=='__main__': + # 子线程 loop + tread_loop=asyncio.new_event_loop() + + run_loop_thread=Thread(target=start_loop,args=(tread_loop,)) + run_loop_thread.start() + + main_loop=asyncio.new_event_loop() + + #在主线程loop里面 + main_loop.run_until_complete(creat_task(tread_loop)) main_loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" index 15f9d2554a71811586c089153e7c8cab381036da..f4de40ab308a33cb2fc7e60f24e9499e66ce3049 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" @@ -1,68 +1,68 @@ -from multiprocessing import Process,Lock -from multiprocessing import Queue -from threading import Thread - - - -def save_to_file(index,lock): - with lock: - with open("job.log","a",encoding="utf-8") as f: - f.write(str(index)+"\n") - -def save_to_queue(index,my_queue): - my_queue.put(index) - -zero=0 -lock=Lock() -def foo(): - global zero - for i in range(10): - with lock: - zero=i - print("zero",zero) - - -#多进程 锁 -""" -if __name__ == "__main__": - procress_array=[] - lock=Lock() - for i in range(10): - p=Process(target=save_to_file,args=(i,lock)) - procress_array.append(p) - p.start() - for p in procress_array: - p.join() - print("done") -""" - - -#多线程 锁 -if __name__ == "__main__": - process_array=[] - for i in range(2): - t=Thread(target=foo) - process_array.append(t) - t.start() - for p in process_array: - p.join() - - print(zero) - - - -#多进程 Queue队列 -""" -if __name__ == "__main__": - process_array=[] - my_queue=Queue() - for i in range(10): - p=Process(target=save_to_queue,args=(i,my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - print(my_queue.get()) - -""" +from multiprocessing import Process,Lock +from multiprocessing import Queue +from threading import Thread + + + +def save_to_file(index,lock): + with lock: + with open("job.log","a",encoding="utf-8") as f: + f.write(str(index)+"\n") + +def save_to_queue(index,my_queue): + my_queue.put(index) + +zero=0 +lock=Lock() +def foo(): + global zero + for i in range(10): + with lock: + zero=i + print("zero",zero) + + +#多进程 锁 +""" +if __name__ == "__main__": + procress_array=[] + lock=Lock() + for i in range(10): + p=Process(target=save_to_file,args=(i,lock)) + procress_array.append(p) + p.start() + for p in procress_array: + p.join() + print("done") +""" + + +#多线程 锁 +if __name__ == "__main__": + process_array=[] + for i in range(2): + t=Thread(target=foo) + process_array.append(t) + t.start() + for p in process_array: + p.join() + + print(zero) + + + +#多进程 Queue队列 +""" +if __name__ == "__main__": + process_array=[] + my_queue=Queue() + for i in range(10): + p=Process(target=save_to_queue,args=(i,my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + print(my_queue.get()) + +""" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.md" index 6e2be0a209ab6cb91ef2a302f2a9c13a9cc0ec7b..f8fce08beba63ea932caff743479a8e1c49d5190 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.md" @@ -1,64 +1,64 @@ -#1.简单使用Mysql约束, 并举例说明使用场景. -#2.练习使用分组查询. - -#1.创建表时添加主键 -create table store_pref( -id int primary key auto_increment, -store_name varchar(255) -) -## 自增键必须是主键 - -#修改主键 -alter table store_pref add primary key('id') - -## 如果在表中有相应的主键,会报错 - -## 移除主键 -alter table store_pref drop primary key - -##添加联合主键 -alter table store_pref add primary key('id','store_name) - -## NOT NULL -#只能约束程序层面没有该操作表中的某个字段,不能约束人行为上对其赋值为空白字符 - -#唯一约束 UNIQUE -#NULL 可以重复 比如统计店铺业绩,该店铺不可以重复,那就可以使用唯一约束 - -#外键约束 foreign key -#外键的作用 保持数据的一致性和完整性,通过外键来表达主表和从表的关系,避免冗余字段 - - -#为什么现在不用外键的了呢? - -## 1.性能问题 插入数据需要校验 -## 2.并发问题 在高并发的事务场景下,使用外键容易造成死锁 -## 3.扩展性问题 -## 外键就相当于把对象之间的关系 交给数据库来维护,如果遇到分库分表,外键是不生效的 -## 作数据迁移时,触发器,存储过程和外键都很难迁移,增加了维护成本 -## 维护成本 需要专业的DBA来维护数据库关系 - -# default 默认约束,默认会填充当期的字段 -# 如果我们没有给一个有默认约束的字段 create_time值,那么该字段会默认填充current_timestamp - -## 分组查询 group by -将数据按某个字段进行分组,配合 SUM,AVG,COUNT MAX,MIN等聚合函数做统计使用 - -插入数据 -INSERT INTO store_perf(store_name, amount, department) values ("男装_店铺1", 34543123.23, "男装事业部"), ("男装_店铺2", 41232373.12, "男装事业部"),("男装_店铺3", 62135632.22, "男装事业部"), ("男装_店铺4", 612356123.26, "男装事业部"), ("女装_店铺1", 78716237854.3, "女装事业部"), ("女装_店铺2", 89123565741.23, "女装事业部"), ("女装_店铺3", 831235769.23, "女装事业部"), ("女装_店铺4", 1912312345.13, "女装事业部"), ("女装_店铺5", 87324234712.92, "女装事业部"), ("女装_店铺6", 12754547457.93, "女装事业部") - - -##查询数据 -SELECT count(*) as 店铺数, -FORMAT(AVG(amount), 2) as 平均业绩, -SUM(amount) as 总业绩, -MAX(amount) as 最大业绩, -MIN(amount) as 最小业绩, -department as 部门 -FROM store_perf GROUP BY department - -店铺数 平均业绩 总业绩 最大业绩 最小业绩 部门 -6 803,155.55 4818933.273124695 3409350 33.32 女装事业部 -4 2,808.57 11234.29600906372 11123.3 33.3 男装事业部 - - +#1.简单使用Mysql约束, 并举例说明使用场景. +#2.练习使用分组查询. + +#1.创建表时添加主键 +create table store_pref( +id int primary key auto_increment, +store_name varchar(255) +) +## 自增键必须是主键 + +#修改主键 +alter table store_pref add primary key('id') + +## 如果在表中有相应的主键,会报错 + +## 移除主键 +alter table store_pref drop primary key + +##添加联合主键 +alter table store_pref add primary key('id','store_name) + +## NOT NULL +#只能约束程序层面没有该操作表中的某个字段,不能约束人行为上对其赋值为空白字符 + +#唯一约束 UNIQUE +#NULL 可以重复 比如统计店铺业绩,该店铺不可以重复,那就可以使用唯一约束 + +#外键约束 foreign key +#外键的作用 保持数据的一致性和完整性,通过外键来表达主表和从表的关系,避免冗余字段 + + +#为什么现在不用外键的了呢? + +## 1.性能问题 插入数据需要校验 +## 2.并发问题 在高并发的事务场景下,使用外键容易造成死锁 +## 3.扩展性问题 +## 外键就相当于把对象之间的关系 交给数据库来维护,如果遇到分库分表,外键是不生效的 +## 作数据迁移时,触发器,存储过程和外键都很难迁移,增加了维护成本 +## 维护成本 需要专业的DBA来维护数据库关系 + +# default 默认约束,默认会填充当期的字段 +# 如果我们没有给一个有默认约束的字段 create_time值,那么该字段会默认填充current_timestamp + +## 分组查询 group by +将数据按某个字段进行分组,配合 SUM,AVG,COUNT MAX,MIN等聚合函数做统计使用 + +插入数据 +INSERT INTO store_perf(store_name, amount, department) values ("男装_店铺1", 34543123.23, "男装事业部"), ("男装_店铺2", 41232373.12, "男装事业部"),("男装_店铺3", 62135632.22, "男装事业部"), ("男装_店铺4", 612356123.26, "男装事业部"), ("女装_店铺1", 78716237854.3, "女装事业部"), ("女装_店铺2", 89123565741.23, "女装事业部"), ("女装_店铺3", 831235769.23, "女装事业部"), ("女装_店铺4", 1912312345.13, "女装事业部"), ("女装_店铺5", 87324234712.92, "女装事业部"), ("女装_店铺6", 12754547457.93, "女装事业部") + + +##查询数据 +SELECT count(*) as 店铺数, +FORMAT(AVG(amount), 2) as 平均业绩, +SUM(amount) as 总业绩, +MAX(amount) as 最大业绩, +MIN(amount) as 最小业绩, +department as 部门 +FROM store_perf GROUP BY department + +店铺数 平均业绩 总业绩 最大业绩 最小业绩 部门 +6 803,155.55 4818933.273124695 3409350 33.32 女装事业部 +4 2,808.57 11234.29600906372 11123.3 33.3 男装事业部 + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index 98e251b309651aaf5b94640172ff4bf1cb690da0..5882c48321d77ad63f887540719b77bc686433f0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,123 +1,123 @@ -import pymysql -import random -import time -My_conf={ - "host":"127.0.0.1", - "user":"root", - "password":"root", - "db":"tunan_class_2" -} - -##链接数据库 -mysql_con=pymysql.connect(**My_conf) - -#简单理解为真正执行语句的线程 -mysql_cursor=mysql_con.cursor() -print(mysql_cursor) - -##单条执行 -def clock_it_deco(): - pass - -''' -def insert_one(): - for i in range(10**4): - store_name=f"店铺_{i}" - amount=format(random.uniform(10**3,10**6),'.2f') - department=f"事业部_{random.randint(1,10)}" - sta_date=time.strftime("%Y-%m-%d") - - SQL=f"""insert into store_perf(store_name,amount,department,sta_date) - values ('{store_name}',{amount},'{department}','{sta_date}') """ - print(SQL) - #mysql_cursor.execute(SQL) - - #mysql_con.commit() - -''' - -def insert_many(): - values=[] - for i in range(10**1): - store_name=f"店铺m_{i}" - amount=format(random.uniform(10**3,10**6),'.2f') - department=f"事业部m_{random.randint(1,10)}" - sta_date=time.strftime("%Y-%m-%d") - values.append((store_name,amount,department,sta_date)) - - #SQL2="""insert into store_perf(store_name,amount,department,sta_date) values(%s,%s,%s,%s)""" - - SQL2 = """INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES (%s, %s, %s, %s)""" - - print('----many--values-----',values) - mysql_cursor.executemany(SQL2,values) - mysql_con.commit() - - -## 获取返回值 -def get_shops(): - SQL="select store_name,amount,sta_date from store_perf where department='事业部_1' limit 3" - mysql_cursor.execute(SQL) - - query_set= mysql_cursor.fetchall() - print(query_set) - - - - - - -##事务 -###事务的提交,回滚 -''' -START TRANSACTION; -INSERT INTO store_perf(store_name, amount, department, sta_date) VALUES ('店铺_1764', 753294.41, '事业部_8', '2021-02-05'); -ROLLBACK; -COMMIT; -''' - -def transaction(): - try: - SQL="delete from class_2 where name='name_13'" - mysql_cursor.execute(SQL) - SQL_2="insert into class_1 values(name)" - mysql_cursor.execute(SQL_2) - - except Exception as e: - print("raise Exception",e.args[0]) - print("rollback") - mysql_con.rollback() - - finally: - mysql_con.commit() - - -if __name__=='__main__': - #insert_one() - insert_many() - # get_shops() - #transaction() - -''' -如何优化mysql -合理地建立索引 - -频繁作为查询条件的字段应该建立索引 -唯一性太差的字段不适合单独建立索引 -更新非常频繁的字段不适合建立索引 -避免不经过索引的操作 -not in, !=等反向逻辑 -BETWEEN范围查找 -or逻辑两边都必须命中索引才会走索引 -联合索引, 不按左缀查询规则 -加缓存 - -数据库缓存 - -show VARIABLES LIKE '%query_cache%' -用redis做缓存 - -请求 -> redis -> 未命中 -> mysql -> 返回 -换固态硬盘 +import pymysql +import random +import time +My_conf={ + "host":"127.0.0.1", + "user":"root", + "password":"root", + "db":"tunan_class_2" +} + +##链接数据库 +mysql_con=pymysql.connect(**My_conf) + +#简单理解为真正执行语句的线程 +mysql_cursor=mysql_con.cursor() +print(mysql_cursor) + +##单条执行 +def clock_it_deco(): + pass + +''' +def insert_one(): + for i in range(10**4): + store_name=f"店铺_{i}" + amount=format(random.uniform(10**3,10**6),'.2f') + department=f"事业部_{random.randint(1,10)}" + sta_date=time.strftime("%Y-%m-%d") + + SQL=f"""insert into store_perf(store_name,amount,department,sta_date) + values ('{store_name}',{amount},'{department}','{sta_date}') """ + print(SQL) + #mysql_cursor.execute(SQL) + + #mysql_con.commit() + +''' + +def insert_many(): + values=[] + for i in range(10**1): + store_name=f"店铺m_{i}" + amount=format(random.uniform(10**3,10**6),'.2f') + department=f"事业部m_{random.randint(1,10)}" + sta_date=time.strftime("%Y-%m-%d") + values.append((store_name,amount,department,sta_date)) + + #SQL2="""insert into store_perf(store_name,amount,department,sta_date) values(%s,%s,%s,%s)""" + + SQL2 = """INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES (%s, %s, %s, %s)""" + + print('----many--values-----',values) + mysql_cursor.executemany(SQL2,values) + mysql_con.commit() + + +## 获取返回值 +def get_shops(): + SQL="select store_name,amount,sta_date from store_perf where department='事业部_1' limit 3" + mysql_cursor.execute(SQL) + + query_set= mysql_cursor.fetchall() + print(query_set) + + + + + + +##事务 +###事务的提交,回滚 +''' +START TRANSACTION; +INSERT INTO store_perf(store_name, amount, department, sta_date) VALUES ('店铺_1764', 753294.41, '事业部_8', '2021-02-05'); +ROLLBACK; +COMMIT; +''' + +def transaction(): + try: + SQL="delete from class_2 where name='name_13'" + mysql_cursor.execute(SQL) + SQL_2="insert into class_1 values(name)" + mysql_cursor.execute(SQL_2) + + except Exception as e: + print("raise Exception",e.args[0]) + print("rollback") + mysql_con.rollback() + + finally: + mysql_con.commit() + + +if __name__=='__main__': + #insert_one() + insert_many() + # get_shops() + #transaction() + +''' +如何优化mysql +合理地建立索引 + +频繁作为查询条件的字段应该建立索引 +唯一性太差的字段不适合单独建立索引 +更新非常频繁的字段不适合建立索引 +避免不经过索引的操作 +not in, !=等反向逻辑 +BETWEEN范围查找 +or逻辑两边都必须命中索引才会走索引 +联合索引, 不按左缀查询规则 +加缓存 + +数据库缓存 + +show VARIABLES LIKE '%query_cache%' +用redis做缓存 + +请求 -> redis -> 未命中 -> mysql -> 返回 +换固态硬盘 ''' \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" index e7a1c66c471bd1273c989a827f5ee96daf26e154..b9f013d57cb248f62dd37e7b698d1441410bc128 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.md" @@ -1,71 +1,71 @@ -# 列出mysql所有系统变量 - -#服务器系统变量 -show VARIABLES -select @@DATE_FORMAT("2021-02-05','yy-mm-dd') - - - -#用户变量 - -#输出变量 yesterday -select @yesterday - -#对变量yesterda进行赋值 -select @yesterday=subdate(current_date,1); - -#日期的格式化 -set @yesterday=date_format(@yesterday,'%Y/%m%d') - -#小数的格式化 -set @amount=0.4 - -set @amount=CAST(@amount as decimal(15,3)); - -select @amount - -#局部变量 -不需要@前缀 -需要事先进行变量类型的声明和初始化 - -## 存储过程 -CREATE PROCEDURE stat_store_perf(days INT) -BEGIN - DECLARE t_date VARCHAR(255); - set t_date = DATE_FORMAT(subdate(CURRENT_DATE, days), '%Y-%m-%d'); - SELECT count(*) as 店铺数, - FORMAT(AVG(amount), 2) as 平均业绩, - SUM(amount) as 总业绩, - MAX(amount) as 最大业绩, - MIN(amount) as 最小业绩, - department as 部门 - FROM store_perf WHERE sta_date=t_date - GROUP BY department; -END - -##调用存储过程 -call stat_store_perf(1) - -## 删除存储过程 -drop procedure sta_store_perf - - -#触发器 -## 创建触发器 -create TRIGGER check_department -BEFORE INSERT -ON store_perf -FOR each row -BEGIN - IF new.department not in ("男装事业部", "女装事业部") THEN - SET new.department 'unknow'; - END IF; -END - -## 查看触发器 -show triggers from store_perf - -##删除触发器 -## 建议通过客户端删除 -drop triggers check_department - +# 列出mysql所有系统变量 + +#服务器系统变量 +show VARIABLES +select @@DATE_FORMAT("2021-02-05','yy-mm-dd') + + + +#用户变量 + +#输出变量 yesterday +select @yesterday + +#对变量yesterda进行赋值 +select @yesterday=subdate(current_date,1); + +#日期的格式化 +set @yesterday=date_format(@yesterday,'%Y/%m%d') + +#小数的格式化 +set @amount=0.4 + +set @amount=CAST(@amount as decimal(15,3)); + +select @amount + +#局部变量 +不需要@前缀 +需要事先进行变量类型的声明和初始化 + +## 存储过程 +CREATE PROCEDURE stat_store_perf(days INT) +BEGIN + DECLARE t_date VARCHAR(255); + set t_date = DATE_FORMAT(subdate(CURRENT_DATE, days), '%Y-%m-%d'); + SELECT count(*) as 店铺数, + FORMAT(AVG(amount), 2) as 平均业绩, + SUM(amount) as 总业绩, + MAX(amount) as 最大业绩, + MIN(amount) as 最小业绩, + department as 部门 + FROM store_perf WHERE sta_date=t_date + GROUP BY department; +END + +##调用存储过程 +call stat_store_perf(1) + +## 删除存储过程 +drop procedure sta_store_perf + + +#触发器 +## 创建触发器 +create TRIGGER check_department +BEFORE INSERT +ON store_perf +FOR each row +BEGIN + IF new.department not in ("男装事业部", "女装事业部") THEN + SET new.department 'unknow'; + END IF; +END + +## 查看触发器 +show triggers from store_perf + +##删除触发器 +## 建议通过客户端删除 +drop triggers check_department + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" index b62700c867a148fe1c9907740bc80bce0dd79dcb..22d144250a56ca52af0efab3bfbf0b27ca985d98 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" @@ -1,96 +1,96 @@ -讲清楚浏览器地址栏敲下url发生了什么? -基本流程: -①查询ip地址 - -②建立tcp连接,接入服务器 - -③浏览器发起http请求 - -④服务器后台操作并做出http响应 - -⑤网页的解析与渲染 - - -详细步骤如下: -查询ip地址 -①浏览器解析出url中的域名。 - -②查询浏览器的DNS缓存。 - -③浏览器中没有DNS缓存,则查找本地客户端hosts文件有无对应的ip地址。 - -④hosts中无,则查找本地DNS服务器(运营商提供的DNS服务器)有无对应的DNS缓存。 - -⑤若本地DNS没有DNS缓存,则向根服务器查询,进行递归查找。 - -⑥递归查找从顶级域名开始(如.com),一步步缩小范围,最终客户端取得ip地址。 - - - -tcp连接与http连接 -①http协议建立在tcp协议之上,http请求前,需先进行tcp连接,形成客户端到服务器的稳定的通道。俗称TCP的三次握手。 - -②tcp连接完成后,http请求开始,请求有多种方式,常见的有get,post等。 - -③http请求包含请求头,也可能包含请求体两部分,请求头中包含我们希望对请求文件的操作的信息,请求体中包含传递给后台的参数。 - -④服务器收到http请求后,后台开始工作,如负载平衡,跨域等,这里就是后端的工作了。 - -⑤文件处理完毕,生成响应数据包,响应也包含两部分,响应头和相应体,响应体就是我们所请求的文件。 - -⑥经过网络传输,文件被下载到本地客户端,客户端开始加载。 - - - -html渲染 -①客户端浏览器加载了html文件后,由上到下解析html为DOM树(DOM Tree)。 - -②遇到css文件,css中的url发起http请求。 - -③这是第二次http请求,由于http1.1协议增加了Connection: keep-alive声明,故tcp连接不会关闭,可以复用。 - -④http连接是无状态连接,客户端与服务器端需要重新发起请求--响应。 - -在请求css的过程中,解析器继续解析html,然后到了script标签。 - -⑤由于script可能会改变DOM结构,故解析器停止生成DOM树,解析器被js阻塞,等待js文件发起http请求,然后加载。这是第三次http请求。js执行完成后解析器继续解析。 - -⑥由于css文件可能会影响js文件的执行结果,因此需等css文件加载完成后再执行。 - -⑦浏览器收到css文件后,开始解析css文件为CSSOM树(CSS Rule Tree)。 - -⑧CSSOM树生成后,DOM Tree与CSS Rule Tree结合生成渲染树(Render Tree)。 - -⑨Render Tree会被css文件阻塞,渲染树生成后,先布局,绘制渲染树中节点的属性(位置,宽度,大小等),然后渲染,页面就会呈现信息。 - -⑩继续边解析边渲染,遇到了另一个js文件,js文件执行后改变了DOM树,渲染树从被改变的dom开始再次渲染。 - -⑪继续向下渲染,碰到一个img标签,浏览器发起http请求,不会等待img加载完成,继续向下渲染,之后再重新渲染此部分。 - -⑫DOM树遇到html结束标签,停止解析,进而渲染结束。 - - - -从此可以得出网站的一些优化的方法: -①减少DNS查询:将服务器域名的ip信息加入本地host文件。 - -②减少http请求数量,对于图片使用雪碧图,对于html文件和css文件,js文件分别进行合并操作。 - -③减少下载时间:压缩图片,使用压缩应用压缩文档中的空格,删除文件多余的语句和注释,创造自己的js精简库和精简框架,使用本地浏览器缓存。 - -④提前渲染开始时间:将css链接放在html头部。 - -⑤减轻解析器的阻塞:将js链接放在body尾部。 - - - -五层协议有哪五层, 举例说明. -分为,应用层,传输层,网络层,数据链路层,物理层等5层 - -应用层:HTTP,FTP,SMTP等 -传输层 传输控制协议TCP,用户数据协议UDP -网路层有四个协议,ARP协议,IP协议,ICM协议,IGMP协议 -集线器工作在物理层 -交换机工作在数据链路层 -路由器工作在网路层 - +讲清楚浏览器地址栏敲下url发生了什么? +基本流程: +①查询ip地址 + +②建立tcp连接,接入服务器 + +③浏览器发起http请求 + +④服务器后台操作并做出http响应 + +⑤网页的解析与渲染 + + +详细步骤如下: +查询ip地址 +①浏览器解析出url中的域名。 + +②查询浏览器的DNS缓存。 + +③浏览器中没有DNS缓存,则查找本地客户端hosts文件有无对应的ip地址。 + +④hosts中无,则查找本地DNS服务器(运营商提供的DNS服务器)有无对应的DNS缓存。 + +⑤若本地DNS没有DNS缓存,则向根服务器查询,进行递归查找。 + +⑥递归查找从顶级域名开始(如.com),一步步缩小范围,最终客户端取得ip地址。 + + + +tcp连接与http连接 +①http协议建立在tcp协议之上,http请求前,需先进行tcp连接,形成客户端到服务器的稳定的通道。俗称TCP的三次握手。 + +②tcp连接完成后,http请求开始,请求有多种方式,常见的有get,post等。 + +③http请求包含请求头,也可能包含请求体两部分,请求头中包含我们希望对请求文件的操作的信息,请求体中包含传递给后台的参数。 + +④服务器收到http请求后,后台开始工作,如负载平衡,跨域等,这里就是后端的工作了。 + +⑤文件处理完毕,生成响应数据包,响应也包含两部分,响应头和相应体,响应体就是我们所请求的文件。 + +⑥经过网络传输,文件被下载到本地客户端,客户端开始加载。 + + + +html渲染 +①客户端浏览器加载了html文件后,由上到下解析html为DOM树(DOM Tree)。 + +②遇到css文件,css中的url发起http请求。 + +③这是第二次http请求,由于http1.1协议增加了Connection: keep-alive声明,故tcp连接不会关闭,可以复用。 + +④http连接是无状态连接,客户端与服务器端需要重新发起请求--响应。 + +在请求css的过程中,解析器继续解析html,然后到了script标签。 + +⑤由于script可能会改变DOM结构,故解析器停止生成DOM树,解析器被js阻塞,等待js文件发起http请求,然后加载。这是第三次http请求。js执行完成后解析器继续解析。 + +⑥由于css文件可能会影响js文件的执行结果,因此需等css文件加载完成后再执行。 + +⑦浏览器收到css文件后,开始解析css文件为CSSOM树(CSS Rule Tree)。 + +⑧CSSOM树生成后,DOM Tree与CSS Rule Tree结合生成渲染树(Render Tree)。 + +⑨Render Tree会被css文件阻塞,渲染树生成后,先布局,绘制渲染树中节点的属性(位置,宽度,大小等),然后渲染,页面就会呈现信息。 + +⑩继续边解析边渲染,遇到了另一个js文件,js文件执行后改变了DOM树,渲染树从被改变的dom开始再次渲染。 + +⑪继续向下渲染,碰到一个img标签,浏览器发起http请求,不会等待img加载完成,继续向下渲染,之后再重新渲染此部分。 + +⑫DOM树遇到html结束标签,停止解析,进而渲染结束。 + + + +从此可以得出网站的一些优化的方法: +①减少DNS查询:将服务器域名的ip信息加入本地host文件。 + +②减少http请求数量,对于图片使用雪碧图,对于html文件和css文件,js文件分别进行合并操作。 + +③减少下载时间:压缩图片,使用压缩应用压缩文档中的空格,删除文件多余的语句和注释,创造自己的js精简库和精简框架,使用本地浏览器缓存。 + +④提前渲染开始时间:将css链接放在html头部。 + +⑤减轻解析器的阻塞:将js链接放在body尾部。 + + + +五层协议有哪五层, 举例说明. +分为,应用层,传输层,网络层,数据链路层,物理层等5层 + +应用层:HTTP,FTP,SMTP等 +传输层 传输控制协议TCP,用户数据协议UDP +网路层有四个协议,ARP协议,IP协议,ICM协议,IGMP协议 +集线器工作在物理层 +交换机工作在数据链路层 +路由器工作在网路层 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index 85c1ff34ddff8300d1f1bf8aeeeec8f0f01828ec..bf524b57e8619a229aa6dd8fbc0437987fd4dab4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,80 +1,80 @@ -课后作业 -学会用fiddler抓包https请求 -学会用fiddler抓包手机app中的请求 -学会使用postman模拟GET, POST请求. - -第六周-第三节课 -抓包 -抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. - -对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. - -抓包软件 - -Fiddler - -https://www.telerik.com/fiddler -Charles - -wireshark - -web端抓包 - -现代互联网环境几乎都是https协议的网站 - -信任证书 - -Qi3lw.png - -Rules -> Options -> HTTPS -- 勾选Decrypt HTTPS traffic -- 右上角点击Actions -- Trust Root Certificates -App端抓包 - -下载夜神模拟器 -打开远程终端连接 - -QinkU.png - -Rules -> Options -> Connections -> Allow remote computes to connect - - -- 把手机/模拟器的代理指向fiddler -wifi调出设置的时候要长按 - -查看当前fiddler所在pc本地局域网ip - -ipconfig/ifconfig -在代理项中填写ip地址和fiddler端口, 默认是8888 - -信任证书 - -App有一定的反爬措施, 第一件事就是修改请求协议 - -双向验证 - -需要客户端也带上证书 - -解决请求协议上的反爬措施 - -安装VirtualXposed_0.18.2, JustTrustMe -模拟请求 -PostMan简单使用 - -GET - -POST - -form_data - -参数表单 - -x-www-form-urlencoded - -如果headers中content-type为x-www-form-urlencoded, 那么我们需要在当前选项下填写参数 - -raw - -请求的真实body内容. - +课后作业 +学会用fiddler抓包https请求 +学会用fiddler抓包手机app中的请求 +学会使用postman模拟GET, POST请求. + +第六周-第三节课 +抓包 +抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. + +对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. + +抓包软件 + +Fiddler + +https://www.telerik.com/fiddler +Charles + +wireshark + +web端抓包 + +现代互联网环境几乎都是https协议的网站 + +信任证书 + +Qi3lw.png + +Rules -> Options -> HTTPS +- 勾选Decrypt HTTPS traffic +- 右上角点击Actions +- Trust Root Certificates +App端抓包 + +下载夜神模拟器 +打开远程终端连接 + +QinkU.png + +Rules -> Options -> Connections -> Allow remote computes to connect + + +- 把手机/模拟器的代理指向fiddler +wifi调出设置的时候要长按 + +查看当前fiddler所在pc本地局域网ip + +ipconfig/ifconfig +在代理项中填写ip地址和fiddler端口, 默认是8888 + +信任证书 + +App有一定的反爬措施, 第一件事就是修改请求协议 + +双向验证 + +需要客户端也带上证书 + +解决请求协议上的反爬措施 + +安装VirtualXposed_0.18.2, JustTrustMe +模拟请求 +PostMan简单使用 + +GET + +POST + +form_data + +参数表单 + +x-www-form-urlencoded + +如果headers中content-type为x-www-form-urlencoded, 那么我们需要在当前选项下填写参数 + +raw + +请求的真实body内容. + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" index 07e30478224acbe0f810d146130431757f723857..37f323652c6231c1359a95ac59e563612ec5c1be 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" @@ -1,57 +1,57 @@ -讲述TCP/IP三次握手 -讲述TCP/IP四次挥手 -讲述HTTPS加密的过程 - - -TCP/IP三次握手 -为了建立可靠的TCP连接, 尽可能地保证数据传输的正确性. - - - -三次握手的过程 - -客户端向服务端发送带有SYN(同步序列编号)标识的数据包 --------------------------服务端确认了客户端的发送能力正常 -服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包-----------------------服务端确认了自己接受能力是正常 -客户端向服务端返回带有ACK标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 -第2次握手已经传回了ACK, 为什么服务端还要返回SYN? - -为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. - - - - - - -TCP/IP四次挥手 - - -四次挥手的过程 - -我们以客户端作为主动关闭方来描述四次挥手过程 -客户端向服务端发送了一个FIN(finish)数据包-------------------------------------关闭客户端到服务端的连接通道 -服务端收到FIN后, 返回了ACK数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 -服务端发送FIN数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 -客户端返回ACK数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 - - - - -https加密的过程 - -客户端向服务端发送通信请求 - -服务端返回给客户端证书和密钥 - -客户端通过CA中心验证证书的真实性 - -客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. - -非对称加密 - -16 = 2* 8 也可以是 4 * 4 -公钥就是拿到了16这个结果 -私钥就是某个因数2 -通过这样的方式才可以得出唯一解8 -服务端收到加密后的请求数据后, 使用私钥进行解密. - +讲述TCP/IP三次握手 +讲述TCP/IP四次挥手 +讲述HTTPS加密的过程 + + +TCP/IP三次握手 +为了建立可靠的TCP连接, 尽可能地保证数据传输的正确性. + + + +三次握手的过程 + +客户端向服务端发送带有SYN(同步序列编号)标识的数据包 --------------------------服务端确认了客户端的发送能力正常 +服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包-----------------------服务端确认了自己接受能力是正常 +客户端向服务端返回带有ACK标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 +第2次握手已经传回了ACK, 为什么服务端还要返回SYN? + +为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. + + + + + + +TCP/IP四次挥手 + + +四次挥手的过程 + +我们以客户端作为主动关闭方来描述四次挥手过程 +客户端向服务端发送了一个FIN(finish)数据包-------------------------------------关闭客户端到服务端的连接通道 +服务端收到FIN后, 返回了ACK数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 +服务端发送FIN数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 +客户端返回ACK数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 + + + + +https加密的过程 + +客户端向服务端发送通信请求 + +服务端返回给客户端证书和密钥 + +客户端通过CA中心验证证书的真实性 + +客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. + +非对称加密 + +16 = 2* 8 也可以是 4 * 4 +公钥就是拿到了16这个结果 +私钥就是某个因数2 +通过这样的方式才可以得出唯一解8 +服务端收到加密后的请求数据后, 使用私钥进行解密. + 服务器和客户端使用对称加密进行通信 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" index 34bdb1ebd817a5e0aa9831b616b99b4d416f7b48..6b1bd80b9aae3b2ce96bfe00dbbcd90feab3dff9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" @@ -1,61 +1,61 @@ -""" -课后作业 -通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 -封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. -""" - - -""" -时间转字符串 -2021-01-05 - 22:54:37 -2021-01-05 22:54:37 -""" -time=datetime.datetime.today() -#print(time.strftime("%Y-%m-%d")) -#print(time.strftime(" %H:%M:%S")) -#print(time.strftime("%Y-%m-%d %H:%M:%S")) - -""" -字符串转时间 -""" -str='22:54:37' -str2='2021-01-06' -#print(datetime.datetime.strptime(str2,"%Y-%m-%d")) -#print(datetime.datetime.strptime(str,"%H:%M:%S")) - -""" -时间转时间戳 -""" -time2=datetime.datetime.today() -#print(time2.timestamp()) - -""" -时间戳 转时间 -1609858686.217262 -""" -ts=1609858686.217262 -#print(datetime.datetime.fromtimestamp(ts,tz=None)) - - -from datetime import timedelta - -""" -2021-01-02 23:05:05.400499 -封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. - -""" - - - -def get_date(day_delta): - wow = datetime.datetime.today() - if day_delta==-1: - wow+=timedelta(days=-3) - wow= datetime.datetime.strftime(wow,"%Y-%m-%d") - else: - wow = datetime.datetime.strftime(wow, "%Y-%m-%d") - - return wow - -print(get_date(-1)) +""" +课后作业 +通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 +封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. +""" + + +""" +时间转字符串 +2021-01-05 + 22:54:37 +2021-01-05 22:54:37 +""" +time=datetime.datetime.today() +#print(time.strftime("%Y-%m-%d")) +#print(time.strftime(" %H:%M:%S")) +#print(time.strftime("%Y-%m-%d %H:%M:%S")) + +""" +字符串转时间 +""" +str='22:54:37' +str2='2021-01-06' +#print(datetime.datetime.strptime(str2,"%Y-%m-%d")) +#print(datetime.datetime.strptime(str,"%H:%M:%S")) + +""" +时间转时间戳 +""" +time2=datetime.datetime.today() +#print(time2.timestamp()) + +""" +时间戳 转时间 +1609858686.217262 +""" +ts=1609858686.217262 +#print(datetime.datetime.fromtimestamp(ts,tz=None)) + + +from datetime import timedelta + +""" +2021-01-02 23:05:05.400499 +封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02. + +""" + + + +def get_date(day_delta): + wow = datetime.datetime.today() + if day_delta==-1: + wow+=timedelta(days=-3) + wow= datetime.datetime.strftime(wow,"%Y-%m-%d") + else: + wow = datetime.datetime.strftime(wow, "%Y-%m-%d") + + return wow + +print(get_date(-1)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index 9b9ee876bae8a191417a5c06bce4279424f95343..ba61ec9a997c928cff8b96ca2d5bc2736f676f9a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,81 +1,81 @@ -import self as self - -class MyMath: - @staticmethod - def add(a,b): #加法 - return a+b - - @staticmethod - def sub(a,b):# 减法 - return a-b - - @staticmethod - def mul(a,b):# 乘法 - return a*b - - @staticmethod - def division(a,b): #除法 - return a/b - - @staticmethod - def Power(a,b): #Power 幂 - return a**b - - @staticmethod - def sqr(a): #开根 - return a**(1/2) # x ** (1 / 2) - -""" -print(MyMath.add(3,4)) -print(MyMath.sub(3,4)) -print(MyMath.mul(3,4)) -print(MyMath.division(3,4)) -print(MyMath.Power(3,4)) -print(MyMath.sqr(4)) -""" - -print("-----------自定义类------------") -class Book: - content="我是父类的一个参数" #声明类属性 - __news="新闻" #声明私有属性 - - self.__read="read" #声明私有属性 通过实例._类名__变量名来访问私有属性 - - """ - def __int__(self): - pass - def __init__(self,sig): - self.sig=sig - """ - def __init__(self,a,b,c): - self.a=a - self.b=b - self.content="周杰伦" #初始化实例属性 - self.__news=c #绑定私有实例属性 - - def add(self): - return "无参数" - - -def __repr__(self): - s = "In __repr__:\n <{} object at {:#016x}>\n".format(repr(self.__class__), id(self)) # 使用类相关的信息输出类名和实例ID - s += super().__repr__() # 直接调用object.__repr__方法输出类信息和实例ID - # 通过实例的self.__dict__获取实例的详细属性信息,注意使用了repr函数去获取字典信息字符串 - s += '\n' + repr(self.__dict__) - return s - - -def __str__(self): - return f"My Dict {self.a}" - -book=Book("a","b","c") -book.Book__read="reads" -print(book.content) - - -print(book._Book__news) # 通过类._类名__变量名来访问私有属性 -#print(book._Book__read) -print(book) - - - +import self as self + +class MyMath: + @staticmethod + def add(a,b): #加法 + return a+b + + @staticmethod + def sub(a,b):# 减法 + return a-b + + @staticmethod + def mul(a,b):# 乘法 + return a*b + + @staticmethod + def division(a,b): #除法 + return a/b + + @staticmethod + def Power(a,b): #Power 幂 + return a**b + + @staticmethod + def sqr(a): #开根 + return a**(1/2) # x ** (1 / 2) + +""" +print(MyMath.add(3,4)) +print(MyMath.sub(3,4)) +print(MyMath.mul(3,4)) +print(MyMath.division(3,4)) +print(MyMath.Power(3,4)) +print(MyMath.sqr(4)) +""" + +print("-----------自定义类------------") +class Book: + content="我是父类的一个参数" #声明类属性 + __news="新闻" #声明私有属性 + + self.__read="read" #声明私有属性 通过实例._类名__变量名来访问私有属性 + + """ + def __int__(self): + pass + def __init__(self,sig): + self.sig=sig + """ + def __init__(self,a,b,c): + self.a=a + self.b=b + self.content="周杰伦" #初始化实例属性 + self.__news=c #绑定私有实例属性 + + def add(self): + return "无参数" + + +def __repr__(self): + s = "In __repr__:\n <{} object at {:#016x}>\n".format(repr(self.__class__), id(self)) # 使用类相关的信息输出类名和实例ID + s += super().__repr__() # 直接调用object.__repr__方法输出类信息和实例ID + # 通过实例的self.__dict__获取实例的详细属性信息,注意使用了repr函数去获取字典信息字符串 + s += '\n' + repr(self.__dict__) + return s + + +def __str__(self): + return f"My Dict {self.a}" + +book=Book("a","b","c") +book.Book__read="reads" +print(book.content) + + +print(book._Book__news) # 通过类._类名__变量名来访问私有属性 +#print(book._Book__read) +print(book) + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" index d6a463482c3170b55885fd33c2d11579cc03034c..27d5cbae7ae04a5b0d52520da2a7d820d2ecb8fe 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\346\235\216\346\263\212/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" @@ -1,92 +1,92 @@ -class MyMath: - def add(self,a,b): #加法 - return a+b - def sub(self,a,b):# 减法 - return a-b - def mul(self,a,b):# 乘法 - return a*b - def division(self,a,b): #除法 - return a/b - def Power(self,a,b): #Power 幂 - return a**b - def sqr(self,a): #开根 - return a**(1/2) # x ** (1 / 2) - -math=MyMath() -print(math.add(3,4)) -print(math.sub(3,4)) -print(math.mul(3,4)) -print(math.division(3,4)) -print(math.Power(3,4)) -print(math.sqr(4)) - - -class Book: - content="我是父类的一个参数" - def __int__(self): - pass - def __init__(self,sig): - self.sig=sig - def __init__(self,a,b): - self.a=a - self.b=b - - def add(self): - return "无参数" - -book=Book("a","b") -print(book.content) -print(book.a) -print(book.b) -print(book.add()) - -class ToolBook(Book): - def __int__(self,a): - self.a=a - - def add(self): - return "子类 无参数" - - def toolBook(self,a): - return a - -toolBook=ToolBook("a1","a2") -print(toolBook.add()) -print(toolBook.toolBook("我是 工具书,你呢?")) - -class LiteratureBook(Book): - def __int__(self): - self.a="LiteratureBook" - - def literature(self,a): - return a - -literatureBook=LiteratureBook("aa","dd") -print(literatureBook.a) -print(literatureBook.literature("我是文学工具书,你呢?")) - - -class SonBook(ToolBook,LiteratureBook): - - content = "我是子类的一个参数" #继承 父类的参数 - def __int__(self,a,b): - self.a=a - self.b=b - - def toolBook(self,a): #继承 父类的方法 - return a - - def literature(self,a):#继承 父类的方法 - return a - - def myBook(self): #定义自己的方法 - return "我有自己工具" - -print("-----------儿子---------") -sonBook=SonBook("儿子","儿子") -print(sonBook.a) -print(sonBook.content) -print(sonBook.toolBook("覆盖")) -print(sonBook.literature("覆盖2")) -print(sonBook.myBook()) +class MyMath: + def add(self,a,b): #加法 + return a+b + def sub(self,a,b):# 减法 + return a-b + def mul(self,a,b):# 乘法 + return a*b + def division(self,a,b): #除法 + return a/b + def Power(self,a,b): #Power 幂 + return a**b + def sqr(self,a): #开根 + return a**(1/2) # x ** (1 / 2) + +math=MyMath() +print(math.add(3,4)) +print(math.sub(3,4)) +print(math.mul(3,4)) +print(math.division(3,4)) +print(math.Power(3,4)) +print(math.sqr(4)) + + +class Book: + content="我是父类的一个参数" + def __int__(self): + pass + def __init__(self,sig): + self.sig=sig + def __init__(self,a,b): + self.a=a + self.b=b + + def add(self): + return "无参数" + +book=Book("a","b") +print(book.content) +print(book.a) +print(book.b) +print(book.add()) + +class ToolBook(Book): + def __int__(self,a): + self.a=a + + def add(self): + return "子类 无参数" + + def toolBook(self,a): + return a + +toolBook=ToolBook("a1","a2") +print(toolBook.add()) +print(toolBook.toolBook("我是 工具书,你呢?")) + +class LiteratureBook(Book): + def __int__(self): + self.a="LiteratureBook" + + def literature(self,a): + return a + +literatureBook=LiteratureBook("aa","dd") +print(literatureBook.a) +print(literatureBook.literature("我是文学工具书,你呢?")) + + +class SonBook(ToolBook,LiteratureBook): + + content = "我是子类的一个参数" #继承 父类的参数 + def __int__(self,a,b): + self.a=a + self.b=b + + def toolBook(self,a): #继承 父类的方法 + return a + + def literature(self,a):#继承 父类的方法 + return a + + def myBook(self): #定义自己的方法 + return "我有自己工具" + +print("-----------儿子---------") +sonBook=SonBook("儿子","儿子") +print(sonBook.a) +print(sonBook.content) +print(sonBook.toolBook("覆盖")) +print(sonBook.literature("覆盖2")) +print(sonBook.myBook()) print(sonBook.toolBook("我是你们的儿子")) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/main.py" index 695813a39a96169d855a5fe4da126b83efc680a3..898726ca0c1f2cdb42334a0a79bce5fcaf6b1e4e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/main.py" @@ -1,16 +1,16 @@ -# int, float, string, boolean, bytes, None -# list -l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] -print(l) - -# tuple -t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) -print(t) - -# dict -d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} -print(d) - -# set -s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} +# int, float, string, boolean, bytes, None +# list +l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] +print(l) + +# tuple +t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) +print(t) + +# dict +d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} +print(d) + +# set +s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} print(s) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index 9a6989eeba8236a9bcf0843b9b4c3f42a3a511f4..04a5fc22f99a5a201cf121faaa9b29c66505bca9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,6 +1,6 @@ -# 第一周-第一节-作业提交 - -![image](./images/L101.png) - -![image](./images/L102.png) - +# 第一周-第一节-作业提交 + +![image](./images/L101.png) + +![image](./images/L102.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index c4423bc2d906c324170ebb4e598a9cbc9da8f7f4..1052efdd9a6ed2be176faae1f348f27b56b58211 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,36 +1,36 @@ -# 第一周-第三节-作业提交 - -- #### 四大基本数据结构中哪些是可变的, 哪些是不可变的? - - 可变的:`list`,`dict`,`set` - - 不可变:`tuple` - -- #### 四大基本数据结构中哪些是有序的, 哪些是无序的? - - 有序的:`list`,`tuple` - - 无序的:`dict`,`set` - -- #### 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. - - ``` - # int, float, string, boolean, bytes, None - # list - l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] - print(l) - - # tuple - t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) - print(t) - - # dict - d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} - print(d) - - # set - s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} - print(s) - ``` - +# 第一周-第三节-作业提交 + +- #### 四大基本数据结构中哪些是可变的, 哪些是不可变的? + + 可变的:`list`,`dict`,`set` + + 不可变:`tuple` + +- #### 四大基本数据结构中哪些是有序的, 哪些是无序的? + + 有序的:`list`,`tuple` + + 无序的:`dict`,`set` + +- #### 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. + + ``` + # int, float, string, boolean, bytes, None + # list + l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] + print(l) + + # tuple + t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) + print(t) + + # dict + d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} + print(d) + + # set + s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} + print(s) + ``` + \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index 35540edabf2fb55c98a9153f5fc07a87da1e52a6..031fc346c289586a827490aea1c15b2bab113427 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,11 +1,11 @@ -# 第一周-第二节-作业提交 - -### 码云git仓库 - -![image](./images/远程仓库.png) - -![image](./images/远程仓库02.png) - -### pycharm虚拟环境 - +# 第一周-第二节-作业提交 + +### 码云git仓库 + +![image](./images/远程仓库.png) + +![image](./images/远程仓库02.png) + +### pycharm虚拟环境 + ![image](./images/克隆_虚拟环境.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/homework2.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/homework2.txt" index b42b4c4a84618dfa07f7f808aa13ebbd1372a996..0b9fc4aa8e6c80e6d1b40ab70cedafc0a38056e4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/homework2.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/homework2.txt" @@ -1,70 +1,70 @@ ->>> "鸽子".encode("unicode_escape").decode() -'\\u9e3d\\u5b50' ->>> '\u9e3d\u5b50' -'鸽子' ->>> len('\u9e3d\u5b50') -2 - ->>> "鸽子".encode("utf-8") -b'\xe9\xb8\xbd\xe5\xad\x90' ->>> b = b'\xe9\xb8\xbd\xe5\xad\x90' ->>> b.decode("utf") -'鸽子' - ->>> import chardet ->>> chardet.detect(b) -{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''} ->>> b_2 = "是".encode("gbk") + "鸽子".encode("utf-8") ->>> b_2 -b'\xca\xc7\xe9\xb8\xbd\xe5\xad\x90' - ->>> b_2.decode("utf-8", errors = 'ignore') -'鸽子' ->>> b_2.decode("utf-8", errors = 'replace') -'��鸽子' - ->>> a = "g">>> id(a) -25860512 ->>> a = a + "z" ->>> id(a) -19123520 ->>> a -'gz' - ->>> a = "a" ->>> a += "b" ->>> a -'ab' - ->>> a = "hello,world" ->>> a[4] -'o' ->>> a.find("o") -4 ->>> f = "2020-11-22XXXX" ->>> f.startswith("2020-11-22") -True ->>> f = "xxxxxxx.jpg" ->>> f.endswith(".jpg") -True - ->>> a = "faae pigeon, faae pigeon" ->>> a.replace("aae" , "ake") -'fake pigeon, fake pigeon' ->>> a = "<>,<>,<>" ->>> a.split(",") -['<>', '<>', '<>'] ->>> b = a.split(",") ->>> b -['<>', '<>', '<>'] ->>> ",".join(b) -'<>,<>,<>' ->>> a = " fake pigeon " ->>> a -' fake pigeon ' ->>> a.strip() -'fake pigeon' ->>> a.lstrip() -'fake pigeon ' ->>> a.rstrip() +>>> "鸽子".encode("unicode_escape").decode() +'\\u9e3d\\u5b50' +>>> '\u9e3d\u5b50' +'鸽子' +>>> len('\u9e3d\u5b50') +2 + +>>> "鸽子".encode("utf-8") +b'\xe9\xb8\xbd\xe5\xad\x90' +>>> b = b'\xe9\xb8\xbd\xe5\xad\x90' +>>> b.decode("utf") +'鸽子' + +>>> import chardet +>>> chardet.detect(b) +{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''} +>>> b_2 = "是".encode("gbk") + "鸽子".encode("utf-8") +>>> b_2 +b'\xca\xc7\xe9\xb8\xbd\xe5\xad\x90' + +>>> b_2.decode("utf-8", errors = 'ignore') +'鸽子' +>>> b_2.decode("utf-8", errors = 'replace') +'��鸽子' + +>>> a = "g">>> id(a) +25860512 +>>> a = a + "z" +>>> id(a) +19123520 +>>> a +'gz' + +>>> a = "a" +>>> a += "b" +>>> a +'ab' + +>>> a = "hello,world" +>>> a[4] +'o' +>>> a.find("o") +4 +>>> f = "2020-11-22XXXX" +>>> f.startswith("2020-11-22") +True +>>> f = "xxxxxxx.jpg" +>>> f.endswith(".jpg") +True + +>>> a = "faae pigeon, faae pigeon" +>>> a.replace("aae" , "ake") +'fake pigeon, fake pigeon' +>>> a = "<>,<>,<>" +>>> a.split(",") +['<>', '<>', '<>'] +>>> b = a.split(",") +>>> b +['<>', '<>', '<>'] +>>> ",".join(b) +'<>,<>,<>' +>>> a = " fake pigeon " +>>> a +' fake pigeon ' +>>> a.strip() +'fake pigeon' +>>> a.lstrip() +'fake pigeon ' +>>> a.rstrip() ' fake pigeon' \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson2.py" index a81ddafd8a90b5e480922e6ec69a1372a759b959..259a6f9c28c15d36c7bffba5b6ad083df2faebe7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson2.py" @@ -1,78 +1,78 @@ -# open函数打开一个文件,没有文件会新建,但是路径不对会报错 -# 指定文件名,方法(读,写,追加),编码格式 -output = open("homework2.txt", "w", encoding="utf-8") -content = ">>> \"鸽子\".encode(\"unicode_escape\").decode()\n" \ - "'\\\\u9e3d\\\\u5b50'\n" \ - ">>> '\\u9e3d\\u5b50'\n" \ - "'鸽子'\n" \ - ">>> len('\\u9e3d\\u5b50')\n" \ - "2\n" \ - "\n" \ - ">>> \"鸽子\".encode(\"utf-8\")\n" \ - "b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ - ">>> b = b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ - ">>> b.decode(\"utf\")\n" \ - "'鸽子'\n" \ - "\n" \ - ">>> import chardet\n" \ - ">>> chardet.detect(b)\n" \ - "{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''}\n" \ - ">>> b_2 = \"是\".encode(\"gbk\") + \"鸽子\".encode(\"utf-8\")\n" \ - ">>> b_2\n" \ - "b'\\xca\\xc7\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ - "\n" \ - ">>> b_2.decode(\"utf-8\", errors = 'ignore')\n" \ - "'鸽子'\n" \ - ">>> b_2.decode(\"utf-8\", errors = 'replace')\n" \ - "'��鸽子'\n" \ - "\n" \ - ">>> a = \"g\"" \ - ">>> id(a)\n" \ - "25860512\n" \ - ">>> a = a + \"z\"\n" \ - ">>> id(a)\n" \ - "19123520\n" \ - ">>> a\n" \ - "'gz'\n" \ - "\n" \ - ">>> a = \"a\"\n" \ - ">>> a += \"b\"\n" \ - ">>> a\n" \ - "'ab'\n" \ - "\n" \ - ">>> a = \"hello,world\"\n" \ - ">>> a[4]\n" \ - "'o'\n" \ - ">>> a.find(\"o\")\n" \ - "4\n" \ - ">>> f = \"2020-11-22XXXX\"\n" \ - ">>> f.startswith(\"2020-11-22\")\n" \ - "True\n" \ - ">>> f = \"xxxxxxx.jpg\"\n" \ - ">>> f.endswith(\".jpg\")\n" \ - "True\n" \ - "\n" \ - ">>> a = \"faae pigeon, faae pigeon\"\n" \ - ">>> a.replace(\"aae\" , \"ake\")\n" \ - "'fake pigeon, fake pigeon'\n" \ - ">>> a = \"<>,<>,<>\"\n" \ - ">>> a.split(\",\")\n" \ - "['<>', '<>', '<>']\n" \ - ">>> b = a.split(\",\")\n" \ - ">>> b\n" \ - "['<>', '<>', '<>']\n" \ - ">>> \",\".join(b)\n" \ - "'<>,<>,<>'\n" \ - ">>> a = \" fake pigeon \"\n" \ - ">>> a\n" \ - "' fake pigeon '\n" \ - ">>> a.strip()\n" \ - "'fake pigeon'\n" \ - ">>> a.lstrip()\n" \ - "'fake pigeon '\n" \ - ">>> a.rstrip()\n" \ - "' fake pigeon'" -# 正式写入文件 -output.write(content) -# 关闭文件句柄 +# open函数打开一个文件,没有文件会新建,但是路径不对会报错 +# 指定文件名,方法(读,写,追加),编码格式 +output = open("homework2.txt", "w", encoding="utf-8") +content = ">>> \"鸽子\".encode(\"unicode_escape\").decode()\n" \ + "'\\\\u9e3d\\\\u5b50'\n" \ + ">>> '\\u9e3d\\u5b50'\n" \ + "'鸽子'\n" \ + ">>> len('\\u9e3d\\u5b50')\n" \ + "2\n" \ + "\n" \ + ">>> \"鸽子\".encode(\"utf-8\")\n" \ + "b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ + ">>> b = b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ + ">>> b.decode(\"utf\")\n" \ + "'鸽子'\n" \ + "\n" \ + ">>> import chardet\n" \ + ">>> chardet.detect(b)\n" \ + "{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''}\n" \ + ">>> b_2 = \"是\".encode(\"gbk\") + \"鸽子\".encode(\"utf-8\")\n" \ + ">>> b_2\n" \ + "b'\\xca\\xc7\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \ + "\n" \ + ">>> b_2.decode(\"utf-8\", errors = 'ignore')\n" \ + "'鸽子'\n" \ + ">>> b_2.decode(\"utf-8\", errors = 'replace')\n" \ + "'��鸽子'\n" \ + "\n" \ + ">>> a = \"g\"" \ + ">>> id(a)\n" \ + "25860512\n" \ + ">>> a = a + \"z\"\n" \ + ">>> id(a)\n" \ + "19123520\n" \ + ">>> a\n" \ + "'gz'\n" \ + "\n" \ + ">>> a = \"a\"\n" \ + ">>> a += \"b\"\n" \ + ">>> a\n" \ + "'ab'\n" \ + "\n" \ + ">>> a = \"hello,world\"\n" \ + ">>> a[4]\n" \ + "'o'\n" \ + ">>> a.find(\"o\")\n" \ + "4\n" \ + ">>> f = \"2020-11-22XXXX\"\n" \ + ">>> f.startswith(\"2020-11-22\")\n" \ + "True\n" \ + ">>> f = \"xxxxxxx.jpg\"\n" \ + ">>> f.endswith(\".jpg\")\n" \ + "True\n" \ + "\n" \ + ">>> a = \"faae pigeon, faae pigeon\"\n" \ + ">>> a.replace(\"aae\" , \"ake\")\n" \ + "'fake pigeon, fake pigeon'\n" \ + ">>> a = \"<>,<>,<>\"\n" \ + ">>> a.split(\",\")\n" \ + "['<>', '<>', '<>']\n" \ + ">>> b = a.split(\",\")\n" \ + ">>> b\n" \ + "['<>', '<>', '<>']\n" \ + ">>> \",\".join(b)\n" \ + "'<>,<>,<>'\n" \ + ">>> a = \" fake pigeon \"\n" \ + ">>> a\n" \ + "' fake pigeon '\n" \ + ">>> a.strip()\n" \ + "'fake pigeon'\n" \ + ">>> a.lstrip()\n" \ + "'fake pigeon '\n" \ + ">>> a.rstrip()\n" \ + "' fake pigeon'" +# 正式写入文件 +output.write(content) +# 关闭文件句柄 output.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson3.py" index cdc3f7fe1d52efa70dc1812b3bd3366550af74f2..57817bdfdaf1a3eead4de297712ea8df56322f57 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/lesson3.py" @@ -1,92 +1,92 @@ -# int, float, string, boolean, bytes, None -# list -l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] -print('l:', l) -# append -l.append('append') -print('l:', l) -# + & += -l1 = ['l1'] -l2 = l + l1 -print('l2:', l2) -l += l1 -print('l:', l) -# * & *= -a = 'a' -la = a * 10 -print('la:', la) -# insert -l.insert(0, 'start') -print('l:', l) -# retrieve -print('l[1]:', l[1]) -print('l[0:5]:', l[0:5]) -l.insert(l.index('abc'), 'before') -print('l:', l) -# update -l[0] = 'start2' -print(l) -l[0: 2] = 'a' -print('l:', l) -# delete -x = l.pop() -print('x:', x) -print('l:', l) -l.clear() -print('l:', l) -# sort -l = [1, 4, 2, 6, 3] -l.sort() -print('l:', l) -l_1 = [1, 4, 2, 6, 3] -l_2 = sorted(l_1) -print('l_1:', l_1) -print('l_2:', l_2) -l.reverse() -print('l:', l) -print('\n') - -# tuple -t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) -print('t:', t) -# retrieve -print('t[0]:', t[0]) -print('t.index(2):', t.index(2)) -print('t[0:2]', t[0:2]) -print('\n') - -# dict -d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} -print(d) -# update -d2 = {'g': 1, 'h': 2} -d.update(d2) -print('d2', d2) -print('d:', d) -x = d.setdefault('b', 0) -print('x:', x) -print('d:', d) -keys = list(d.keys()) -print('keys:', keys) -values = d.values() -print('values:', values) -items = d.items() -print('items:', items) -# delete -a = d.pop('a') -print('a:', a) -print('d:', d) -d.clear() -print('d:', d) -print('\n') - -# set -s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} -print('s:', s) -s.add('last') -print('s:', s) -b = 'a' in s -print('b:', b) -# delete -s.remove('world') +# int, float, string, boolean, bytes, None +# list +l = [1, 1.1, 'abc', bool(1), bytes('abc'.encode("utf-8")), None] +print('l:', l) +# append +l.append('append') +print('l:', l) +# + & += +l1 = ['l1'] +l2 = l + l1 +print('l2:', l2) +l += l1 +print('l:', l) +# * & *= +a = 'a' +la = a * 10 +print('la:', la) +# insert +l.insert(0, 'start') +print('l:', l) +# retrieve +print('l[1]:', l[1]) +print('l[0:5]:', l[0:5]) +l.insert(l.index('abc'), 'before') +print('l:', l) +# update +l[0] = 'start2' +print(l) +l[0: 2] = 'a' +print('l:', l) +# delete +x = l.pop() +print('x:', x) +print('l:', l) +l.clear() +print('l:', l) +# sort +l = [1, 4, 2, 6, 3] +l.sort() +print('l:', l) +l_1 = [1, 4, 2, 6, 3] +l_2 = sorted(l_1) +print('l_1:', l_1) +print('l_2:', l_2) +l.reverse() +print('l:', l) +print('\n') + +# tuple +t = (2, 2.2, 'def', bool(0), bytes('def'.encode("utf-8")), None) +print('t:', t) +# retrieve +print('t[0]:', t[0]) +print('t.index(2):', t.index(2)) +print('t[0:2]', t[0:2]) +print('\n') + +# dict +d = {'a': 3, 'b': 3.3, 'c': 'hello', 'd': bool(3), 'e': bytes('hello'.encode("utf-8")), 'f': None} +print(d) +# update +d2 = {'g': 1, 'h': 2} +d.update(d2) +print('d2', d2) +print('d:', d) +x = d.setdefault('b', 0) +print('x:', x) +print('d:', d) +keys = list(d.keys()) +print('keys:', keys) +values = d.values() +print('values:', values) +items = d.items() +print('items:', items) +# delete +a = d.pop('a') +print('a:', a) +print('d:', d) +d.clear() +print('d:', d) +print('\n') + +# set +s = {4, 4.4, 'world', bool(4), bytes('world'.encode("utf-8")), None} +print('s:', s) +s.add('last') +print('s:', s) +b = 'a' in s +print('b:', b) +# delete +s.remove('world') print('s:', s) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/my_caculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/my_caculator.py" index 16d1544e5f3cd860de00233025a0c3695a5c6b0e..f25ba097305f466d32a97c79a53d79bd66a2b4b8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/my_caculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week2/my_caculator.py" @@ -1,48 +1,48 @@ -def add(a, b): - print(a, "+", b, "=") - return a + b - -def minus(a, b): - print(a, "-", b, "=") - return a - b - -def mul(a, b): - print(a, "*", b, "=") - return a * b - -def div(a, b): - print(a, "/", b, "=") - return a / b - -def be_div(a, b): - print(a, "//", b, "=") - return a // b - -def rem(a, b): - print(a, "%", b, "=") - return a % b - -def root(a): - print(a, "^1/2 =") - return a ** (1/2) - -a = int(input("请输入数字:")) -symbol = str(input("请输入要执行的操作:")) -if str(symbol) == "开方": - print(root(a)) -else: - b = int(input("请输入数字:")) - if str(symbol) == "+": - print(add(a, b)) - elif str(symbol) == "-": - print(minus(a, b)) - elif str(symbol) == "*": - print(mul(a, b)) - elif str(symbol) == "/": - print(div(a, b)) - elif str(symbol) == "//": - print(be_div(a, b)) - elif str(symbol) == "%": - print(rem(a, b)) - else: +def add(a, b): + print(a, "+", b, "=") + return a + b + +def minus(a, b): + print(a, "-", b, "=") + return a - b + +def mul(a, b): + print(a, "*", b, "=") + return a * b + +def div(a, b): + print(a, "/", b, "=") + return a / b + +def be_div(a, b): + print(a, "//", b, "=") + return a // b + +def rem(a, b): + print(a, "%", b, "=") + return a % b + +def root(a): + print(a, "^1/2 =") + return a ** (1/2) + +a = int(input("请输入数字:")) +symbol = str(input("请输入要执行的操作:")) +if str(symbol) == "开方": + print(root(a)) +else: + b = int(input("请输入数字:")) + if str(symbol) == "+": + print(add(a, b)) + elif str(symbol) == "-": + print(minus(a, b)) + elif str(symbol) == "*": + print(mul(a, b)) + elif str(symbol) == "/": + print(div(a, b)) + elif str(symbol) == "//": + print(be_div(a, b)) + elif str(symbol) == "%": + print(rem(a, b)) + else: print("无法进行该运算") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson1.py" index a08cb00953013daacfb35f195dbeb1c0e76a7ea1..d36f06a68ccc13733bc6727cbaff712be31cd365 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson1.py" @@ -1,107 +1,107 @@ -l = [1, 2, 3, 4, 5, 6, 7] -fcount = 0 -# for循环计数 -for i in l: - fcount += 1 -print(f"一共有:{fcount}") - -# while循环计数 -i = 0 -wcount = 0 -while i < 100: - i += 3 - wcount += 1 -print(f"一共有:{wcount}") - - -# for斐波那契 -i = 0 -j = 1 -l1 = [] -l1.append(i) -l1.append(j) -for n in range(0, 5): - i += j - l1.append(i) - j += i - l1.append(j) -print(l1) - -# while斐波那契 -i = 0 -j = 1 -l2 = [] -l2.append(i) -l2.append(j) -while True: - i += j - if i < 100: - l2.append(i) - else: - break - j += i - if j < 100: - l2.append(j) - else: - break -print(l2) - -# 计算器 - -class ParamsError(Exception): - pass -def add(a, b): - print(a, "+", b, "=") - return a + b - -def minus(a, b): - print(a, "-", b, "=") - return a - b - -def mul(a, b): - print(a, "*", b, "=") - return a * b - -def div(a, b): - try: - print(a, "/", b, "=") - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function div end") - -def be_div(a, b): - print(a, "//", b, "=") - return a // b - -def rem(a, b): - print(a, "%", b, "=") - return a % b - -def root(a): - print(a, "^1/2 =") - return a ** (1/2) - -a = int(input("请输入数字:")) -print("加法运算请输入'+',减法运算请输入’-‘,乘法运算请输入’*‘,除法运算请输入’/‘") -print("取商运算请输入‘//’,取余运算请输入‘%’,开方运算请输入‘开方’") -symbol = str(input("请输入要执行的操作:")) -if str(symbol) == "开方": - print(root(a)) -else: - b = int(input("请输入数字:")) - if str(symbol) == "+": - print(add(a, b)) - elif str(symbol) == "-": - print(minus(a, b)) - elif str(symbol) == "*": - print(mul(a, b)) - elif str(symbol) == "/": - print(div(a, b)) - elif str(symbol) == "//": - print(be_div(a, b)) - elif str(symbol) == "%": - print(rem(a, b)) - else: +l = [1, 2, 3, 4, 5, 6, 7] +fcount = 0 +# for循环计数 +for i in l: + fcount += 1 +print(f"一共有:{fcount}") + +# while循环计数 +i = 0 +wcount = 0 +while i < 100: + i += 3 + wcount += 1 +print(f"一共有:{wcount}") + + +# for斐波那契 +i = 0 +j = 1 +l1 = [] +l1.append(i) +l1.append(j) +for n in range(0, 5): + i += j + l1.append(i) + j += i + l1.append(j) +print(l1) + +# while斐波那契 +i = 0 +j = 1 +l2 = [] +l2.append(i) +l2.append(j) +while True: + i += j + if i < 100: + l2.append(i) + else: + break + j += i + if j < 100: + l2.append(j) + else: + break +print(l2) + +# 计算器 + +class ParamsError(Exception): + pass +def add(a, b): + print(a, "+", b, "=") + return a + b + +def minus(a, b): + print(a, "-", b, "=") + return a - b + +def mul(a, b): + print(a, "*", b, "=") + return a * b + +def div(a, b): + try: + print(a, "/", b, "=") + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function div end") + +def be_div(a, b): + print(a, "//", b, "=") + return a // b + +def rem(a, b): + print(a, "%", b, "=") + return a % b + +def root(a): + print(a, "^1/2 =") + return a ** (1/2) + +a = int(input("请输入数字:")) +print("加法运算请输入'+',减法运算请输入’-‘,乘法运算请输入’*‘,除法运算请输入’/‘") +print("取商运算请输入‘//’,取余运算请输入‘%’,开方运算请输入‘开方’") +symbol = str(input("请输入要执行的操作:")) +if str(symbol) == "开方": + print(root(a)) +else: + b = int(input("请输入数字:")) + if str(symbol) == "+": + print(add(a, b)) + elif str(symbol) == "-": + print(minus(a, b)) + elif str(symbol) == "*": + print(mul(a, b)) + elif str(symbol) == "/": + print(div(a, b)) + elif str(symbol) == "//": + print(be_div(a, b)) + elif str(symbol) == "%": + print(rem(a, b)) + else: print("无法进行该运算") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson2.py" index a5d6438745d2d8f9f059d8ebd51e70d52ceb8cb2..c30fe1acdc025bc8d273049124fb82493e55adf2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson2.py" @@ -1,34 +1,34 @@ -# 根据grade排序 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -classes.sort(key=lambda x: x.get("grade")) -print(classes) - -# 筛选grade为A的同学 -f = filter(lambda x: True if x.get("grade") == "A" else False, classes) -print(list(f)) - -# age + 1 -m = map(lambda x: x.get("age") + 1, classes) -print(list(m)) - - -# 递归函数 -def f(n): - if n == 1: - return 0 - elif n == 2: - return 1 - else: - return f(n - 1) + f(n - 2) - - -for i in range(1, 13): +# 根据grade排序 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +classes.sort(key=lambda x: x.get("grade")) +print(classes) + +# 筛选grade为A的同学 +f = filter(lambda x: True if x.get("grade") == "A" else False, classes) +print(list(f)) + +# age + 1 +m = map(lambda x: x.get("age") + 1, classes) +print(list(m)) + + +# 递归函数 +def f(n): + if n == 1: + return 0 + elif n == 2: + return 1 + else: + return f(n - 1) + f(n - 2) + + +for i in range(1, 13): print(f(i)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson3.py" index 0f5082bee924c35da18498d9df5b64860c066a27..9cc0f55a5d1222bf00ef226a7d7927e493feb43d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week3/lesson3.py" @@ -1,85 +1,85 @@ -import time - -a = "a" -b = "b" -c = ["c"] - -def foo1(): - a = "a_change" - global b - b = "b_change" - c.append("c_change") - print("此处a为函数foo1的局部变量:a =", a) - print("此处b进行global申明,为全局变量:b =", b) - print("此处c未进行赋值,c仍为全局变量:c =", c) - return None - -foo1() -print("此处a为全局变量,foo1的调用对全局变量a不产生影响:a =", a) -print("此处b为全局变量,b在调用foo1后发生改变:b =", b) -print("此处c为全局变量,b在调用foo1后发生改变:c =", c) - -def make_sum(): - sum = 0 - def get_sum(x): - nonlocal sum - sum += x - return sum - return get_sum - -sum_x = make_sum() -print(sum_x(1)) -print(sum_x(2)) -print(sum_x(3)) -print(sum_x(4)) - - -# 时间装饰器 -def clock_it_deco(func): - def wrapper(a, b): - start_time = time.time() - result = func(a, b) - end_time = time.time() - print(f"{func.__name__} execution time is : {format(end_time - start_time, '.2f')} s") - return result - - return wrapper - -@clock_it_deco -def foo2(a, b): - count = 0 - while True: - if count > a ** b: - break - else: - count += 1 - -foo2(10, 5) - - - -# 斐波那契装饰器 -def fib_cache_deco(func): - def wrapper(n): - d_fib = {} - if n in d_fib.keys(): - print(d_fib) - return d_fib(n) - else: - result = func(n) - d = {n: result} - d_fib.update(d) - print(d_fib) - return result - - return wrapper - - -@fib_cache_deco -def fib(n): - if n == 1: - return 0 - elif n == 2: - return 1 - else: +import time + +a = "a" +b = "b" +c = ["c"] + +def foo1(): + a = "a_change" + global b + b = "b_change" + c.append("c_change") + print("此处a为函数foo1的局部变量:a =", a) + print("此处b进行global申明,为全局变量:b =", b) + print("此处c未进行赋值,c仍为全局变量:c =", c) + return None + +foo1() +print("此处a为全局变量,foo1的调用对全局变量a不产生影响:a =", a) +print("此处b为全局变量,b在调用foo1后发生改变:b =", b) +print("此处c为全局变量,b在调用foo1后发生改变:c =", c) + +def make_sum(): + sum = 0 + def get_sum(x): + nonlocal sum + sum += x + return sum + return get_sum + +sum_x = make_sum() +print(sum_x(1)) +print(sum_x(2)) +print(sum_x(3)) +print(sum_x(4)) + + +# 时间装饰器 +def clock_it_deco(func): + def wrapper(a, b): + start_time = time.time() + result = func(a, b) + end_time = time.time() + print(f"{func.__name__} execution time is : {format(end_time - start_time, '.2f')} s") + return result + + return wrapper + +@clock_it_deco +def foo2(a, b): + count = 0 + while True: + if count > a ** b: + break + else: + count += 1 + +foo2(10, 5) + + + +# 斐波那契装饰器 +def fib_cache_deco(func): + def wrapper(n): + d_fib = {} + if n in d_fib.keys(): + print(d_fib) + return d_fib(n) + else: + result = func(n) + d = {n: result} + d_fib.update(d) + print(d_fib) + return result + + return wrapper + + +@fib_cache_deco +def fib(n): + if n == 1: + return 0 + elif n == 2: + return 1 + else: return fib(n - 1) + fib(n - 2) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson1.py" index 929822ed07fc8da4aa90c2a562c6b1a506950c18..d052557d6f7978d6ee44a1ce75f2b5bcbb5ca089 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson1.py" @@ -1,51 +1,51 @@ -import datetime -import time -from datetime import timedelta - -now = datetime.datetime.now(tz=None) -ts = time.time() - -# datetime.datetime对象转换为时间戳 -now_ts = now.timestamp() -print("datetime.datetime对象转换为时间戳: now_ts =", now_ts) - -# 时间戳转换为datetime.datetime对象 -ts_now = datetime.datetime.fromtimestamp(ts, tz=None) -print("时间戳转换为datetime.datetime对象: ts_now =", ts_now) -print("ts_now数据类型:", type(ts_now)) - -print('\n') - -# datetime.datetime对象转换为字符串 -now_s = now.strftime("%Y-%m-%d %H:%M:%S") -print("datetime.datetime对象转换为字符串: now_s =", now_s) - -# 字符串转换为datetime.datetime对象 -s_now = datetime.datetime.strptime(now_s, "%Y-%m-%d %H:%M:%S") -print("字符串转换为datetime.datetime对象: s_now =", s_now) -print("s_now数据类型: ", type(s_now)) - -print('\n') - -# 时间戳转换为字符串 -t_n = datetime.datetime.fromtimestamp(ts, tz=None) -n_s = t_n.strftime("%Y-%m-%d %H:%M:%S") -print("时间戳转换为字符串: n_s =", n_s) - -# 字符串转换为时间戳 -s_n = datetime.datetime.strptime(n_s, "%Y-%m-%d %H:%M:%S") -n_t = s_n.timestamp() -print("字符串转换为时间戳: n_t =", n_t) - -print('\n') - - -def get_date(day_delt): - n = datetime.datetime.now(tz=None) - n = n + timedelta(days=day_delt) - s = n.strftime("%Y-%m-%d") - print("进行运算后时间: ", s) - return None - -x = int(input("请输入需要运算的天数:\n")) +import datetime +import time +from datetime import timedelta + +now = datetime.datetime.now(tz=None) +ts = time.time() + +# datetime.datetime对象转换为时间戳 +now_ts = now.timestamp() +print("datetime.datetime对象转换为时间戳: now_ts =", now_ts) + +# 时间戳转换为datetime.datetime对象 +ts_now = datetime.datetime.fromtimestamp(ts, tz=None) +print("时间戳转换为datetime.datetime对象: ts_now =", ts_now) +print("ts_now数据类型:", type(ts_now)) + +print('\n') + +# datetime.datetime对象转换为字符串 +now_s = now.strftime("%Y-%m-%d %H:%M:%S") +print("datetime.datetime对象转换为字符串: now_s =", now_s) + +# 字符串转换为datetime.datetime对象 +s_now = datetime.datetime.strptime(now_s, "%Y-%m-%d %H:%M:%S") +print("字符串转换为datetime.datetime对象: s_now =", s_now) +print("s_now数据类型: ", type(s_now)) + +print('\n') + +# 时间戳转换为字符串 +t_n = datetime.datetime.fromtimestamp(ts, tz=None) +n_s = t_n.strftime("%Y-%m-%d %H:%M:%S") +print("时间戳转换为字符串: n_s =", n_s) + +# 字符串转换为时间戳 +s_n = datetime.datetime.strptime(n_s, "%Y-%m-%d %H:%M:%S") +n_t = s_n.timestamp() +print("字符串转换为时间戳: n_t =", n_t) + +print('\n') + + +def get_date(day_delt): + n = datetime.datetime.now(tz=None) + n = n + timedelta(days=day_delt) + s = n.strftime("%Y-%m-%d") + print("进行运算后时间: ", s) + return None + +x = int(input("请输入需要运算的天数:\n")) get_date(x) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson2.py" index 7e0e9be1382db2fa27196c9170fe2cdcc364d15f..e7a7c14f28b26d4aa528f7d0efddf49d5005b618 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson2.py" @@ -1,41 +1,41 @@ -class MyMath: - def add(self, a, b): - return a + b - - def minus(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - return a / b - - def root(self, a): - return a ** (1 / 2) - - - -class Worker: - profession = 'Internet' - def __init__(self, name): - self.p = name - - -class FinanceWorker(Worker): - department = 'finance' - -class DevelopWorker(Worker): - department = 'development' - -class ServiceWorker(Worker): - department = 'service' - -a = FinanceWorker('Alice') -print(f"{a.p}在{a.profession}的{a.department}部") - -b = DevelopWorker('Barbara') -print(f"{b.p}在{b.profession}的{b.department}部") - -c = ServiceWorker('Carl') +class MyMath: + def add(self, a, b): + return a + b + + def minus(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def root(self, a): + return a ** (1 / 2) + + + +class Worker: + profession = 'Internet' + def __init__(self, name): + self.p = name + + +class FinanceWorker(Worker): + department = 'finance' + +class DevelopWorker(Worker): + department = 'development' + +class ServiceWorker(Worker): + department = 'service' + +a = FinanceWorker('Alice') +print(f"{a.p}在{a.profession}的{a.department}部") + +b = DevelopWorker('Barbara') +print(f"{b.p}在{b.profession}的{b.department}部") + +c = ServiceWorker('Carl') print(f"{c.p}在{c.profession}的{c.department}部") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson3.py" index 4341ba124eb759a709507716162e7096df436018..412995de43226220658b2b49da28f21bbbc9058d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week4/lesson3.py" @@ -1,52 +1,52 @@ -# MyMath类静态方法 -class MyMath: - @staticmethod - def add(a, b): - return a + b - - @staticmethod - def minus(a, b): - return a - b - - @staticmethod - def mul(a, b): - return a * b - - @staticmethod - def div(a, b): - return a / b - - @staticmethod - def root(a): - return a ** (1 / 2) - -print(MyMath.add(1, 2)) -print(MyMath.minus(4, 3)) -print(MyMath.mul(2, 4)) -print(MyMath.div(6, 3)) -print(MyMath.root(9)) - - -# 自定义类 -class Worker: - # 类属性 - profession = 'Internet' - # 私有属性 - __firm = 'hehe' - # init类初始化实例属性、绑定私有实例属性 - def __init__(self, name = None): - self.__name = name - # 自定义类中实现__str__自定义输出格式 - @classmethod - def __str__(cls, *args, **kwargs): - print(f"员工从事行业为{cls.profession},公司名为{cls.__firm}") - return None - - -w = Worker() -print(w._Worker__name) - -a = Worker('Alice') -print(a._Worker__name) -a.__str__() - +# MyMath类静态方法 +class MyMath: + @staticmethod + def add(a, b): + return a + b + + @staticmethod + def minus(a, b): + return a - b + + @staticmethod + def mul(a, b): + return a * b + + @staticmethod + def div(a, b): + return a / b + + @staticmethod + def root(a): + return a ** (1 / 2) + +print(MyMath.add(1, 2)) +print(MyMath.minus(4, 3)) +print(MyMath.mul(2, 4)) +print(MyMath.div(6, 3)) +print(MyMath.root(9)) + + +# 自定义类 +class Worker: + # 类属性 + profession = 'Internet' + # 私有属性 + __firm = 'hehe' + # init类初始化实例属性、绑定私有实例属性 + def __init__(self, name = None): + self.__name = name + # 自定义类中实现__str__自定义输出格式 + @classmethod + def __str__(cls, *args, **kwargs): + print(f"员工从事行业为{cls.profession},公司名为{cls.__firm}") + return None + + +w = Worker() +print(w._Worker__name) + +a = Worker('Alice') +print(a._Worker__name) +a.__str__() + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson1.py" index 432d0fc52e7edcdff9f7706ecb56e30b0a849ab8..af25543bcc8159549320710adb8bdf5472d23f16 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson1.py" @@ -1,50 +1,50 @@ -import requests -from threading import Thread -from multiprocessing import Process -import time - -result = [] - -def request_sougou(index): - time.sleep(1) - url = "https://www.sogou.com/" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75" - } - response = requests.get(url=url, headers=headers) - print(f"序列号:{index}, 结果状态码:{response.status_code}") - result.append(response) - - - -# 多线程部分: -if __name__ == "__main__": - start_time = time.time() - thread_array = [] - for i in range(5): - t = Thread(target=request_sougou, args=(i, )) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - end_time = time.time() - print("done!") - print(result) - print(f"多线程执行时间为:{end_time-start_time} s") - - -# 多进程部分: -if __name__ == "__main__": - start_time = time.time() - process_array = [] - for i in range(5): - p = Process(target=request_sougou, args=(i, )) - process_array.append(p) - p.start() - # 调用thread对象join接口,等任务完成后回到主进程 - for p in process_array: - p.join() - end_time = time.time() - print("done!") - print("多进程无法通过全局变量拿到返回结果") +import requests +from threading import Thread +from multiprocessing import Process +import time + +result = [] + +def request_sougou(index): + time.sleep(1) + url = "https://www.sogou.com/" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75" + } + response = requests.get(url=url, headers=headers) + print(f"序列号:{index}, 结果状态码:{response.status_code}") + result.append(response) + + + +# 多线程部分: +if __name__ == "__main__": + start_time = time.time() + thread_array = [] + for i in range(5): + t = Thread(target=request_sougou, args=(i, )) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + end_time = time.time() + print("done!") + print(result) + print(f"多线程执行时间为:{end_time-start_time} s") + + +# 多进程部分: +if __name__ == "__main__": + start_time = time.time() + process_array = [] + for i in range(5): + p = Process(target=request_sougou, args=(i, )) + process_array.append(p) + p.start() + # 调用thread对象join接口,等任务完成后回到主进程 + for p in process_array: + p.join() + end_time = time.time() + print("done!") + print("多进程无法通过全局变量拿到返回结果") print(f"多进程执行时间为:{end_time-start_time} s") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson2.py" index 170351c6fdd14759b7a768f519a7a3d54f7bb889..295fd5e6517b592af86a376c54ddf3e844c44555 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson2.py" @@ -1,58 +1,58 @@ -from threading import Thread, Lock -from multiprocessing import Process, Lock -from multiprocessing import Queue - -# 多进程锁 -# 文件 -def save_to_file(index, lock): - # f = open("test.log", "w", encoding="utf-8") - # f.write(index) - # f.close() - - # lock.acquire() - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + '\n') - # lock.release() - -# 消息队列 -def save_to_queue(index, my_queue): - my_queue.put(index) - # print(my_queue.get()) - -if __name__ == "__main__": - process_array = [] - my_queue = Queue() - # lock = Lock() - for i in range(5): - # p = Process(target=save_to_file, args=(i, lock)) - p = Process(target=save_to_queue, args=(i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - # print("done!") - - while True: - print(my_queue.get()) - -# 多线程锁 -x = 0 -lock = Lock() - -def lock_Thread(): - global x - for i in range (10**6): - with lock: - x += 1 - x -= 1 - -if __name__ == "__main__": - thread_array = [] - for i in range(2): - t = Thread(target=lock_Thread) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() +from threading import Thread, Lock +from multiprocessing import Process, Lock +from multiprocessing import Queue + +# 多进程锁 +# 文件 +def save_to_file(index, lock): + # f = open("test.log", "w", encoding="utf-8") + # f.write(index) + # f.close() + + # lock.acquire() + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + '\n') + # lock.release() + +# 消息队列 +def save_to_queue(index, my_queue): + my_queue.put(index) + # print(my_queue.get()) + +if __name__ == "__main__": + process_array = [] + my_queue = Queue() + # lock = Lock() + for i in range(5): + # p = Process(target=save_to_file, args=(i, lock)) + p = Process(target=save_to_queue, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + # print("done!") + + while True: + print(my_queue.get()) + +# 多线程锁 +x = 0 +lock = Lock() + +def lock_Thread(): + global x + for i in range (10**6): + with lock: + x += 1 + x -= 1 + +if __name__ == "__main__": + thread_array = [] + for i in range(2): + t = Thread(target=lock_Thread) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() print(x) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson3.py" index ead7ecaa8a7447a249aa31b42b35f5b7785b1456..f690e411f8b1e159aaea703907f0923d2fe704fe 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/lesson3.py" @@ -1,62 +1,62 @@ -# 迭代器:一次只返回一个元素,省内存,只能自行通过调用next方法,才能返回值。 -# 迭代器中没有值后抛出的异常需要自行处理 - -# 生成器:特殊的迭代器,通过生成器可以实现函数的暂停。 -# yield:暂停并返回右边的值 - -# 协程:函数的实现依靠:send赋值,yield暂停并返回值 -# send->yield;send->yield;send->yield - -# asyncio:将事件放入一个队列中,通过对队列的循环实现事件的异步访问 - -# 协程实现计算平均数 -def get_avg(): - sum = 0 - num = 0 - while True: - # value = yield sum / num - try: - value = yield sum / num - except ZeroDivisionError: - value = yield 0 - sum += value - num += 1 - -my_avg = get_avg() -print(next(my_avg)) -print(my_avg.send(4)) -print(my_avg.send(12)) -# 0 -# 4.0 -# 8.0 - - - -# asyncio -import asyncio - -class Response: - ststus_code = 1 - -async def sim_request(index): - print(f"模拟发送请求 Index: {index}") - response = Response() - print("将休眠3秒") - await asyncio.sleep(3) - print(f"request index {index}, response status_code: {response.ststus_code}") - # 尝试返回一个递增列表 - return response.ststus_code+index - -loop = asyncio.get_event_loop() - -task_array = [] -for i in range(10): - print("在这里尝试打印") - task_array.append(sim_request(i)) - print("我又在这尝试打印") - -# loop.run_until_complete(asyncio.wait(task_array)) -result = loop.run_until_complete(asyncio.gather(*task_array)) -print(result) - +# 迭代器:一次只返回一个元素,省内存,只能自行通过调用next方法,才能返回值。 +# 迭代器中没有值后抛出的异常需要自行处理 + +# 生成器:特殊的迭代器,通过生成器可以实现函数的暂停。 +# yield:暂停并返回右边的值 + +# 协程:函数的实现依靠:send赋值,yield暂停并返回值 +# send->yield;send->yield;send->yield + +# asyncio:将事件放入一个队列中,通过对队列的循环实现事件的异步访问 + +# 协程实现计算平均数 +def get_avg(): + sum = 0 + num = 0 + while True: + # value = yield sum / num + try: + value = yield sum / num + except ZeroDivisionError: + value = yield 0 + sum += value + num += 1 + +my_avg = get_avg() +print(next(my_avg)) +print(my_avg.send(4)) +print(my_avg.send(12)) +# 0 +# 4.0 +# 8.0 + + + +# asyncio +import asyncio + +class Response: + ststus_code = 1 + +async def sim_request(index): + print(f"模拟发送请求 Index: {index}") + response = Response() + print("将休眠3秒") + await asyncio.sleep(3) + print(f"request index {index}, response status_code: {response.ststus_code}") + # 尝试返回一个递增列表 + return response.ststus_code+index + +loop = asyncio.get_event_loop() + +task_array = [] +for i in range(10): + print("在这里尝试打印") + task_array.append(sim_request(i)) + print("我又在这尝试打印") + +# loop.run_until_complete(asyncio.wait(task_array)) +result = loop.run_until_complete(asyncio.gather(*task_array)) +print(result) + loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/test.log" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/test.log" index 6e2f75e6a578fe84f1fd691aefd4efb806536098..358bd4227559b982302f650cd15f5a2a71be14bd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/test.log" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week5/test.log" @@ -1,5 +1,5 @@ -0 -2 -1 -3 -4 +0 +2 +1 +3 +4 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index 94344c020df09415d29949e9e840e1970c7bfedd..be0588a38fa66e6aefdbeca17af648c4d2c676ee 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,18 +1,18 @@ -# 第六周-第一节-作业提交 - -- 浏览器地址栏敲下url: - -输入域名后,先请求DNS服务器进行DNS解析,DNS服务器返回域名对应的IP地址,浏览器根据IP地址访问域名网站的服务器; - -然后客户端和服务器需要互相确认身份:客户端向服务端发送传递数据的请求,服务端处理请求并返回接收数据的结果,此时建立连接通道,开始传输数据; - -最后浏览器获取响应并根据响应渲染,用户才能正常浏览网站。 - - - -- 五层协议 - - 应用层:支持各种网络应用(FTP、SMTP、HTTP) - - 传输层:进程-进程的数据传输(TCP、UDP) - - 网络层:源主机到目的主机的数据分组路由与转发(IP、ICMP、OSPF) - - 数据链路层:把网络层传下的数据包封装成帧(PPP) +# 第六周-第一节-作业提交 + +- 浏览器地址栏敲下url: + +输入域名后,先请求DNS服务器进行DNS解析,DNS服务器返回域名对应的IP地址,浏览器根据IP地址访问域名网站的服务器; + +然后客户端和服务器需要互相确认身份:客户端向服务端发送传递数据的请求,服务端处理请求并返回接收数据的结果,此时建立连接通道,开始传输数据; + +最后浏览器获取响应并根据响应渲染,用户才能正常浏览网站。 + + + +- 五层协议 + - 应用层:支持各种网络应用(FTP、SMTP、HTTP) + - 传输层:进程-进程的数据传输(TCP、UDP) + - 网络层:源主机到目的主机的数据分组路由与转发(IP、ICMP、OSPF) + - 数据链路层:把网络层传下的数据包封装成帧(PPP) - 物理层:比特传输 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index d4dddff4f51f4f1d9096b55420082b230f76d979..bae3d0337d759cbec3409191b21c68b33a6cd1da 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,33 +1,33 @@ -# 第六周-第三节-作业提交 - -- fiddler抓包web - - - 信任证书 - - ![](./images/web信任证书.png) - - - web抓包 - - ![](./images/web抓包.png) - -- fiddler抓包app - - - app信任证书 - - ![](./images/app信任证书.png) - - - 手机代理指向fiddler - - ![](./images/手机代理指向fiddler.png) - - ![](./images/代理指向fiddler2.png) - - - app抓包 - - ![](./images/app抓包.png) - -- postman - - ![](./images/postman_get.png) - +# 第六周-第三节-作业提交 + +- fiddler抓包web + + - 信任证书 + + ![](./images/web信任证书.png) + + - web抓包 + + ![](./images/web抓包.png) + +- fiddler抓包app + + - app信任证书 + + ![](./images/app信任证书.png) + + - 手机代理指向fiddler + + ![](./images/手机代理指向fiddler.png) + + ![](./images/代理指向fiddler2.png) + + - app抓包 + + ![](./images/app抓包.png) + +- postman + + ![](./images/postman_get.png) + ![](./images/postman_post.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index f702d6bd64a5354ae1cd462a0df6d00b3775fcea..4b141d32c3a4769c74b7c25176b9c253f3db4570 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week6/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,48 +1,48 @@ -`在考研书上看到的比较容易理解的图示` - -`TCP/IP连接传输有三个阶段:连接建立-数据传送-连接释放` - -`三次握手为连接建立,四次挥手为连接释放` - -- TCP/IP三次握手 - - - ![image](./images/三次握手.png) - - - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 - - 服务端确认了客户端的发送能力正常:即图示中"有件事不知当讲不当讲" - - - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包 - - 服务端确认了自己接受能力是正常:即图示中"当讲,你说吧!" - - - 客户端向服务端返回带有`ACK`标识的数据包 - - 服务端确认了自己发送能力, 客户端接受正常:即图示中"好的!#¥%" - -- TCP/IP四次挥手 - - - ![image](./images/四次挥手.png) - - - 客户端向服务端发送了一个`FIN(finish)`数据包 - - 关闭客户端到服务端的连接通道:即图示中"我说完了。" - - - 服务端收到`FIN`后, 返回了`ACK`数据包 - - 服务端已经知道了客户端到服务端的连接通道已关闭:即图示中"好的。我想说……" - - - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接 - - 目的是关闭服务端到客户端的连接通道:即图示中"我说完了" - - - 客户端返回`ACK`数据包确认 - - 通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭:即图示中"好吧。" - -- HTTPS加密 - - 客户端向服务端发送通信请求 - - 服务端返回给客户端证书和密钥 - - 客户端通过CA中心验证证书的真实性 - - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端 +`在考研书上看到的比较容易理解的图示` + +`TCP/IP连接传输有三个阶段:连接建立-数据传送-连接释放` + +`三次握手为连接建立,四次挥手为连接释放` + +- TCP/IP三次握手 + + - ![image](./images/三次握手.png) + + - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 + + 服务端确认了客户端的发送能力正常:即图示中"有件事不知当讲不当讲" + + - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包 + + 服务端确认了自己接受能力是正常:即图示中"当讲,你说吧!" + + - 客户端向服务端返回带有`ACK`标识的数据包 + + 服务端确认了自己发送能力, 客户端接受正常:即图示中"好的!#¥%" + +- TCP/IP四次挥手 + + - ![image](./images/四次挥手.png) + + - 客户端向服务端发送了一个`FIN(finish)`数据包 + + 关闭客户端到服务端的连接通道:即图示中"我说完了。" + + - 服务端收到`FIN`后, 返回了`ACK`数据包 + + 服务端已经知道了客户端到服务端的连接通道已关闭:即图示中"好的。我想说……" + + - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接 + + 目的是关闭服务端到客户端的连接通道:即图示中"我说完了" + + - 客户端返回`ACK`数据包确认 + + 通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭:即图示中"好吧。" + +- HTTPS加密 + - 客户端向服务端发送通信请求 + - 服务端返回给客户端证书和密钥 + - 客户端通过CA中心验证证书的真实性 + - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端 - 服务端收到加密后的请求数据后, 使用私钥进行解密 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index f7ee4d77d58d36e06df8b7a86e7688cb2e4276fc..9e8966b24ecb848e1b4f42691beaac78b5f58419 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,37 +1,37 @@ -# 第七周-第一节-作业提交 - -- 关系型数据表: - - 创建在关系模型基础上的数据库,用来存储和管理结构化的数据。 - - 非关系型数据表: - - 创建在nosql系统存储基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据。 - - 区别: - - 非关系型数据库功能包含且不限于关系型数据库功能 - -- 事务: - - 事务的四个特性可以也可以认为是关系型数据库的特性 - - 事务的特点:原子性、一致性、隔离性、持久性 - - 原子性:对事务的操作只有两种状态(完成、不完成) - - 一致性:两件事务同时运行,无论哪个事务先结束,数据库都会达成一致 - - 隔离性:一个事务的执行不会被其他事务干扰 - - 持久性:一个事务一旦提交,它对数据库中数据的改变就应该是永久性的 - -- #### 完成Mysql服务端和Navicat的安装 - - ![](./images/MySQL.png) - - ![](./images/Navicat和MySQL连接.png) - -- #### 完成数据库和数据表的基础操作 - +# 第七周-第一节-作业提交 + +- 关系型数据表: + + 创建在关系模型基础上的数据库,用来存储和管理结构化的数据。 + + 非关系型数据表: + + 创建在nosql系统存储基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据。 + + 区别: + + 非关系型数据库功能包含且不限于关系型数据库功能 + +- 事务: + + 事务的四个特性可以也可以认为是关系型数据库的特性 + + 事务的特点:原子性、一致性、隔离性、持久性 + + 原子性:对事务的操作只有两种状态(完成、不完成) + + 一致性:两件事务同时运行,无论哪个事务先结束,数据库都会达成一致 + + 隔离性:一个事务的执行不会被其他事务干扰 + + 持久性:一个事务一旦提交,它对数据库中数据的改变就应该是永久性的 + +- #### 完成Mysql服务端和Navicat的安装 + + ![](./images/MySQL.png) + + ![](./images/Navicat和MySQL连接.png) + +- #### 完成数据库和数据表的基础操作 + ![](./images/数据库基本操作.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index d2099bb1f32b40ce4feb20a789b373b576ec61cf..1bac4c37fd146857c48670e2854f20314ea5714f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,70 +1,70 @@ -# 第七周-第三节-作业提交 - -- #### CRUD - -``` -insert into employees(id, name, department) values -(1, 'A', 'fiance'), -(2, 'B', 'engineering'), -(3, 'C', 'service'), -(4, 'D', 'fiance'), -(5, 'E', 'engineering'), -(6, 'F', 'service'); - -insert into hotel(id, name, room) values -(4, 'D', '101'), -(5, 'E', '102'), -(6, 'F', '201'), -(7, 'G', '202'), -(8, 'H', '301'), -(9, 'I', '302'); -``` - -![](./images/CRUD_1.png) - -![](./images/CRUD_2.png) - -``` -select * from employees; -select * from hotel where id > 6 order by id desc; -select name from employees where department = 'service' -select count(id) from employees where department like '%ce%' -select a.id, a.name, a.department, b.room from employees as a, hotel as b where a.id = b.id and a.name = b.name; -select * from hotel limit 3; -select distinct(department) from employees; -``` - -![](./images/CRUD_3.png) - -``` -update employees set department = 'Finance' where id = 1; -update employees set department = 'Finance' where id = 4; -``` - -![](./images/CRUD_4.png) - -- #### 集合 - -![](./images/集合1.png) - -![](./images/集合2.png) - -``` -select * from -(select id, name from employees where name is not NULL and id is not NULL) as a -left join -(select id, name from hotel where name is not NULL and id is not NULL) as b -on a.id =b.id -where b.name is NULL and b.id is NULL - -union - -select * from -(select id, name from employees where name is not NULL and id is not NULL) as a -right join -(select id, name from hotel where name is not NULL and id is not NULL) as b -on a.id =b.id -where a.name is NULL and a.id is NULL -``` - +# 第七周-第三节-作业提交 + +- #### CRUD + +``` +insert into employees(id, name, department) values +(1, 'A', 'fiance'), +(2, 'B', 'engineering'), +(3, 'C', 'service'), +(4, 'D', 'fiance'), +(5, 'E', 'engineering'), +(6, 'F', 'service'); + +insert into hotel(id, name, room) values +(4, 'D', '101'), +(5, 'E', '102'), +(6, 'F', '201'), +(7, 'G', '202'), +(8, 'H', '301'), +(9, 'I', '302'); +``` + +![](./images/CRUD_1.png) + +![](./images/CRUD_2.png) + +``` +select * from employees; +select * from hotel where id > 6 order by id desc; +select name from employees where department = 'service' +select count(id) from employees where department like '%ce%' +select a.id, a.name, a.department, b.room from employees as a, hotel as b where a.id = b.id and a.name = b.name; +select * from hotel limit 3; +select distinct(department) from employees; +``` + +![](./images/CRUD_3.png) + +``` +update employees set department = 'Finance' where id = 1; +update employees set department = 'Finance' where id = 4; +``` + +![](./images/CRUD_4.png) + +- #### 集合 + +![](./images/集合1.png) + +![](./images/集合2.png) + +``` +select * from +(select id, name from employees where name is not NULL and id is not NULL) as a +left join +(select id, name from hotel where name is not NULL and id is not NULL) as b +on a.id =b.id +where b.name is NULL and b.id is NULL + +union + +select * from +(select id, name from employees where name is not NULL and id is not NULL) as a +right join +(select id, name from hotel where name is not NULL and id is not NULL) as b +on a.id =b.id +where a.name is NULL and a.id is NULL +``` + ![](./images/集合3.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index d412055ec0e8f626943b26b998be490da91998a2..bf3e450cc53ff26aef3441b4fde27c520bd5ee85 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week7/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,5 +1,5 @@ -# 第七周-第二节-作业提交 - -![](./images/字段.png) - +# 第七周-第二节-作业提交 + +![](./images/字段.png) + ![](./images/插入值.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/lesson3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/lesson3.py" index e009784c5274719e12b01f8cb0ead6cdd36f0cd4..7e2fcd10fc7ad8a49ac4c969b74c27adb9257960 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/lesson3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/lesson3.py" @@ -1,82 +1,82 @@ -import pymysql -import random -import time -from week3.follow3 import clock_it_deco - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "", - "db": "week8" -} - -mysql_con = pymysql.connect(**MYSQL_CONF) - -mysql_cursor = mysql_con.cursor() - -@clock_it_deco -def insert_one(): - for i in range(10**2): - name = f"员工_{i}" - salary = format(random.uniform(10**3, 10**4), '.2f') - department = f"部门_{random.randint(1, 10)}" - e_day = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO employees_2(name, salary, department, e_day) - VALUES ('{name}', {salary}, '{department}', '{e_day}')""" - print(SQL) - mysql_cursor.execute(SQL) - - mysql_con.commit() - - - -@clock_it_deco -def insert_many(): - values = [] - for i in range(10**2): - name = f"员工_{i}" - salary = format(random.uniform(10**3, 10**4), '.2f') - department = f"部门_{random.randint(1, 10)}" - e_day = time.strftime("%Y-%m-%d") - values.append((name, salary, department, e_day)) - - SQL = """INSERT INTO employees_3(name, salary, department, e_day) - VALUES (%s, %s, %s, %s)""" - print(values) - mysql_cursor.executemany(SQL, values) - mysql_con.commit() - - - -def get_shops(): - SQL = "SELECT name, salary, e_day from employees_2 where department='部门_1' " - mysql_cursor.execute(SQL) - # 获取返回值 - query_set = mysql_cursor.fetchall() - print(query_set) - - - -def transaction(): - try: - SQL = "DELETE FROM employees_2 where name='员工_13'" - mysql_cursor.execute(SQL) - SQL_2 = "INSERT INTO employees_2 VALUES(name)" - mysql_cursor.execute(SQL_2) - - except Exception as e: - print("raise Exceptions", e.args[0]) - print("rollback") - mysql_con.rollback() - finally: - mysql_con.commit() - - - - -if __name__ == '__main__': - # insert_one() - # insert_many() - # get_shops() +import pymysql +import random +import time +from week3.follow3 import clock_it_deco + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "", + "db": "week8" +} + +mysql_con = pymysql.connect(**MYSQL_CONF) + +mysql_cursor = mysql_con.cursor() + +@clock_it_deco +def insert_one(): + for i in range(10**2): + name = f"员工_{i}" + salary = format(random.uniform(10**3, 10**4), '.2f') + department = f"部门_{random.randint(1, 10)}" + e_day = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO employees_2(name, salary, department, e_day) + VALUES ('{name}', {salary}, '{department}', '{e_day}')""" + print(SQL) + mysql_cursor.execute(SQL) + + mysql_con.commit() + + + +@clock_it_deco +def insert_many(): + values = [] + for i in range(10**2): + name = f"员工_{i}" + salary = format(random.uniform(10**3, 10**4), '.2f') + department = f"部门_{random.randint(1, 10)}" + e_day = time.strftime("%Y-%m-%d") + values.append((name, salary, department, e_day)) + + SQL = """INSERT INTO employees_3(name, salary, department, e_day) + VALUES (%s, %s, %s, %s)""" + print(values) + mysql_cursor.executemany(SQL, values) + mysql_con.commit() + + + +def get_shops(): + SQL = "SELECT name, salary, e_day from employees_2 where department='部门_1' " + mysql_cursor.execute(SQL) + # 获取返回值 + query_set = mysql_cursor.fetchall() + print(query_set) + + + +def transaction(): + try: + SQL = "DELETE FROM employees_2 where name='员工_13'" + mysql_cursor.execute(SQL) + SQL_2 = "INSERT INTO employees_2 VALUES(name)" + mysql_cursor.execute(SQL_2) + + except Exception as e: + print("raise Exceptions", e.args[0]) + print("rollback") + mysql_con.rollback() + finally: + mysql_con.commit() + + + + +if __name__ == '__main__': + # insert_one() + # insert_many() + # get_shops() transaction() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index 9811dc662645915152d3c0efbbfbd3adb445dbf3..141abe5a4aee7ef1dfdf59659e90e67445cbec46 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,47 +1,47 @@ -# 第八周-第一节-作业提交 - -- ### MySQL约束 - - - ##### primary key - - 不能为空,不可重复, - - ![](./images/主键.png) - - - ##### NOT NULL - - ![](./images/NOTNULL.png) - - - ##### default - - ![](./images/default.png) - -- ### 分组查询 - - ``` - INSERT INTO employees(id, name, salary, department, working_year) VALUES - (1,'A',5000,'service',1.0), - (2,'B',5500,'service',1.5), - (3,'C',10000,'engineering',3.5), - (4,'D',7000,'finance',0.5), - (5,'E',8000,'engineering',2.0), - (6,'F',6000,'service',2.0), - (7,'G',15000,'finance',10.0), - (8,'H',20000,'engineering',8.0); - ``` - - ![](./images/employees.png) - -``` -SELECT department AS 部门, -COUNT(*) AS 部门人数, -FORMAT(AVG(salary),2) AS 平均薪资, -FORMAT(AVG(working_year),2) AS 平均工作年限, -SUM(salary) AS 整体薪资水平, -MAX(salary) AS 最高薪资, -MIN(salary) AS 最低薪资 -FROM employees -GROUP BY department; -``` - +# 第八周-第一节-作业提交 + +- ### MySQL约束 + + - ##### primary key + + 不能为空,不可重复, + + ![](./images/主键.png) + + - ##### NOT NULL + + ![](./images/NOTNULL.png) + + - ##### default + + ![](./images/default.png) + +- ### 分组查询 + + ``` + INSERT INTO employees(id, name, salary, department, working_year) VALUES + (1,'A',5000,'service',1.0), + (2,'B',5500,'service',1.5), + (3,'C',10000,'engineering',3.5), + (4,'D',7000,'finance',0.5), + (5,'E',8000,'engineering',2.0), + (6,'F',6000,'service',2.0), + (7,'G',15000,'finance',10.0), + (8,'H',20000,'engineering',8.0); + ``` + + ![](./images/employees.png) + +``` +SELECT department AS 部门, +COUNT(*) AS 部门人数, +FORMAT(AVG(salary),2) AS 平均薪资, +FORMAT(AVG(working_year),2) AS 平均工作年限, +SUM(salary) AS 整体薪资水平, +MAX(salary) AS 最高薪资, +MIN(salary) AS 最低薪资 +FROM employees +GROUP BY department; +``` + ![](./images/分组查询.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" index bb40fcc203fe9e404863434ba6ac11832bfd8941..a36536c9e08f846c1da936df67dabb0a78366919 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week8/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244.md" @@ -1,53 +1,53 @@ -# 第八周-第二节-作业提交 - -- 用户变量 - - ``` - SET @yesterday = DATE_FORMAT(SUBDATE(CURRENT_DATE,1),"%Y/%m/%d"); - SELECT @yesterday; - ``` - -![](./images/8-2-1.png) - -- 存储过程 - - ``` - CREATE PROCEDURE employees(days INT) - BEGIN - DECLARE t_date VARCHAR(255); - SET t_date = DATE_FORMAT(SUBDATE(CURRENT_DATE,1),"%Y/%m/%d"); - SELECT department AS 部门, - COUNT(*) AS 部门人数, - FORMAT(AVG(salary),2) AS 平均薪资, - FORMAT(AVG(working_year),2) AS 平均工作年限, - SUM(salary) AS 整体薪资水平, - MAX(salary) AS 最高薪资, - MIN(salary) AS 最低薪资 - FROM employees - WHERE e_day = t_date - GROUP BY department; - END - ``` - - ![](./images/8-2-2.png) - -- 触发器 - - ``` - CREATE TRIGGER check_dep - BEFORE INSERT - ON employees - FOR EACH ROW - BEGIN - IF new.department NOT IN ('finance', 'sevice', 'engineering') THEN - SET new.department = 'unknow'; - END IF; - END - ``` - - ``` - INSERT INTO employees(id, name, salary, department, working_year,e_day) VALUES (9,'I',15000,'digital',5.0,'2021/02/05') - ``` - - ![](./images/8-2-3.png) - +# 第八周-第二节-作业提交 + +- 用户变量 + + ``` + SET @yesterday = DATE_FORMAT(SUBDATE(CURRENT_DATE,1),"%Y/%m/%d"); + SELECT @yesterday; + ``` + +![](./images/8-2-1.png) + +- 存储过程 + + ``` + CREATE PROCEDURE employees(days INT) + BEGIN + DECLARE t_date VARCHAR(255); + SET t_date = DATE_FORMAT(SUBDATE(CURRENT_DATE,1),"%Y/%m/%d"); + SELECT department AS 部门, + COUNT(*) AS 部门人数, + FORMAT(AVG(salary),2) AS 平均薪资, + FORMAT(AVG(working_year),2) AS 平均工作年限, + SUM(salary) AS 整体薪资水平, + MAX(salary) AS 最高薪资, + MIN(salary) AS 最低薪资 + FROM employees + WHERE e_day = t_date + GROUP BY department; + END + ``` + + ![](./images/8-2-2.png) + +- 触发器 + + ``` + CREATE TRIGGER check_dep + BEFORE INSERT + ON employees + FOR EACH ROW + BEGIN + IF new.department NOT IN ('finance', 'sevice', 'engineering') THEN + SET new.department = 'unknow'; + END IF; + END + ``` + + ``` + INSERT INTO employees(id, name, salary, department, working_year,e_day) VALUES (9,'I',15000,'digital',5.0,'2021/02/05') + ``` + + ![](./images/8-2-3.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson1.py" index dd43932bb3dbb601737ed50c6179629a0ff98ef4..6d99bc9ef5aca1fa2dc444df1f8f6f9324e2598a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson1.py" @@ -1,21 +1,21 @@ -import requests - -def request_jd(keyword): - url = "https://item.jd.com/100017744916.html" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.81" - } - response = requests.get(url=url, params=params, headers=headers) - - output = open("detail_10.html", "w", encoding="utf-8") - content = response.text - output.write(content) - output.close() - - - -if __name__ == '__main__': - request_jd("手机") +import requests + +def request_jd(keyword): + url = "https://item.jd.com/100017744916.html" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.81" + } + response = requests.get(url=url, params=params, headers=headers) + + output = open("detail_10.html", "w", encoding="utf-8") + content = response.text + output.write(content) + output.close() + + + +if __name__ == '__main__': + request_jd("手机") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson2.py" index b98753067cb9a78883e6d557eb8c6ca8f404a1d8..ab2bee335e1ce088da72d4dd2f42bc63d1de394e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson2.py" @@ -1,24 +1,24 @@ -from bs4 import BeautifulSoup - - -def jd_search_parse(html): - html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") - soup = BeautifulSoup(html, "lxml") - item = soup.select("li[data-sku='6027207']")[0] - # item = soup.select("li[data-sku^='2']")[0] - print(item.text) - - # 下一个结点 - # print(item.next_sibling) - - # 父节点 - # print(item.parent) - - # 子节点 - # print(item.children) - - -if __name__ == '__main__': - with open("jd_search.html", "r", encoding="utf-8") as f: - html = f.read() - jd_search_parse(html) +from bs4 import BeautifulSoup + + +def jd_search_parse(html): + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='6027207']")[0] + # item = soup.select("li[data-sku^='2']")[0] + print(item.text) + + # 下一个结点 + # print(item.next_sibling) + + # 父节点 + # print(item.parent) + + # 子节点 + # print(item.children) + + +if __name__ == '__main__': + with open("jd_search.html", "r", encoding="utf-8") as f: + html = f.read() + jd_search_parse(html) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/main.py" index 444c439a382e9771b450a0be0fd4f80de8750764..52ad5b6f6c0b27c77acb73a34f3ead3c6615a942 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/main.py" @@ -1,37 +1,37 @@ -import random -import pymysql -import requests -from jd_crawler.parser.search import parse_jd_item -from jd_crawler.settings import MYSQL_CONF, HEADERS - -def saver(item_array): - cursor = mysql_con.cursor() - SQL = """insert into jd_search(sku_id, img, price, title, shop, icons) values (%s, %s, %s , %s, %s, %s)""" - cursor.executemany(SQL, item_array) - mysql_con.commit() - cursor.close() - - - -def downloader(task): - url = "https://search.jd.com/Search" - params = { - "keyword": task - } - res = requests.get(url=url, params=params, headers=HEADERS) - return res - - -def main(task_array): - for task in task_array: - result = downloader(task) - item_array = parse_jd_item(result.text) - - print("GET ITEMS", item_array) - saver(item_array) - - -if __name__ == "__main__": - mysql_con = pymysql.connect(**MYSQL_CONF) - task_array = ["鼠标", "键盘", "显卡", "耳机"] +import random +import pymysql +import requests +from jd_crawler.parser.search import parse_jd_item +from jd_crawler.settings import MYSQL_CONF, HEADERS + +def saver(item_array): + cursor = mysql_con.cursor() + SQL = """insert into jd_search(sku_id, img, price, title, shop, icons) values (%s, %s, %s , %s, %s, %s)""" + cursor.executemany(SQL, item_array) + mysql_con.commit() + cursor.close() + + + +def downloader(task): + url = "https://search.jd.com/Search" + params = { + "keyword": task + } + res = requests.get(url=url, params=params, headers=HEADERS) + return res + + +def main(task_array): + for task in task_array: + result = downloader(task) + item_array = parse_jd_item(result.text) + + print("GET ITEMS", item_array) + saver(item_array) + + +if __name__ == "__main__": + mysql_con = pymysql.connect(**MYSQL_CONF) + task_array = ["鼠标", "键盘", "显卡", "耳机"] main(task_array) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/search.py" index 1ea4501ebf7321b1b84b1c50f6a1c6a636675947..a3c5237029c5a4864cb79e9ba9412c7a1dd5519f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/search.py" @@ -1,35 +1,35 @@ -from bs4 import BeautifulSoup -import json - -def parse_jd_item(html): - result = [] - soup = BeautifulSoup(html, "lxml") - item_array = soup.select("ul[class = 'gl-warp clearfix'] li[class='gl-item']") - - for item in item_array: - try: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else "" - - result.append((sku_id, img, price, title, shop, icons)) - - except Exception as e: - print(e.args) - return result - - -if __name__ == "__main__": - with open("../test/search.html", "r", encoding="utf-8") as f: - html = f.read() - result = parse_jd_item(html) +from bs4 import BeautifulSoup +import json + +def parse_jd_item(html): + result = [] + soup = BeautifulSoup(html, "lxml") + item_array = soup.select("ul[class = 'gl-warp clearfix'] li[class='gl-item']") + + for item in item_array: + try: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else "" + + result.append((sku_id, img, price, title, shop, icons)) + + except Exception as e: + print(e.args) + return result + + +if __name__ == "__main__": + with open("../test/search.html", "r", encoding="utf-8") as f: + html = f.read() + result = parse_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/settings.py" index c45990433fd6e52542feb23a2eb9b8499d8fcc5a..7105b68ecd986088624ebce9f515cfef71f65828 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week9/lesson3/settings.py" @@ -1,12 +1,12 @@ -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.81", - "upgrade-insecure-requests": "1" -} - - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "xmt66237029", - "db": "week9" +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.81", + "upgrade-insecure-requests": "1" +} + + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "xmt66237029", + "db": "week9" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/lesson_1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/lesson_1.py" index a6d54a2984953c8dad44f2dcf70da509948499dd..f3d1328033f4931a2d71c1bafcc28c16696786f4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/lesson_1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/lesson_1.py" @@ -1,40 +1,40 @@ -# 四大基本数据结构中哪些是可变的, 哪些是不可变的? -# -# 可变的:列表list,字典dict,集合set -# 不可以变的:元组tuple -# - -# 四大基本数据结构中哪些是有序的, 哪些是无序的? -# -# 有序的:list,tupe -# 无序的:dict,set -# -# 创建set, list, dict, tuple实例, 每个数据结构的实例需要包括六大基本类型. -# -# 六大基本类型:int,float,bytes,str,boolean,None -from encodings.utf_8 import encode - -print(type(7)) -print(type(2.0)) -print(type('3'.encode("utf-8"))) -print(type('str')) -a=bool(1) -print(a,type(a)) -print(type(None)) - -print("=====22========") -# 基本数据类型 -a=int(7) -b=float(2.0) -c=str('77') -d=bytes('python'.encode("utf-8")) -e=bool(0) -f=None -alist=[a,b,c,d,f] -atuple=(a,b,c,d,f) -adict={'1':a,'2':b,'3':c,'4':d,'5':f} -aset=set([a,b,c,d,e,f]) -print("列表alist:",alist) -print("元组atuple:",atuple) -print("字典adict:",adict) +# 四大基本数据结构中哪些是可变的, 哪些是不可变的? +# +# 可变的:列表list,字典dict,集合set +# 不可以变的:元组tuple +# + +# 四大基本数据结构中哪些是有序的, 哪些是无序的? +# +# 有序的:list,tupe +# 无序的:dict,set +# +# 创建set, list, dict, tuple实例, 每个数据结构的实例需要包括六大基本类型. +# +# 六大基本类型:int,float,bytes,str,boolean,None +from encodings.utf_8 import encode + +print(type(7)) +print(type(2.0)) +print(type('3'.encode("utf-8"))) +print(type('str')) +a=bool(1) +print(a,type(a)) +print(type(None)) + +print("=====22========") +# 基本数据类型 +a=int(7) +b=float(2.0) +c=str('77') +d=bytes('python'.encode("utf-8")) +e=bool(0) +f=None +alist=[a,b,c,d,f] +atuple=(a,b,c,d,f) +adict={'1':a,'2':b,'3':c,'4':d,'5':f} +aset=set([a,b,c,d,e,f]) +print("列表alist:",alist) +print("元组atuple:",atuple) +print("字典adict:",adict) print("集合aset:",aset) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202.md" index 7e6356387c642b6d8bd19c679932ba17939dccab..d6a929b8e91f94278699cf22ef3189b4a09ec7c0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202.md" @@ -1,138 +1,138 @@ -# 第一周-第一节 - -## 养成来哦好的编程习惯 - -- 不要相信自己的记忆力,做好笔记和文档 - - - typora - - ``` - https://typora.io/ - ``` - - - - - 创建标题 - - ``` - ctrl + 数字 - ``` - - - 创建目录列表结构 - - ``` - - + 空格 - ``` - - - 創建代码块 - - ``` - Ctrl+shift+k - ``` - -- 科学的使用搜索习惯 - - - 官方文档和GitHub库 - - ``` - https://docs.python.org/zh-cn/3.6/ - https://github.com/ - ``` - - - stackoverflow(英语比较好的可以用) - - ``` - https://stackoverflow.com/ - ``` - - - 简书和知乎 - - - 百度搜索 - -- 良好的学习心态 - - 面向需求学习 - - 有效率地学习 - - 自己思索10分钟 - - 不要担心自己的问题太小白,要及时的询问 - - 尽量在大群中讨论 - -## 编程语言的基本概述 - -- 什么是编程语言? - - 相对于人与人之间的沟通,编程语言是人与计算机交互的媒介 - -- 代码的执行流程 - - 代码 -> 机器码 -> 由计算机处理器来执行 - - - 把代码翻译成为机器的翻译就是编译器,在Python中也可以叫做Python解释器 - - 编程语言Python是我们与解释器之间的翻译 - - 解释器是Python与计算机之间的翻译 - -- 编程语言分类 - - ``` - C - C++ - Java - Python - JavaScript - ``` - - - 编译型语言、解释性语言和混合型语言 - - 动态语言和静态语言 - - 请类型语言和弱类型语言 - -- 什么是动态语言和静态语言 - - 编译时不知道变量是什么类型的语言叫动态语言 - - - 动态语言 - - Python - - JavaScript - - 静态语言 - - C - - C++ - - Java - -- 什么是强类型语言与弱类型语言 - - 在使用变量时不会自动改变变量的类型 ,反之,弱类型语言会隐式的转换变量类型 - - - 弱类型语言 - - JavaScript - - 强类型语言 - - Python - - Java - - C - - C++ - -## Python环境搭建 - -- Python下载安装(记住自己的安装目录) - - 环境变量配置 - - IDE的下载与安装 - -## 运行我们的第一个Python程序 - -- 使用pycharm新建第一个程序(新建项目确认安装路径/ D:\python\pythonProject ) - -- 运行第一个程序 - -- 可能遇到的问题 - - - Python无法运行,通过自定义位置解决 - - 单双引号不能混用(中英双引号混用) - - 注意:缩进,空格和tab键(缩进一般用tab键) - - - - - - - - - - - +# 第一周-第一节 + +## 养成来哦好的编程习惯 + +- 不要相信自己的记忆力,做好笔记和文档 + + - typora + + ``` + https://typora.io/ + ``` + + + + - 创建标题 + + ``` + ctrl + 数字 + ``` + + - 创建目录列表结构 + + ``` + - + 空格 + ``` + + - 創建代码块 + + ``` + Ctrl+shift+k + ``` + +- 科学的使用搜索习惯 + + - 官方文档和GitHub库 + + ``` + https://docs.python.org/zh-cn/3.6/ + https://github.com/ + ``` + + - stackoverflow(英语比较好的可以用) + + ``` + https://stackoverflow.com/ + ``` + + - 简书和知乎 + + - 百度搜索 + +- 良好的学习心态 + - 面向需求学习 + - 有效率地学习 + - 自己思索10分钟 + - 不要担心自己的问题太小白,要及时的询问 + - 尽量在大群中讨论 + +## 编程语言的基本概述 + +- 什么是编程语言? + + 相对于人与人之间的沟通,编程语言是人与计算机交互的媒介 + +- 代码的执行流程 + + 代码 -> 机器码 -> 由计算机处理器来执行 + + - 把代码翻译成为机器的翻译就是编译器,在Python中也可以叫做Python解释器 + - 编程语言Python是我们与解释器之间的翻译 + - 解释器是Python与计算机之间的翻译 + +- 编程语言分类 + + ``` + C + C++ + Java + Python + JavaScript + ``` + + - 编译型语言、解释性语言和混合型语言 + - 动态语言和静态语言 + - 请类型语言和弱类型语言 + +- 什么是动态语言和静态语言 + + 编译时不知道变量是什么类型的语言叫动态语言 + + - 动态语言 + - Python + - JavaScript + - 静态语言 + - C + - C++ + - Java + +- 什么是强类型语言与弱类型语言 + + 在使用变量时不会自动改变变量的类型 ,反之,弱类型语言会隐式的转换变量类型 + + - 弱类型语言 + - JavaScript + - 强类型语言 + - Python + - Java + - C + - C++ + +## Python环境搭建 + +- Python下载安装(记住自己的安装目录) + - 环境变量配置 + - IDE的下载与安装 + +## 运行我们的第一个Python程序 + +- 使用pycharm新建第一个程序(新建项目确认安装路径/ D:\python\pythonProject ) + +- 运行第一个程序 + +- 可能遇到的问题 + + - Python无法运行,通过自定义位置解决 + - 单双引号不能混用(中英双引号混用) + - 注意:缩进,空格和tab键(缩进一般用tab键) + + + + + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.md" index eec3c6c7698592334fcffab78918e4d4ada2153f..3f610e65123b593ff066c7f559991612b0eb82c3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week1/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232.md" @@ -1,6 +1,6 @@ -1.新建仓库提交到码云 -https://gitee.com/nilive/git_test -2.新建虚拟环境 - -![虚拟环境](https://gitee.com/nilive/git_test/blob/master/images/%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83.png) - +1.新建仓库提交到码云 +https://gitee.com/nilive/git_test +2.新建虚拟环境 + +![虚拟环境](https://gitee.com/nilive/git_test/blob/master/images/%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/my_calculator.py" index 83bc4132ddf152ef650126e89f03e78bc5b945c6..3dd004ee007b9df0bb3118c0c4e46fdca14bd4a1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/my_calculator.py" @@ -1,57 +1,57 @@ -''' -用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 - -my_calculator.py - -def add(a, b): - -def sqrt(a, b): - -''' -def add(a,b): - return a + b ; -def sub(a,b): - return a - b; -def mul(a,b): - return a * b; -def div(a,b): - if b != 0: - return a / b; - else: - return "除数不能为零!!!" -def rem(a,b): - return a // b; -def ediv(a,b): - return a % b; -def sqrt(a): - c = int(a) - if c>=0: - return c ** (1/2); - else: - return "开方数不能小于零?"; -c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%:") -# input3 = input("请输入你要开方的数,如果不是进行开方运算请按回车键") - -if c == '%%': - a = float(input("请输入你要开方的数:")) - print(a,"^(1/2)","=",sqrt(a)) -else: - a = float(input("请输入你要运算的第一个数:")) - b = float(input("请输入你要运算的第二个数:")) - # c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%") - if c == '+': - print(a,"+",b,"=",add(a,b)) - elif c == '-': - print(a,"-",b,"=",sub(a,b)) - elif c == '*': - print(a,"*",b,"=",mul(a,b)) - elif c == '-': - print(a,"/",b,"=",div(a,b)) - elif c == '-': - print(a,"//",b,"=",ediv(a,b)) - elif c == '-': - print(a,"%",b,"=",rem(a,b)) - elif c == '-': - print(a,"^(1/2)",b,"=",sqrt(a,b)) - else : - print("请输入正确的运算?") +''' +用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 + +my_calculator.py + +def add(a, b): + +def sqrt(a, b): + +''' +def add(a,b): + return a + b ; +def sub(a,b): + return a - b; +def mul(a,b): + return a * b; +def div(a,b): + if b != 0: + return a / b; + else: + return "除数不能为零!!!" +def rem(a,b): + return a // b; +def ediv(a,b): + return a % b; +def sqrt(a): + c = int(a) + if c>=0: + return c ** (1/2); + else: + return "开方数不能小于零?"; +c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%:") +# input3 = input("请输入你要开方的数,如果不是进行开方运算请按回车键") + +if c == '%%': + a = float(input("请输入你要开方的数:")) + print(a,"^(1/2)","=",sqrt(a)) +else: + a = float(input("请输入你要运算的第一个数:")) + b = float(input("请输入你要运算的第二个数:")) + # c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%") + if c == '+': + print(a,"+",b,"=",add(a,b)) + elif c == '-': + print(a,"-",b,"=",sub(a,b)) + elif c == '*': + print(a,"*",b,"=",mul(a,b)) + elif c == '-': + print(a,"/",b,"=",div(a,b)) + elif c == '-': + print(a,"//",b,"=",ediv(a,b)) + elif c == '-': + print(a,"%",b,"=",rem(a,b)) + elif c == '-': + print(a,"^(1/2)",b,"=",sqrt(a,b)) + else : + print("请输入正确的运算?") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/second_word.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/second_word.py" index 3d50c98ce9831d291346094980d8a74d79834e37..4640384ac92798bba55ad716990061504406ef49 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/second_word.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/second_word.py" @@ -1,110 +1,110 @@ -''' -- 字符串(字符序列)和字节序列 - - 字符Unicode - - 字节 字符的二进制表现形式 - - - - - - 码位与编码区别:(b')表二进制的意思 - + b = '您好'.encode("utf-8") - + b'\xe6\x82\xa8\xe5\xa5\xbd' - = b1 = '您好'.encode("utf-8") + '啊'.encode('gbk') - + b1.decode("utf-8",errors='ignore') - + b1.decode("utf-8",errors='replace') - - -- 字符串CURD操作 - create: - a = 'ab' - > 'ab' - - retrieve: - - a.find("a") - > 0 - a.find("b") - > 1 - a.find("c") - > -1 - a.index("a") - > 0 - a.index("c") - Traceback (most recent call last): - File "", line 1, in - ValueError: substring not found - update: - - > a - 'ab' - > a.replace("b","c") - 'ac' - - > a = "Python,Java,c++" - > a.split(",") - ['Python', 'Java', 'c++'] - > a - 'Python,Java,c++' - > b = a.split(",") - > b - ['Python', 'Java', 'c++'] - > a - 'Python,Java,c++' - > ",".join(b) - 'Python,Java,c++' - - delete: - - > a = " Java " - > a - ' Java ' - > a.strip() - 'Java' - a.rstrip() #把右侧的空格都消掉 - a.lstrip() #把左侧的空格都消掉 - -- 练习字符串的格式化 - > a = "Python" - > b = "learn" - > print("I {0} {1}".format(a,b)) - I Python learn - > print("I {0} {1}".format(b,a)) - I learn Python - ·按传入参数默认顺序 - > print("I {} {}".format(b,a)) - I learn Python - ·按指定参数索引 - > print("I {0} {1}".format(b,a)) - I learn Python - > print("I {0}{0} {1}".format(b,a)) - I learnlearn Python - ·按关键词参数 - > print("I {a} {b}".format(a = 'am',b = 'studying')) - I am studying - 按变量 - > print(f"I am learning: {a}, {b}") - I am learning: Python, learn - ·小数的表示 - > " "{:.3f}".format(3.1415926) - '3.142' - ·% - > "learning %s %s" % ("Python", "Java") - 'learning Python Java' - - - -''' - -# 字符串 - -''' -output = open("output.txt","w",encoding="utf-8") -content = "Hello, Python" -# 正式写入文件 -output.write(content) -# 关闭文件语句 -output.close() -''' -input = open("output.txt","r",encoding="utf-8") -# 获取文件中的内容 -content = input.read() -print(content) - +''' +- 字符串(字符序列)和字节序列 + - 字符Unicode + - 字节 字符的二进制表现形式 + - + - + - 码位与编码区别:(b')表二进制的意思 + + b = '您好'.encode("utf-8") + + b'\xe6\x82\xa8\xe5\xa5\xbd' + = b1 = '您好'.encode("utf-8") + '啊'.encode('gbk') + + b1.decode("utf-8",errors='ignore') + + b1.decode("utf-8",errors='replace') + + +- 字符串CURD操作 + create: + a = 'ab' + > 'ab' + + retrieve: + + a.find("a") + > 0 + a.find("b") + > 1 + a.find("c") + > -1 + a.index("a") + > 0 + a.index("c") + Traceback (most recent call last): + File "", line 1, in + ValueError: substring not found + update: + + > a + 'ab' + > a.replace("b","c") + 'ac' + + > a = "Python,Java,c++" + > a.split(",") + ['Python', 'Java', 'c++'] + > a + 'Python,Java,c++' + > b = a.split(",") + > b + ['Python', 'Java', 'c++'] + > a + 'Python,Java,c++' + > ",".join(b) + 'Python,Java,c++' + + delete: + + > a = " Java " + > a + ' Java ' + > a.strip() + 'Java' + a.rstrip() #把右侧的空格都消掉 + a.lstrip() #把左侧的空格都消掉 + +- 练习字符串的格式化 + > a = "Python" + > b = "learn" + > print("I {0} {1}".format(a,b)) + I Python learn + > print("I {0} {1}".format(b,a)) + I learn Python + ·按传入参数默认顺序 + > print("I {} {}".format(b,a)) + I learn Python + ·按指定参数索引 + > print("I {0} {1}".format(b,a)) + I learn Python + > print("I {0}{0} {1}".format(b,a)) + I learnlearn Python + ·按关键词参数 + > print("I {a} {b}".format(a = 'am',b = 'studying')) + I am studying + 按变量 + > print(f"I am learning: {a}, {b}") + I am learning: Python, learn + ·小数的表示 + > " "{:.3f}".format(3.1415926) + '3.142' + ·% + > "learning %s %s" % ("Python", "Java") + 'learning Python Java' + + + +''' + +# 字符串 + +''' +output = open("output.txt","w",encoding="utf-8") +content = "Hello, Python" +# 正式写入文件 +output.write(content) +# 关闭文件语句 +output.close() +''' +input = open("output.txt","r",encoding="utf-8") +# 获取文件中的内容 +content = input.read() +print(content) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" index 89d09ecd328330b4faeef415d58c7112f7373d6a..b7da4d6b16c48124f10b1a97f2729fd4e46930ea 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week2/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,569 +1,569 @@ -# 第二周-第三节课作业 - -## 基础数据结构的CRUD操作 - -- List(列表) - - **list中存的元素是引用** - - - create(增加) - - - append - - 末尾添加元素 - - ``` - >>> a = [] - >>> id(a) - 22164744 - >>> a - [] - >>> a.append("a") - >>> a - ['a'] - >>> id(a) - 22164744 - >>> a.append("b") - >>> a - ['a', 'b'] - >>> id(a) - 22164744 - ``` - - - `+` 和`+=` - - - `+` - - 拼接两个列表, 然后返回一个新列表 - - ``` - >>> b - ['A'] - >>> id(b) - 51858888 - >>> b = b+a - >>> b - ['A', 'a', 'b', 'A'] - >>> id(b) - 51858928 - ``` - - - `+=` - - ``` - >>> a - ['a', 'b'] - >>> id(a) - 22164744 - >>> b = ["A"] - >>> b - ['A'] - >>> a += b - >>> a - ['a', 'b', 'A'] - >>> id(a) - 22164744 - ``` - - - `*`和`*=` - - ``` - >>> a - ['a', 'b', 'A'] - >>> id(a) - 22164744 - >>> a = a * 3 - >>> a - ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b', 'A'] - >>> id(a) - 51858888 - ··· 赋值语句之后, a是一个新的对象了 - ``` - - - insert - - 指定位置添加元素 - - ``` - >>> b - ['A', 'a', 'b', 'A'] - >>> b.insert(1,'B') - >>> b - ['A', 'B', 'a', 'b', 'A'] - >>> b.insert(10,'AB') - >>> b - ['A', 'B', 'a', 'b', 'A', 'AB'] - ``` - - - Retrieve(检索) - - - 索引取值 - - 所有序列都支持索引取值 - - ``` - >>> b - ['A', 'B', 'a', 'b', 'A', 'AB'] - >>> - >>> b[2] - 'a' - >>> b[10] - Traceback (most recent call last): - File "", line 1, in - IndexError: list index out of range - ``` - - - 切片 - - ``` - >>> l = list(range(100)) - >>> l - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 - 6, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3 - 0, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 4 - 4, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 5 - 8, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 7 - 2, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 8 - 6, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] - - # 取一段区间 - >>> l[0:10] - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - - >>> l[20:10] - [] - - >>> l[20:25] - [20, 21, 22, 23, 24] - - # 取最后一个值 - >>> l[-1] - 99 - - # 间隔问题 - >>> l[::3] - [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, - 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, - 87, 90, 93, 96, 99] - - >>> l[::10] - [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] - >>> l[2:15:3] - - [2, 5, 8, 11, 14] - >>> l[0:15:3] - - [0, 3, 6, 9, 12] - >>> l[0:15:5] - [0, 5, 10] - ``` - - - index - - ``` - >>> l = ['a','b','c'] - >>> l - ['a', 'b', 'c'] - >>> l.index(2) - Traceback (most recent call last): - File "", line 1, in - ValueError: 2 is not in list - >>> l.index('c') - 2 - ``` - - - Update(更新) - - - 索引赋值 - - ``` - >>> l - ['a', 'b', 'c'] - >>> id(l) - 51892392 - >>> l[1] = "B" - >>> l - ['a', 'B', 'c'] - >>> id(l) - 51892392 - #不改变地址 - ``` - - - 切片赋值 - - ``` - >>> l - ['a_1', 'a_2', 'b', 'c'] - >>> l[0:2] = "a" - >>> l - ['a', 'b', 'c'] - >>> l[0:2] = 1 - ``` - - - DELETE(删除) - - - pop() - - 从末尾删除元素并返回 - - ``` - >>> a - ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b', 'A'] - >>> a.pop() - 'A' - >>> a - ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b'] - ``` - - - clear() - - 清楚当前列表的元素, 不会改变列表的内存地址. - - ``` - >>> l - ['A', 'c'] - >>> l.clear() - >>> l - [] - ``` - - - - - ★SORT(排序) - - - sort() - - ``` - >>> l = [1,7,5,3] - >>> l - [1, 7, 5, 3] - >>> id(l) - 51892392 - >>> l.sort() - >>> l - [1, 3, 5, 7] - >>> id(l) - 51892392 - ``` - - - sorted - - 排序后返回新列表 - - ``` - >>> l = [1,7,5,3] - >>> l - [1, 7, 5, 3] - >>> id(l) - 51859408 - >>> l = sorted(l) - >>> l - [1, 3, 5, 7] - >>> id(l) - 51892392 - ``` - - - reverse - - ``` - >>> l2 - [1, 2, 3, 4, 6] - >>> l2.reverse() - >>> l2 - [6, 4, 3, 2, 1] - ``` - - - reversed - - 倒序之后返回新列表 - - ``` - >>> l - [1, 3, 2, 6, 4] - >>> list(reversed(l)) - [4, 6, 2, 3, 1] - ``` - -- tuple - - - Create - - 无 - - - Retrieve - - ``` - - 索引取值 - >>> t = (1,3,5) - >>> t[1] - 3 - - - index - >>> t.index(1) - 0 - - - 切片 - >>> t[1:] - (3, 5) - >>> t[:1] - (1,) - ``` - - - - - Update - - 无 - - - Delete - - 无 - -- dict - - - Create - - - 键对值赋值 - - - update - - 提供合并字典的功能 - - ``` - >>> d = {} - >>> d['a'] = 1 - >>> d - {'a': 1} - >>> d2 = {"b":2,"c":3} - >>> d2 - {'b': 2, 'c': 3} - >>> d.update(d2) - >>> d - {'a': 1, 'b': 2, 'c': 3} - - #不改变地址 - >>> d - {'a': 1, 'b': 2, 'c': 3} - >>> id(d) - 22101904 - >>> d.update({'d':0}) - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0} - >>> id(d) - 22101904 - ``` - - - setdefault - - 如果字典中没有当前key, 那么就设置默认值 - - ``` - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0} - >>> id(d) - 22101904 - >>> d.setdefault('l',2) - 2 - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> d.setdefault('a',2) - 1 - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - ``` - - - Retrieve - - - 键对值访问 - - - get - - 键对值访问缺失key会报错, 而get可以指定默认值 - - ``` - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> d['e'] - Traceback (most recent call last): - File "", line 1, in - KeyError: 'e' - >>> d.get('e') - >>> d.get('e',0) - 0 - ``` - - - keys() - - 返回所有key - - ``` - d.keys() - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> d.keys() - dict_keys(['a', 'b', 'c', 'd', 'l']) - >>> list(d.keys()) - ['a', 'b', 'c', 'd', 'l'] - ``` - - - values() - - 返回所有value - - ``` - >>> d.values() - dict_values([1, 2, 3, 0, 2]) - >>> list(d.values()) - [1, 2, 3, 0, 2] - ``` - - - items() - - 返回所有键对值 - - ``` - >>> d.items() - dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 0), ('l' - , 2)]) - >>> list(d.items()) - [('a', 1), ('b', 2), ('c', 3), ('d', 0), ('l', 2)] - ``` - - - Update - - - 键对值赋值 - - ``` - d['a'] = 100 - ``` - - - update - - ``` - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> d.update({"a":100}) - >>> d - {'a': 100, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> id(d) - 22101904 - >>> d.update({"a":10}) - >>> d - {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - >>> id(d) - 22101904 - >>> d.update({"e":10}) - >>> d - {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2, 'e': 10} - ``` - - - Delete - - - pop(key) - - 删除当前元素并返回value - - ``` - >>> d - {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2, 'e': 10} - >>> d.pop('e') - 10 - >>> d - {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2} - ``` - - - popitem() - - 对于人来说, 相当于随机返回一个item - - ``` - >>> d.popitem() - ('l', 2) - - ``` - - - clear() - -- set - - - Create - - - add - - ``` - >>> s = set() - >>> s.add('a') - >>> s - {'a'} - >>> "a" in s - True - ``` - - - update - - ``` - >>> s.update({"b","c"}) - >>> s - {'a', 'b', 'c'} - ``` - - - Retrieve - - - 运算符`in` - - ``` - >>> s - {'a'} - >>> "a" in s - True - ``` - - - update - - - union - - 合并两个set, 并返回一个新的set - - ``` - >>> s - {'a', 'b', 'c'} - >>> id(s) - 51848536 - >>> s2 = {"aa","bb"} - >>> s.union(s2) - {'a', 'b', 'c', 'bb', 'aa'} - >>> s.union({"A"}) - {'a', 'b', 'c', 'A'} - >>> id(s) - 51848536 - ``` - - - delete - - - remove 和discard - - discard缺失元素时不会报错, 而remove会报错 - - ``` - >>> s - {'a', 'b', 'c'} - >>> s.remove("a") - >>> s - {'b', 'c'} - >>> s.discard("a") - >>> s.remove("a") - Traceback (most recent call last): - File "", line 1, in - KeyError: 'a' - ``` - - - pop() - - 当成无序删除并返回元素 - - ``` - >>> s.pop() - 'b' - ``` - +# 第二周-第三节课作业 + +## 基础数据结构的CRUD操作 + +- List(列表) + + **list中存的元素是引用** + + - create(增加) + + - append + + 末尾添加元素 + + ``` + >>> a = [] + >>> id(a) + 22164744 + >>> a + [] + >>> a.append("a") + >>> a + ['a'] + >>> id(a) + 22164744 + >>> a.append("b") + >>> a + ['a', 'b'] + >>> id(a) + 22164744 + ``` + + - `+` 和`+=` + + - `+` + + 拼接两个列表, 然后返回一个新列表 + + ``` + >>> b + ['A'] + >>> id(b) + 51858888 + >>> b = b+a + >>> b + ['A', 'a', 'b', 'A'] + >>> id(b) + 51858928 + ``` + + - `+=` + + ``` + >>> a + ['a', 'b'] + >>> id(a) + 22164744 + >>> b = ["A"] + >>> b + ['A'] + >>> a += b + >>> a + ['a', 'b', 'A'] + >>> id(a) + 22164744 + ``` + + - `*`和`*=` + + ``` + >>> a + ['a', 'b', 'A'] + >>> id(a) + 22164744 + >>> a = a * 3 + >>> a + ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b', 'A'] + >>> id(a) + 51858888 + ··· 赋值语句之后, a是一个新的对象了 + ``` + + - insert + + 指定位置添加元素 + + ``` + >>> b + ['A', 'a', 'b', 'A'] + >>> b.insert(1,'B') + >>> b + ['A', 'B', 'a', 'b', 'A'] + >>> b.insert(10,'AB') + >>> b + ['A', 'B', 'a', 'b', 'A', 'AB'] + ``` + + - Retrieve(检索) + + - 索引取值 + + 所有序列都支持索引取值 + + ``` + >>> b + ['A', 'B', 'a', 'b', 'A', 'AB'] + >>> + >>> b[2] + 'a' + >>> b[10] + Traceback (most recent call last): + File "", line 1, in + IndexError: list index out of range + ``` + + - 切片 + + ``` + >>> l = list(range(100)) + >>> l + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 + 6, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3 + 0, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 4 + 4, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 5 + 8, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 7 + 2, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 8 + 6, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] + + # 取一段区间 + >>> l[0:10] + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + + >>> l[20:10] + [] + + >>> l[20:25] + [20, 21, 22, 23, 24] + + # 取最后一个值 + >>> l[-1] + 99 + + # 间隔问题 + >>> l[::3] + [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, + 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, + 87, 90, 93, 96, 99] + + >>> l[::10] + [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] + >>> l[2:15:3] + + [2, 5, 8, 11, 14] + >>> l[0:15:3] + + [0, 3, 6, 9, 12] + >>> l[0:15:5] + [0, 5, 10] + ``` + + - index + + ``` + >>> l = ['a','b','c'] + >>> l + ['a', 'b', 'c'] + >>> l.index(2) + Traceback (most recent call last): + File "", line 1, in + ValueError: 2 is not in list + >>> l.index('c') + 2 + ``` + + - Update(更新) + + - 索引赋值 + + ``` + >>> l + ['a', 'b', 'c'] + >>> id(l) + 51892392 + >>> l[1] = "B" + >>> l + ['a', 'B', 'c'] + >>> id(l) + 51892392 + #不改变地址 + ``` + + - 切片赋值 + + ``` + >>> l + ['a_1', 'a_2', 'b', 'c'] + >>> l[0:2] = "a" + >>> l + ['a', 'b', 'c'] + >>> l[0:2] = 1 + ``` + + - DELETE(删除) + + - pop() + + 从末尾删除元素并返回 + + ``` + >>> a + ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b', 'A'] + >>> a.pop() + 'A' + >>> a + ['a', 'b', 'A', 'a', 'b', 'A', 'a', 'b'] + ``` + + - clear() + + 清楚当前列表的元素, 不会改变列表的内存地址. + + ``` + >>> l + ['A', 'c'] + >>> l.clear() + >>> l + [] + ``` + + + + - ★SORT(排序) + + - sort() + + ``` + >>> l = [1,7,5,3] + >>> l + [1, 7, 5, 3] + >>> id(l) + 51892392 + >>> l.sort() + >>> l + [1, 3, 5, 7] + >>> id(l) + 51892392 + ``` + + - sorted + + 排序后返回新列表 + + ``` + >>> l = [1,7,5,3] + >>> l + [1, 7, 5, 3] + >>> id(l) + 51859408 + >>> l = sorted(l) + >>> l + [1, 3, 5, 7] + >>> id(l) + 51892392 + ``` + + - reverse + + ``` + >>> l2 + [1, 2, 3, 4, 6] + >>> l2.reverse() + >>> l2 + [6, 4, 3, 2, 1] + ``` + + - reversed + + 倒序之后返回新列表 + + ``` + >>> l + [1, 3, 2, 6, 4] + >>> list(reversed(l)) + [4, 6, 2, 3, 1] + ``` + +- tuple + + - Create + + 无 + + - Retrieve + + ``` + - 索引取值 + >>> t = (1,3,5) + >>> t[1] + 3 + + - index + >>> t.index(1) + 0 + + - 切片 + >>> t[1:] + (3, 5) + >>> t[:1] + (1,) + ``` + + + + - Update + + 无 + + - Delete + + 无 + +- dict + + - Create + + - 键对值赋值 + + - update + + 提供合并字典的功能 + + ``` + >>> d = {} + >>> d['a'] = 1 + >>> d + {'a': 1} + >>> d2 = {"b":2,"c":3} + >>> d2 + {'b': 2, 'c': 3} + >>> d.update(d2) + >>> d + {'a': 1, 'b': 2, 'c': 3} + + #不改变地址 + >>> d + {'a': 1, 'b': 2, 'c': 3} + >>> id(d) + 22101904 + >>> d.update({'d':0}) + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0} + >>> id(d) + 22101904 + ``` + + - setdefault + + 如果字典中没有当前key, 那么就设置默认值 + + ``` + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0} + >>> id(d) + 22101904 + >>> d.setdefault('l',2) + 2 + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> d.setdefault('a',2) + 1 + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + ``` + + - Retrieve + + - 键对值访问 + + - get + + 键对值访问缺失key会报错, 而get可以指定默认值 + + ``` + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> d['e'] + Traceback (most recent call last): + File "", line 1, in + KeyError: 'e' + >>> d.get('e') + >>> d.get('e',0) + 0 + ``` + + - keys() + + 返回所有key + + ``` + d.keys() + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> d.keys() + dict_keys(['a', 'b', 'c', 'd', 'l']) + >>> list(d.keys()) + ['a', 'b', 'c', 'd', 'l'] + ``` + + - values() + + 返回所有value + + ``` + >>> d.values() + dict_values([1, 2, 3, 0, 2]) + >>> list(d.values()) + [1, 2, 3, 0, 2] + ``` + + - items() + + 返回所有键对值 + + ``` + >>> d.items() + dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 0), ('l' + , 2)]) + >>> list(d.items()) + [('a', 1), ('b', 2), ('c', 3), ('d', 0), ('l', 2)] + ``` + + - Update + + - 键对值赋值 + + ``` + d['a'] = 100 + ``` + + - update + + ``` + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> d.update({"a":100}) + >>> d + {'a': 100, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> id(d) + 22101904 + >>> d.update({"a":10}) + >>> d + {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + >>> id(d) + 22101904 + >>> d.update({"e":10}) + >>> d + {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2, 'e': 10} + ``` + + - Delete + + - pop(key) + + 删除当前元素并返回value + + ``` + >>> d + {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2, 'e': 10} + >>> d.pop('e') + 10 + >>> d + {'a': 10, 'b': 2, 'c': 3, 'd': 0, 'l': 2} + ``` + + - popitem() + + 对于人来说, 相当于随机返回一个item + + ``` + >>> d.popitem() + ('l', 2) + + ``` + + - clear() + +- set + + - Create + + - add + + ``` + >>> s = set() + >>> s.add('a') + >>> s + {'a'} + >>> "a" in s + True + ``` + + - update + + ``` + >>> s.update({"b","c"}) + >>> s + {'a', 'b', 'c'} + ``` + + - Retrieve + + - 运算符`in` + + ``` + >>> s + {'a'} + >>> "a" in s + True + ``` + + - update + + - union + + 合并两个set, 并返回一个新的set + + ``` + >>> s + {'a', 'b', 'c'} + >>> id(s) + 51848536 + >>> s2 = {"aa","bb"} + >>> s.union(s2) + {'a', 'b', 'c', 'bb', 'aa'} + >>> s.union({"A"}) + {'a', 'b', 'c', 'A'} + >>> id(s) + 51848536 + ``` + + - delete + + - remove 和discard + + discard缺失元素时不会报错, 而remove会报错 + + ``` + >>> s + {'a', 'b', 'c'} + >>> s.remove("a") + >>> s + {'b', 'c'} + >>> s.discard("a") + >>> s.remove("a") + Traceback (most recent call last): + File "", line 1, in + KeyError: 'a' + ``` + + - pop() + + 当成无序删除并返回元素 + + ``` + >>> s.pop() + 'b' + ``` + \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_01.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_01.py" index 42af9a69f990478c82e9a8caa3ee3ee5edd624d2..052edb90431fed11fbfb70be7f60c0fdbf16c1f4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_01.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_01.py" @@ -1,114 +1,114 @@ -''' -用for循环和while来完成简单的计数 - -用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 - -斐波那契函数 - -第N项是N-1, N-2的和 - -F(n)=F(n - 1)+F(n - 2) - -[0, 1, 1, 2, 3, 5, 8, 13, 21....] -在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError -''' -# 用for循环和while来完成简单的计数 -l = [1,3,5,4,9,7] -count = 0 -print("==================for=============") -for i in l: - count += 1 - print("现在是第"+ str(count) +"个数,其值为:", i) - -print("==================for=============") -for i,e in enumerate(l): - print(f"现在的排名为: {i+1}, 分数是:{e}") -print("==================while=============") -i = 0 -while i<= len(l): - i += 1 - print("现在是第"+ str(i) +"个数,其值为:", i) -print("==================break=============") -i = 0 -while True: - i += 1 - if i > len(l)+1: - break - print("现在是第" + str(i) + "个数,其值为:", i) - -# 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 -print("==============for实现斐波那契函数=============") -a = 0 -b = 1 -fn = 0 -for i in range(2,100): - fn = a + b - a = b - b = fn - if fn > 100: - break - print(fn, end=" ") -print("\n") -print("==============while实现斐波那契函数=============") -a = 0 -b = 1 -fn = 0 -while fn <= 100: - fn = a + b - a = b - b = fn - if fn > 100: - break - print(fn, end=" ") -print("\n") - -# 自定义异常ParamsError -class ParamsError(Exception): - raise print("参数出错啦?") -def add(a,b): - return a + b ; -def sub(a,b): - return a - b; -def mul(a,b): - return a * b; -def div(a,b): - try: - return a / b - except ParamsError : - return None -def rem(a,b): - return a // b; -def ediv(a,b): - return a % b; -def sqrt(a): - c = int(a) - if c>=0: - return c ** (1/2); - else: - return "开方数不能小于零?"; -c = input("请输入你的运算符号:‘加法:+、减法:-、乘法:*、除法:/,整除://,取余:%,开方:%%:") -# input3 = input("请输入你要开方的数,如果不是进行开方运算请按回车键") - -if c == '%%': - a = float(input("请输入你要开方的数:")) - print(a,"^(1/2)","=",sqrt(a)) -else: - a = float(input("请输入你要运算的第一个数:")) - b = float(input("请输入你要运算的第二个数:")) - # c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%") - if c == '+': - print(a,"+",b,"=",add(a,b)) - elif c == '-': - print(a,"-",b,"=",sub(a,b)) - elif c == '*': - print(a,"*",b,"=",mul(a,b)) - elif c == '-': - print(a,"/",b,"=",div(a,b)) - elif c == '-': - print(a,"//",b,"=",ediv(a,b)) - elif c == '-': - print(a,"%",b,"=",rem(a,b)) - elif c == '-': - print(a,"^(1/2)",b,"=",sqrt(a,b)) - else : +''' +用for循环和while来完成简单的计数 + +用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 + +斐波那契函数 + +第N项是N-1, N-2的和 + +F(n)=F(n - 1)+F(n - 2) + +[0, 1, 1, 2, 3, 5, 8, 13, 21....] +在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError +''' +# 用for循环和while来完成简单的计数 +l = [1,3,5,4,9,7] +count = 0 +print("==================for=============") +for i in l: + count += 1 + print("现在是第"+ str(count) +"个数,其值为:", i) + +print("==================for=============") +for i,e in enumerate(l): + print(f"现在的排名为: {i+1}, 分数是:{e}") +print("==================while=============") +i = 0 +while i<= len(l): + i += 1 + print("现在是第"+ str(i) +"个数,其值为:", i) +print("==================break=============") +i = 0 +while True: + i += 1 + if i > len(l)+1: + break + print("现在是第" + str(i) + "个数,其值为:", i) + +# 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 +print("==============for实现斐波那契函数=============") +a = 0 +b = 1 +fn = 0 +for i in range(2,100): + fn = a + b + a = b + b = fn + if fn > 100: + break + print(fn, end=" ") +print("\n") +print("==============while实现斐波那契函数=============") +a = 0 +b = 1 +fn = 0 +while fn <= 100: + fn = a + b + a = b + b = fn + if fn > 100: + break + print(fn, end=" ") +print("\n") + +# 自定义异常ParamsError +class ParamsError(Exception): + raise print("参数出错啦?") +def add(a,b): + return a + b ; +def sub(a,b): + return a - b; +def mul(a,b): + return a * b; +def div(a,b): + try: + return a / b + except ParamsError : + return None +def rem(a,b): + return a // b; +def ediv(a,b): + return a % b; +def sqrt(a): + c = int(a) + if c>=0: + return c ** (1/2); + else: + return "开方数不能小于零?"; +c = input("请输入你的运算符号:‘加法:+、减法:-、乘法:*、除法:/,整除://,取余:%,开方:%%:") +# input3 = input("请输入你要开方的数,如果不是进行开方运算请按回车键") + +if c == '%%': + a = float(input("请输入你要开方的数:")) + print(a,"^(1/2)","=",sqrt(a)) +else: + a = float(input("请输入你要运算的第一个数:")) + b = float(input("请输入你要运算的第二个数:")) + # c = input("请输入你的运算符号:‘+、-、*、/,//,%,开方:%%") + if c == '+': + print(a,"+",b,"=",add(a,b)) + elif c == '-': + print(a,"-",b,"=",sub(a,b)) + elif c == '*': + print(a,"*",b,"=",mul(a,b)) + elif c == '-': + print(a,"/",b,"=",div(a,b)) + elif c == '-': + print(a,"//",b,"=",ediv(a,b)) + elif c == '-': + print(a,"%",b,"=",rem(a,b)) + elif c == '-': + print(a,"^(1/2)",b,"=",sqrt(a,b)) + else : print("请输入正确的运算?") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_02.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_02.py" index 984ddde36e0f6bba2b087d77cdb05419f3431538..f418cf9aef091c24b5509f78835ee05fdb526a1b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_02.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_02.py" @@ -1,302 +1,302 @@ -''' -内置函数 -from pprint import pprint -# 格式化输出的库 -pprint(dir(__builtins__)) -''' -# 常见的内置函数 -# str -''' ->>> int(1.1) -1 ->>> int("1.0") -Traceback (most recent call last): - File "", line 1, in -ValueError: invalid literal for int() with base 10: '1.0' ->>> int("2") -2 - -''' -# float -''' ->>> float("1.00") -1.0 ->>> float("1") -1.0 ->>> float("1.1") -1.1 - -''' -# bytes -''' ->>> bytes("ab".encode("utf-8")) -b'ab' - -''' -# bool -''' ->>> bool(1) -True ->>> bool(a) -Traceback (most recent call last): - File "", line 1, in -NameError: name 'a' is not defined ->>> bool(1) -True ->>> bool('1') -True ->>> bool('0') -True ->>> bool(0) -False ->>> bool(0.0) -False ->>> bool(0.1) -True ->>> bool("0") -True ->>> bool("a") -True - -''' -# list -''' ->>> list("1234567") -['1', '2', '3', '4', '5', '6', '7'] ->>> list("abcdef") -['a', 'b', 'c', 'd', 'e', 'f'] - -''' -# tuple -''' ->>> tuple("ab123") -('a', 'b', '1', '2', '3') - -''' -# dict -''' ->>> dict(a=2) -{'a': 2} ->>> dict(a=2,b=1) -{'a': 2, 'b': 1} - -''' -# set -''' ->>> set([1,3,5,7,9]) -{1, 3, 5, 7, 9} ->>> set('abcdef') -{'e', 'd', 'c', 'a', 'b', 'f'} - -''' -# id -''' ->>> a = "2" ->>> id(a) -51010400 - -''' -# dir -''' - >>> dir(__builtins__) -['ArithmeticError', - -''' -# max -''' ->>>> max([1,3,5,7,9]) -9 - -''' -# min -''' ->>> min([1,3,5,7,9]) -1 - -''' -# range -''' ->>> range(100) -range(0, 100) ->>> r = range(100) ->>> r -range(0, 100) ->>> l = [] ->>> for i in range(10): -... l.append(i) -... ->>> print(l) -[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - -''' -# 函数的形参和实参 -# 形參 - -def my_power(a, b): - return a ** b -# 实参 -print(my_power(2,3)) - -# 函数的返回值 -''' ->>> def foo(a,b): -... return a*2,b*2 -... ->>> result = foo(2,3) ->>> result -(4, 6) ->>> ->>> a,b = foo(2,3) ->>> a -4 ->>> b -6 ->>> result = foo(2,3) ->>> a,b = result ->>> a -4 ->>> b -6 ->>> result -(4, 6) ->>> result = (2,4,6,8,0) ->>> result -(2, 4, 6, 8, 0) ->>> a,*b,c = result ->>> a -2 ->>> b -[4, 6, 8] ->>> c -0 ->>> a,*b,c,d = result ->>> a -2 ->>> b -[4, 6] ->>> c -8 ->>> d -0 - -''' -# 匿名函数 - -''' ->>> lambda x : x**2 - at 0x030A76F0> ->>> lambda x : True if x % 2==0 else False - at 0x030A7738> - ->>> l = [[1,2],[2,3],[4,5]] ->>> l.sort(key=lambda x: x[1]) ->>> print(l) -[[1, 2], [2, 3], [4, 5]] - -''' -# 高阶函数 -# map映射 -''' ->>> l = [1,3,5] ->>> m = map(lambda x: x**2, [1,3,5]) -# 获得返回结果是一个map对象 ->>> m - ->>> l -[1, 3, 5] -# map对象是一个可迭代对象, 需要驱动可迭代对象返回值, list就有这样的功能. 暂时不要太纠结 ->>> list(m) -[1, 9, 25] - -以上等同于 ->>> def my_power_2(a): -... return a**2 -... ->>> m = map(my_power_2,[1,3,5]) ->>> list(m) -[1, 9, 25] - ->>> import math ->>> m = map(math.sqrt,[1,4,25,36]) ->>> list(m) -[1.0, 2.0, 5.0, 6.0] - -''' - -# filter过滤 -''' ->>> l = [1,0,4,5,8,9] ->>> f = filter(lambda x: x%2, l) ->>> list(f) -[1, 5, 9] -# 过滤奇数 ->>> f = filter(lambda x: False if x%2 == 1 else True, l) ->>> list(f) -[0, 4, 8] - -''' - -# 递归函数 - -''' ->>> def fact(n): -... if n == 1: -... return 1 -... return n * fact(n-1) -... ->>> fact (5) -120 - -''' - -# 课后作业 -''' -给定一个列表, 根据grade来排序 - -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -通过filter语句来筛选出Grade为A的同学 - -通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) - -使用递归函数重构斐波那契函数 - -f(n) = f(n-1) + f(n-2) -''' -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -l = classes -l.sort(key=lambda x: x["grade"]) -print(l) -print("通过filter语句来筛选出Grade为A的同学") -f = filter(lambda x: x["grade"] == 'A',classes) -print(list(f)) -print("通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)") -def add(l): - l["age"]+=1 - return l -m = map(add,classes) -print(list(m)) -print("使用递归函数重构斐波那契函数") -def fibs(n): - if(n<2): - return 1 - else: - return fibs(n-2)+fibs(n-1) - -for i in range(11): +''' +内置函数 +from pprint import pprint +# 格式化输出的库 +pprint(dir(__builtins__)) +''' +# 常见的内置函数 +# str +''' +>>> int(1.1) +1 +>>> int("1.0") +Traceback (most recent call last): + File "", line 1, in +ValueError: invalid literal for int() with base 10: '1.0' +>>> int("2") +2 + +''' +# float +''' +>>> float("1.00") +1.0 +>>> float("1") +1.0 +>>> float("1.1") +1.1 + +''' +# bytes +''' +>>> bytes("ab".encode("utf-8")) +b'ab' + +''' +# bool +''' +>>> bool(1) +True +>>> bool(a) +Traceback (most recent call last): + File "", line 1, in +NameError: name 'a' is not defined +>>> bool(1) +True +>>> bool('1') +True +>>> bool('0') +True +>>> bool(0) +False +>>> bool(0.0) +False +>>> bool(0.1) +True +>>> bool("0") +True +>>> bool("a") +True + +''' +# list +''' +>>> list("1234567") +['1', '2', '3', '4', '5', '6', '7'] +>>> list("abcdef") +['a', 'b', 'c', 'd', 'e', 'f'] + +''' +# tuple +''' +>>> tuple("ab123") +('a', 'b', '1', '2', '3') + +''' +# dict +''' +>>> dict(a=2) +{'a': 2} +>>> dict(a=2,b=1) +{'a': 2, 'b': 1} + +''' +# set +''' +>>> set([1,3,5,7,9]) +{1, 3, 5, 7, 9} +>>> set('abcdef') +{'e', 'd', 'c', 'a', 'b', 'f'} + +''' +# id +''' +>>> a = "2" +>>> id(a) +51010400 + +''' +# dir +''' + >>> dir(__builtins__) +['ArithmeticError', + +''' +# max +''' +>>>> max([1,3,5,7,9]) +9 + +''' +# min +''' +>>> min([1,3,5,7,9]) +1 + +''' +# range +''' +>>> range(100) +range(0, 100) +>>> r = range(100) +>>> r +range(0, 100) +>>> l = [] +>>> for i in range(10): +... l.append(i) +... +>>> print(l) +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +''' +# 函数的形参和实参 +# 形參 + +def my_power(a, b): + return a ** b +# 实参 +print(my_power(2,3)) + +# 函数的返回值 +''' +>>> def foo(a,b): +... return a*2,b*2 +... +>>> result = foo(2,3) +>>> result +(4, 6) +>>> +>>> a,b = foo(2,3) +>>> a +4 +>>> b +6 +>>> result = foo(2,3) +>>> a,b = result +>>> a +4 +>>> b +6 +>>> result +(4, 6) +>>> result = (2,4,6,8,0) +>>> result +(2, 4, 6, 8, 0) +>>> a,*b,c = result +>>> a +2 +>>> b +[4, 6, 8] +>>> c +0 +>>> a,*b,c,d = result +>>> a +2 +>>> b +[4, 6] +>>> c +8 +>>> d +0 + +''' +# 匿名函数 + +''' +>>> lambda x : x**2 + at 0x030A76F0> +>>> lambda x : True if x % 2==0 else False + at 0x030A7738> + +>>> l = [[1,2],[2,3],[4,5]] +>>> l.sort(key=lambda x: x[1]) +>>> print(l) +[[1, 2], [2, 3], [4, 5]] + +''' +# 高阶函数 +# map映射 +''' +>>> l = [1,3,5] +>>> m = map(lambda x: x**2, [1,3,5]) +# 获得返回结果是一个map对象 +>>> m + +>>> l +[1, 3, 5] +# map对象是一个可迭代对象, 需要驱动可迭代对象返回值, list就有这样的功能. 暂时不要太纠结 +>>> list(m) +[1, 9, 25] + +以上等同于 +>>> def my_power_2(a): +... return a**2 +... +>>> m = map(my_power_2,[1,3,5]) +>>> list(m) +[1, 9, 25] + +>>> import math +>>> m = map(math.sqrt,[1,4,25,36]) +>>> list(m) +[1.0, 2.0, 5.0, 6.0] + +''' + +# filter过滤 +''' +>>> l = [1,0,4,5,8,9] +>>> f = filter(lambda x: x%2, l) +>>> list(f) +[1, 5, 9] +# 过滤奇数 +>>> f = filter(lambda x: False if x%2 == 1 else True, l) +>>> list(f) +[0, 4, 8] + +''' + +# 递归函数 + +''' +>>> def fact(n): +... if n == 1: +... return 1 +... return n * fact(n-1) +... +>>> fact (5) +120 + +''' + +# 课后作业 +''' +给定一个列表, 根据grade来排序 + +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +通过filter语句来筛选出Grade为A的同学 + +通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) + +使用递归函数重构斐波那契函数 + +f(n) = f(n-1) + f(n-2) +''' +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +l = classes +l.sort(key=lambda x: x["grade"]) +print(l) +print("通过filter语句来筛选出Grade为A的同学") +f = filter(lambda x: x["grade"] == 'A',classes) +print(list(f)) +print("通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)") +def add(l): + l["age"]+=1 + return l +m = map(add,classes) +print(list(m)) +print("使用递归函数重构斐波那契函数") +def fibs(n): + if(n<2): + return 1 + else: + return fibs(n-2)+fibs(n-1) + +for i in range(11): print(fibs(i),end=" ") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_03.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_03.py" index d55b3c6db1341f6c46e5dd16f3a3a77b47feafe5..925c6b3d15563216fa79dcdf286fc9f1201d3b11 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_03.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week3/lesson_03.py" @@ -1,95 +1,95 @@ -''' -背诵作用域的概念 - 程序创建, 访问, 改变一个变量时, 都是在一个保存该变量的空间内进行, 这个空间被称为命名空间, 即作用域 -练习作用域之间的转换 - -默写一个装饰器, 用来输出函数的执行时间. - -使用装饰器来为斐波那契函数添加缓存 - -def cache_deco(func): - # 保存n执行后的结果 - a = {} - # 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 - result = func(n) - return result - -@cache_deco -def fibo(n): - pass -''' -# 练习作用域之间的转换 -''' -a = 1 -def foo(): - global a - a = 2 - print(a) -foo() -print(a) -''' -a = 1 -b = 7 -def foo(a,b): - c = a - a = b - b = c - print("函数内的a:" ,a, ",b:", b) - return a,b -print("函数外的a:" ,a, ",b:", b) -print(foo(a,b)) -def func(): - total = 0 - count = 0 - def refoo(a,b): - nonlocal total,count - print("开始total为:", total, "count为:", count) - total += a - count += b - print("现在total为:",total,"count为:",count) - return refoo - refoo(1,1) - print(total,count) -func() - -# 默写一个装饰器, 用来输出函数的执行时间. -import time -def clock_it_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - return wrapper - -# @other_deco -@clock_it_deco -def foo_1(a, b): - count = 1 - while True: - if count > a ** b: - break - count += 1 - -foo_1(10, 5) - -# 使用装饰器来为斐波那契函数添加缓存 -a = {} -def cache_deco(func): - global a - def infun(n): - if n not in a: - a[n] = func(n) - return a[n] - return infun - - -@cache_deco -def fibo(n): - if n < 2: - return n - else: - return fibo(n - 2) + fibo(n - 1) -print(fibo(10)) +''' +背诵作用域的概念 + 程序创建, 访问, 改变一个变量时, 都是在一个保存该变量的空间内进行, 这个空间被称为命名空间, 即作用域 +练习作用域之间的转换 + +默写一个装饰器, 用来输出函数的执行时间. + +使用装饰器来为斐波那契函数添加缓存 + +def cache_deco(func): + # 保存n执行后的结果 + a = {} + # 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 + result = func(n) + return result + +@cache_deco +def fibo(n): + pass +''' +# 练习作用域之间的转换 +''' +a = 1 +def foo(): + global a + a = 2 + print(a) +foo() +print(a) +''' +a = 1 +b = 7 +def foo(a,b): + c = a + a = b + b = c + print("函数内的a:" ,a, ",b:", b) + return a,b +print("函数外的a:" ,a, ",b:", b) +print(foo(a,b)) +def func(): + total = 0 + count = 0 + def refoo(a,b): + nonlocal total,count + print("开始total为:", total, "count为:", count) + total += a + count += b + print("现在total为:",total,"count为:",count) + return refoo + refoo(1,1) + print(total,count) +func() + +# 默写一个装饰器, 用来输出函数的执行时间. +import time +def clock_it_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + return wrapper + +# @other_deco +@clock_it_deco +def foo_1(a, b): + count = 1 + while True: + if count > a ** b: + break + count += 1 + +foo_1(10, 5) + +# 使用装饰器来为斐波那契函数添加缓存 +a = {} +def cache_deco(func): + global a + def infun(n): + if n not in a: + a[n] = func(n) + return a[n] + return infun + + +@cache_deco +def fibo(n): + if n < 2: + return n + else: + return fibo(n - 2) + fibo(n - 1) +print(fibo(10)) print(a) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_01.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_01.py" index bd369bdd8c5de58df22ef654337b6dd016fcf915..bf7decd824312a8592540403b827083387992bb4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_01.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_01.py" @@ -1,87 +1,87 @@ -''' -课后作业 -通过`datetime`模块完成时间戳, `datetime.datetime`对象, 格式化字符串三者之间的转换 -封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期`2020-01-02`. -''' -import datetime -from datetime import timedelta -now = datetime.datetime.now() -# 时间格式转换为时间戳 -time_stamp = now.timestamp() -print(time_stamp) -# 时间格式转换为字符串格式 -print(now.time().strftime("%Y:%m:%d %H:%M:%S")) -# 字符串格式转换为时间格式 -str_time = '2021:01:01 10:44:37' -print(datetime.datetime.strptime(str_time,"%Y:%m:%d %H:%M:%S")) -# 字符串转换为时间戳格式 -print(datetime.datetime.strptime(str_time,"%Y:%m:%d %H:%M:%S").timestamp()) -# 时间戳转换为时间格式 -print((datetime.datetime.fromtimestamp(now.timestamp(),tz=None)).strftime("%Y:%m:%d %H:%M:%S")) -# 时间戳转换为字符串格式 -# print((datetime.datetime.now(tz=None).timestamp()) - -def get_date(): - ''' - 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是字符串日期`2020-01-02`. - :param day_delta: - :return: - ''' - n = input("想知道时间?请输入-1: ") - if n == '-1': - print(datetime.datetime.now(tz=None).strftime("%Y:%m:%d")) - else: - print("输入的不是-1,重新输入") - get_date() - return -get_date( ) - - -''' -import time -import datetime -print(time.time()) -# print(time.time().strftime("%Y=%m=%d %H:%M:%S")) -print("=============") -print(datetime.datetime.now()) -now = datetime.datetime.now(tz=None) -print(type(now)) -print(now.strftime("%Y=%m=%d %H:%M:%S")) -print(datetime.datetime.today()) -print("======时间格式转换=======") -print(datetime.datetime.strptime(now.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")) -''' -''' ->>> now = datetime.datetime.now(tz=None) ->>> now -datetime.datetime(2021, 1, 6, 23, 43, 22, 981322) ->>> print(datetime.datetime.strptime(now.strftime("%Y=%m=%d %H:%M:%S"), "%Y=%m=%d %H:%M:%S")) -2021-01-06 23:43:22 ->>> now = now.strftime("%Y-%m-%d %H:%M:%S") ->>> now -'2021-01-06 23:43:22' ->>> datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S") -datetime.datetime(2021, 1, 6, 23, 43, 22) - -''' -# 时间戳转换 -''' ->>> now = datetime.datetime.now(tz=None) ->>> now -datetime.datetime(2021, 1, 6, 23, 52, 26, 803688) ->>> now.timestamp() -1609948346.803688 ->>> ts = now.timestamp() ->>> ts -1609948346.803688 ->>> type(ts) - ->>> datetime.datetime.fromtimestamp(ts, tz=None) -datetime.datetime(2021, 1, 6, 23, 52, 26, 803688) -''' -# 时间运算 -''' ->>> from datetime import timedelta ->>> now + timedelta(hours=-1) -datetime.datetime(2021, 1, 6, 22, 52, 26, 803688) +''' +课后作业 +通过`datetime`模块完成时间戳, `datetime.datetime`对象, 格式化字符串三者之间的转换 +封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期`2020-01-02`. +''' +import datetime +from datetime import timedelta +now = datetime.datetime.now() +# 时间格式转换为时间戳 +time_stamp = now.timestamp() +print(time_stamp) +# 时间格式转换为字符串格式 +print(now.time().strftime("%Y:%m:%d %H:%M:%S")) +# 字符串格式转换为时间格式 +str_time = '2021:01:01 10:44:37' +print(datetime.datetime.strptime(str_time,"%Y:%m:%d %H:%M:%S")) +# 字符串转换为时间戳格式 +print(datetime.datetime.strptime(str_time,"%Y:%m:%d %H:%M:%S").timestamp()) +# 时间戳转换为时间格式 +print((datetime.datetime.fromtimestamp(now.timestamp(),tz=None)).strftime("%Y:%m:%d %H:%M:%S")) +# 时间戳转换为字符串格式 +# print((datetime.datetime.now(tz=None).timestamp()) + +def get_date(): + ''' + 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是字符串日期`2020-01-02`. + :param day_delta: + :return: + ''' + n = input("想知道时间?请输入-1: ") + if n == '-1': + print(datetime.datetime.now(tz=None).strftime("%Y:%m:%d")) + else: + print("输入的不是-1,重新输入") + get_date() + return +get_date( ) + + +''' +import time +import datetime +print(time.time()) +# print(time.time().strftime("%Y=%m=%d %H:%M:%S")) +print("=============") +print(datetime.datetime.now()) +now = datetime.datetime.now(tz=None) +print(type(now)) +print(now.strftime("%Y=%m=%d %H:%M:%S")) +print(datetime.datetime.today()) +print("======时间格式转换=======") +print(datetime.datetime.strptime(now.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")) +''' +''' +>>> now = datetime.datetime.now(tz=None) +>>> now +datetime.datetime(2021, 1, 6, 23, 43, 22, 981322) +>>> print(datetime.datetime.strptime(now.strftime("%Y=%m=%d %H:%M:%S"), "%Y=%m=%d %H:%M:%S")) +2021-01-06 23:43:22 +>>> now = now.strftime("%Y-%m-%d %H:%M:%S") +>>> now +'2021-01-06 23:43:22' +>>> datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S") +datetime.datetime(2021, 1, 6, 23, 43, 22) + +''' +# 时间戳转换 +''' +>>> now = datetime.datetime.now(tz=None) +>>> now +datetime.datetime(2021, 1, 6, 23, 52, 26, 803688) +>>> now.timestamp() +1609948346.803688 +>>> ts = now.timestamp() +>>> ts +1609948346.803688 +>>> type(ts) + +>>> datetime.datetime.fromtimestamp(ts, tz=None) +datetime.datetime(2021, 1, 6, 23, 52, 26, 803688) +''' +# 时间运算 +''' +>>> from datetime import timedelta +>>> now + timedelta(hours=-1) +datetime.datetime(2021, 1, 6, 22, 52, 26, 803688) ''' \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_02.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_02.py" index 045e7388d3e8d6530b2a5529ad3d478d5a02228b..2bdf9720e3b060ecf4700cc3d055ed7315bf81ef 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_02.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_02.py" @@ -1,65 +1,65 @@ -# 第一题 -class MyMath: - ''' - 用类封装一个`MyMath`类, 实现加, 减, 乘, 除, 幂, 开方 - :return: - ''' - def add(self,a ,b): - ''' - 加法运算 - ''' - return a + b - def sub(self, a , b): - ''' - 减法运算 - ''' - return a - b - def mul(self, a, b,): - ''' - 乘法运算 - ''' - return a * b - def div(self, a, b): - ''' - 除法运算 - ''' - return a / b - def power(self, a, n): - ''' - 幂运算 - ''' - return float(a ** n) - def sqrt(self, a): - ''' - 开方运算 - ''' - return float(a ** (1/2)) - -a = MyMath() -b = a.power(2, 13) -print(b) -# 第二题 -class Person(object): - def __init__(self,name, sex): - ''' - 人类 - :param name:名字 - :param sex:性别 - ''' - self.name = name - self.sex = sex - def speak(self): - print(f"我的名字叫{self.name},我是一个可爱的{self.sex}生?") - def play(self, game): - print(f"我{self.name}要玩{game}游戏??") -class Student(Person): - def study(self): - print(f"我们要向学霸{self.name}同学学习!!!") - -Salary = Person("Salary","女") -Salary.speak() -Salary.play("英雄联盟") -XiaoMing = Student("小明","男") -XiaoMing.speak() -XiaoMing.study() +# 第一题 +class MyMath: + ''' + 用类封装一个`MyMath`类, 实现加, 减, 乘, 除, 幂, 开方 + :return: + ''' + def add(self,a ,b): + ''' + 加法运算 + ''' + return a + b + def sub(self, a , b): + ''' + 减法运算 + ''' + return a - b + def mul(self, a, b,): + ''' + 乘法运算 + ''' + return a * b + def div(self, a, b): + ''' + 除法运算 + ''' + return a / b + def power(self, a, n): + ''' + 幂运算 + ''' + return float(a ** n) + def sqrt(self, a): + ''' + 开方运算 + ''' + return float(a ** (1/2)) + +a = MyMath() +b = a.power(2, 13) +print(b) +# 第二题 +class Person(object): + def __init__(self,name, sex): + ''' + 人类 + :param name:名字 + :param sex:性别 + ''' + self.name = name + self.sex = sex + def speak(self): + print(f"我的名字叫{self.name},我是一个可爱的{self.sex}生?") + def play(self, game): + print(f"我{self.name}要玩{game}游戏??") +class Student(Person): + def study(self): + print(f"我们要向学霸{self.name}同学学习!!!") + +Salary = Person("Salary","女") +Salary.speak() +Salary.play("英雄联盟") +XiaoMing = Student("小明","男") +XiaoMing.speak() +XiaoMing.study() XiaoMing.play("王者农药") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_3.py" index c8ba395760fccc79024317f9be0191b9c3b05695..2ebb616a842a498391e72e31df6b63a1f126bd5a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week4/week_4/lesson_3.py" @@ -1,71 +1,71 @@ -#第一问 -class MyMath: - @staticmethod - def add(self, a, b): - ''' - 加法运算 - ''' - return a + b - - def sub(self, a, b): - ''' - 减法运算 - ''' - return a - b - - def mul(self, a, b, ): - ''' - 乘法运算 - ''' - return a * b - - def div(self, a, b): - ''' - 除法运算 - ''' - return a / b - - @staticmethod - def power(a, n): - ''' - 幂运算 - ''' - return float(a ** n) - - def sqrt(self, a): - ''' - 开方运算 - ''' - return float(a ** (1 / 2)) - -print(MyMath.power(2, 13)) - -# 第二问 -class Person(object): - goodperson = True - __secret = "不能告诉你的秘密!" - @classmethod - def get_secret(cls): - return cls.__secret - def __init__(self,name, sex): - ''' - 人类 - :param name:名字 - :param sex:性别 - ''' - self.name = name - self.sex = sex - def __str__(self): - # return print("就是一个:{0}".format((Salary.get_secret())) - return "就是一个:{0}".format((Salary.get_secret())) - def speak(self): - print(f"我的名字叫{self.name},我是一个可爱的{self.sex}生?") - def play(self, game): - print(f"我{self.name}要玩{game}游戏??") -class Student(Person): - def study(self): - print(f"我们要向学霸{self.name}同学学习!!!") - -Salary = Person("Salary","女") -Salary.speak() +#第一问 +class MyMath: + @staticmethod + def add(self, a, b): + ''' + 加法运算 + ''' + return a + b + + def sub(self, a, b): + ''' + 减法运算 + ''' + return a - b + + def mul(self, a, b, ): + ''' + 乘法运算 + ''' + return a * b + + def div(self, a, b): + ''' + 除法运算 + ''' + return a / b + + @staticmethod + def power(a, n): + ''' + 幂运算 + ''' + return float(a ** n) + + def sqrt(self, a): + ''' + 开方运算 + ''' + return float(a ** (1 / 2)) + +print(MyMath.power(2, 13)) + +# 第二问 +class Person(object): + goodperson = True + __secret = "不能告诉你的秘密!" + @classmethod + def get_secret(cls): + return cls.__secret + def __init__(self,name, sex): + ''' + 人类 + :param name:名字 + :param sex:性别 + ''' + self.name = name + self.sex = sex + def __str__(self): + # return print("就是一个:{0}".format((Salary.get_secret())) + return "就是一个:{0}".format((Salary.get_secret())) + def speak(self): + print(f"我的名字叫{self.name},我是一个可爱的{self.sex}生?") + def play(self, game): + print(f"我{self.name}要玩{game}游戏??") +class Student(Person): + def study(self): + print(f"我们要向学霸{self.name}同学学习!!!") + +Salary = Person("Salary","女") +Salary.speak() print(Salary.__str__()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_01.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_01.py" index 4451a27c60ed17a8a3f021cec57d4f0c78e48abd..26025e12d26676c71150f8aedb2acae6d7dfd4a3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_01.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_01.py" @@ -1,70 +1,70 @@ -import requests -from threading import Thread -import time -from multiprocessing import Process - -# 利用Python实现一个多线程程序 - -def printNum(num): - for i in range(num): - time.sleep(0.2) - print(f"当前数字为:{i}") - - -def goThread(): - old = time.time() - thread_array = [] - time.sleep(0.1) - t = Thread(target=printNum, args=(5,)) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - now = time.time() - - print(f"线程done!!!, 用时{round((now - old),2)} s !") - -# 将多线程程序改为多进程程序 - -def goProcess(): - old = time.time() - process_array = [] - time.sleep(0.1) - p = Process(target=printNum,args=(7,)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - now = time.time() - - print(f"进程done!!!, 用时{round((now - old),2)} s !") - -if __name__ == "__main__": - goThread() - print("进程") - goProcess() - - - - - - - - - - - - - -''' -def request_baidu(): - time.sleep(2) - url = "https://www.baidu.com/" - body = " " - headers = { - "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" - } - response = requests.get(url = url, headers = headers) - # print(response.text) - print(response) +import requests +from threading import Thread +import time +from multiprocessing import Process + +# 利用Python实现一个多线程程序 + +def printNum(num): + for i in range(num): + time.sleep(0.2) + print(f"当前数字为:{i}") + + +def goThread(): + old = time.time() + thread_array = [] + time.sleep(0.1) + t = Thread(target=printNum, args=(5,)) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + now = time.time() + + print(f"线程done!!!, 用时{round((now - old),2)} s !") + +# 将多线程程序改为多进程程序 + +def goProcess(): + old = time.time() + process_array = [] + time.sleep(0.1) + p = Process(target=printNum,args=(7,)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + now = time.time() + + print(f"进程done!!!, 用时{round((now - old),2)} s !") + +if __name__ == "__main__": + goThread() + print("进程") + goProcess() + + + + + + + + + + + + + +''' +def request_baidu(): + time.sleep(2) + url = "https://www.baidu.com/" + body = " " + headers = { + "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" + } + response = requests.get(url = url, headers = headers) + # print(response.text) + print(response) ''' \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_02.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_02.py" index 78f6dc77953c94488543666c3140a11bac91fedf..8a5d9b02c1c17d85fb7e150b3e3e434392a23e5d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_02.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_02.py" @@ -1,63 +1,63 @@ -''' -多进程锁, 多线程锁都要自己实现一遍 -多进程通过Queue来实现进程通信 -把上述概念熟记并理解 -''' -import requests -import time -from threading import Thread -from multiprocessing import Process, Lock,Queue - -def speak_num(num, lock): - with lock: - for i in range(num): - print(f"当前在说数字:{i}") - -def process_speak_num(): - process_array = [] - old = time.time() - lock = Lock() - for i in range(7): - p = Process(target=speak_num, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - now = time.time() - print(f"进程说:KO!!!用时{round((now-old),3)}s") - -def thread_speak_num(): - thread_array = [] - old = time.time() - lock = Lock() - for i in range(7): - t = Thread(target=speak_num, args=(i, lock)) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - now = time.time() - print(f"进程说:KO!!!用时{round((now-old),3)}s") -def queue_num(num, my_queue): - my_queue.put(num) -def queue_speak_num(): - process_array = [] - old = time.time() - my_queue = Queue() - for i in range(7): - p = Process(target=queue_num, args=(i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - now = time.time() - print(f"Queue说:KO!!!用时{round((now - old), 3)}s") - n = 0 - while n <= 6: - print(my_queue.get()) - n += 1 - -if __name__ == "__main__": - process_speak_num() - thread_speak_num() +''' +多进程锁, 多线程锁都要自己实现一遍 +多进程通过Queue来实现进程通信 +把上述概念熟记并理解 +''' +import requests +import time +from threading import Thread +from multiprocessing import Process, Lock,Queue + +def speak_num(num, lock): + with lock: + for i in range(num): + print(f"当前在说数字:{i}") + +def process_speak_num(): + process_array = [] + old = time.time() + lock = Lock() + for i in range(7): + p = Process(target=speak_num, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + now = time.time() + print(f"进程说:KO!!!用时{round((now-old),3)}s") + +def thread_speak_num(): + thread_array = [] + old = time.time() + lock = Lock() + for i in range(7): + t = Thread(target=speak_num, args=(i, lock)) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + now = time.time() + print(f"进程说:KO!!!用时{round((now-old),3)}s") +def queue_num(num, my_queue): + my_queue.put(num) +def queue_speak_num(): + process_array = [] + old = time.time() + my_queue = Queue() + for i in range(7): + p = Process(target=queue_num, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + now = time.time() + print(f"Queue说:KO!!!用时{round((now - old), 3)}s") + n = 0 + while n <= 6: + print(my_queue.get()) + n += 1 + +if __name__ == "__main__": + process_speak_num() + thread_speak_num() queue_speak_num() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_03.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_03.py" index 7e0525083e5959356dcf2ca97619efbfe27ff2e1..443ba035bd2cd969055c7bb13af01f4d6ab3ee63 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_03.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\200\206\345\205\211\345\271\264/week5/lesson_03.py" @@ -1,44 +1,44 @@ -''' -什么是迭代器?什么是生成器?两者有什么区别? - -迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有使用next方法调用才会返回值) -迭代器侧重于提供数据的惰性返回功能。生成器侧重于指令的惰性返回功能。 - -协程的实现原理. -asyncio实现原理 -用协程实现一个计算平均数的函数 -编写一个asyncio异步程序 -扩展: 了解aiohttp异步请求网址 -''' -def avg(): - total = 0 - length = 0 - while True: - try: - value = yield total / length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 -my_avg = avg() -print(next(my_avg)) -print(my_avg.send(1)) -print(my_avg.send(2)) -print(my_avg.send(3)) - -import time,asyncio - -async def say_hello(): - await asyncio.sleep(0.7) - print(f"您好,当前时间是:{time.time()}") - -def start_say_hello(): - loop = asyncio.get_event_loop() - task_array = [] - for i in range(7): - task_array.append(say_hello()) - loop.run_until_complete(asyncio.wait(task_array)) - loop.close() - -if __name__ =='__main__': - start_say_hello() +''' +什么是迭代器?什么是生成器?两者有什么区别? + +迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有使用next方法调用才会返回值) +迭代器侧重于提供数据的惰性返回功能。生成器侧重于指令的惰性返回功能。 + +协程的实现原理. +asyncio实现原理 +用协程实现一个计算平均数的函数 +编写一个asyncio异步程序 +扩展: 了解aiohttp异步请求网址 +''' +def avg(): + total = 0 + length = 0 + while True: + try: + value = yield total / length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 +my_avg = avg() +print(next(my_avg)) +print(my_avg.send(1)) +print(my_avg.send(2)) +print(my_avg.send(3)) + +import time,asyncio + +async def say_hello(): + await asyncio.sleep(0.7) + print(f"您好,当前时间是:{time.time()}") + +def start_say_hello(): + loop = asyncio.get_event_loop() + task_array = [] + for i in range(7): + task_array.append(say_hello()) + loop.run_until_complete(asyncio.wait(task_array)) + loop.close() + +if __name__ =='__main__': + start_say_hello() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/3.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/3.1.py" index afa4246e865894c905d8bbd05db2da3dbb20e6e0..1bb52b77c25959a6263be8a81971b7e67a62c4c6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/3.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/3.1.py" @@ -1,84 +1,84 @@ -#1 计数 -i = 0 -while i <6: - print(i) - i += 1 - -i = 0 -while True: - if i == 101: - break - print(i) - i += 1 - - -#斐波那契数列 - - -def fib(n) - a, b = 1,1 - for i in range(n-1): - a,b = b ,a+b - return a - - -#第三题 - -class ParamsError (Exception): - pass -def add(a, b): - return a + b -def sub(a, b): - return a - b -def mul(a, b): - return a * b -def div(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0!") - finally: - return("function my_sub end") -def zc(a, b): - try: - return a // b - except ZeroDivisionError: - raise ParamsError("取整分母不可以为0!") - finally: - return("function my_sub end") - - return a // b -def qy(a, b): - try: - return a % b - except ZeroDivisionError: - raise ParamsError("取余分母不可以为0!") - finally: - return a % b -def kf(a): - return a ** (1/2) -print("计算器") -choice = input ("输入运算选择:1,加法;2,减法;3,乘法;4,除法;5,整除;6,取余数;7,开方") -if choice == "1" : - tmp = input("请输入你要计算的数字:") - add(tmp) -elif choice == '2': - tmp = input("请输入你要计算的数字:") - sub(tmp) -elif choice == '3': - tmp = input("请输入你要计算的数字:") - mul(tmp) -elif choice == '4': - tmp = input("请输入你要计算的数字:") - div(tmp) -elif choice == '5': - tmp = input("请输入你要计算的数字:") - zc(tmp) -elif choice == '6': - tmp = input("请输入你要计算的数字:") - qy(tmp) -elif choice == '7': - tmp = input("请输入你要计算的数字:") - kf(tmp) -else: +#1 计数 +i = 0 +while i <6: + print(i) + i += 1 + +i = 0 +while True: + if i == 101: + break + print(i) + i += 1 + + +#斐波那契数列 + + +def fib(n) + a, b = 1,1 + for i in range(n-1): + a,b = b ,a+b + return a + + +#第三题 + +class ParamsError (Exception): + pass +def add(a, b): + return a + b +def sub(a, b): + return a - b +def mul(a, b): + return a * b +def div(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0!") + finally: + return("function my_sub end") +def zc(a, b): + try: + return a // b + except ZeroDivisionError: + raise ParamsError("取整分母不可以为0!") + finally: + return("function my_sub end") + + return a // b +def qy(a, b): + try: + return a % b + except ZeroDivisionError: + raise ParamsError("取余分母不可以为0!") + finally: + return a % b +def kf(a): + return a ** (1/2) +print("计算器") +choice = input ("输入运算选择:1,加法;2,减法;3,乘法;4,除法;5,整除;6,取余数;7,开方") +if choice == "1" : + tmp = input("请输入你要计算的数字:") + add(tmp) +elif choice == '2': + tmp = input("请输入你要计算的数字:") + sub(tmp) +elif choice == '3': + tmp = input("请输入你要计算的数字:") + mul(tmp) +elif choice == '4': + tmp = input("请输入你要计算的数字:") + div(tmp) +elif choice == '5': + tmp = input("请输入你要计算的数字:") + zc(tmp) +elif choice == '6': + tmp = input("请输入你要计算的数字:") + qy(tmp) +elif choice == '7': + tmp = input("请输入你要计算的数字:") + kf(tmp) +else: print("你输入的有误,请重新输入") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/3.3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/3.3.py" index b79cb2a8b67d7fd007284065fe7652b02b84fde4..8482245b5f347cd5b704be063a39d9f6435cabdc 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/3.3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/3.3.py" @@ -1,72 +1,72 @@ -#练习作用域之间的转换 -m_sub = 0 -def mult(a, b): - m_sub = a * b - print("函数内是局部变量:", m_sub) - return m_sub -print(mult(1, 2)) -print("函数外是全局变量:", m_sub) - -m_sub_1 = 1 -def func(): - global m_sub_1 - print(m_sub_1) - m_sub_1 = 2 - print(m_sub_1) -print(func()) -print(m_sub_1) - -def a(): - m_sub = 1 - def b(): - nonlocal m_sub - m_sub = 3 - print(m_sub) - return b - b() - print(m_sub) -a() -print("------") - -# 实现一个装饰器,用来输出函数的执行时间 -import time -def clock_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") - return result - return wrapper - -@clock_deco -def cool(a, b): - num = 0 - while True: - if num >= a ** b: - break - num += 1 - -cool(5, 10) -print("------") - -# 使用装饰器来为斐波那契函数增加缓存 -a = {} -def cache_deco(func): - global a - def wrap(n): - if n not in a: - a[n] = func(n) - return a[n] - return wrap - -@ cache_deco -def fib(n): - if n < 2: - return n - else: - return fib(n - 2) + fib(n - 1) - -print(fib(10)) -print(a) - +#练习作用域之间的转换 +m_sub = 0 +def mult(a, b): + m_sub = a * b + print("函数内是局部变量:", m_sub) + return m_sub +print(mult(1, 2)) +print("函数外是全局变量:", m_sub) + +m_sub_1 = 1 +def func(): + global m_sub_1 + print(m_sub_1) + m_sub_1 = 2 + print(m_sub_1) +print(func()) +print(m_sub_1) + +def a(): + m_sub = 1 + def b(): + nonlocal m_sub + m_sub = 3 + print(m_sub) + return b + b() + print(m_sub) +a() +print("------") + +# 实现一个装饰器,用来输出函数的执行时间 +import time +def clock_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") + return result + return wrapper + +@clock_deco +def cool(a, b): + num = 0 + while True: + if num >= a ** b: + break + num += 1 + +cool(5, 10) +print("------") + +# 使用装饰器来为斐波那契函数增加缓存 +a = {} +def cache_deco(func): + global a + def wrap(n): + if n not in a: + a[n] = func(n) + return a[n] + return wrap + +@ cache_deco +def fib(n): + if n < 2: + return n + else: + return fib(n - 2) + fib(n - 1) + +print(fib(10)) +print(a) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/3.2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/3.2.py" index f82ef895d2d474087dd51482a757ac0cbe98abf8..52f68291d67fcfef5a0f5b17cb358782868e2c81 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/3.2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\270\211\345\221\250---\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/3.2.py" @@ -1,37 +1,37 @@ -from pprint import pprint - -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -classes.sort(key=lambda x: x['grade']) # 1. 根据 grade 排序 -pprint(classes) - -f = filter(lambda x: x['grade'] == 'A', classes) # 2. 筛选出 grade 为 A 的同学 -pprint(list(f)) - - -def age_add(a): - return a['age'] + 1 - - -c = map(age_add, classes) # 3. 将上述 age + 1 -pprint(list(c)) - - - -#重构斐波那契数列 -def f(n): - - if n <= 1: - return n - return f(n - 1) + f(n - 2) - - -for i in range(13): - print(f(i)) +from pprint import pprint + +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +classes.sort(key=lambda x: x['grade']) # 1. 根据 grade 排序 +pprint(classes) + +f = filter(lambda x: x['grade'] == 'A', classes) # 2. 筛选出 grade 为 A 的同学 +pprint(list(f)) + + +def age_add(a): + return a['age'] + 1 + + +c = map(age_add, classes) # 3. 将上述 age + 1 +pprint(list(c)) + + + +#重构斐波那契数列 +def f(n): + + if n <= 1: + return n + return f(n - 1) + f(n - 2) + + +for i in range(13): + print(f(i)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\200\350\212\202/9.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\200\350\212\202/9.1.py" index 96e7f877ca0c4b35cfc8ec44d34086bf93fdac20..27c9c6dbbd21b5c3fe0b0a999d7701cd8b4995be 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\200\350\212\202/9.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\200\350\212\202/9.1.py" @@ -1,55 +1,55 @@ -import requests -import json -#from urllib.parse import quote, unquote #urlencode -#print(“鼠标") -def request_jd(keyword): - f = open("search information.html", "w", encoding="utf-8") - url = "https://search.jd.com/Search" - params = { - "keyword" : keyword - } - headers = { - "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" - } - response = requests.get(url=url, params=params, headers=headers) - f.write(response.text) - f.close() - print(response.text) - - -if __name__ == "__main__": - i = ["鼠标","键盘","主机","显示器","ipad","显卡","电竞椅", "VR","游戏机", "笔记本"] - for a in i: - request_jd(a) - -#详情页面 -def request_jd(keyword): - f = open("detailled information.html", "w", encoding="utf-8") - url = "https://search.jd.com/Search" - params = { - "keyword" : keyword - } - headers = { - "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" - } - response = requests.get(url=url, params=params, headers=headers) - f.write(response.text) - f.close() - print(response.text) - - -if __name__ == "__main__": - request_jd(a) - - - -# -test_dict = { - "a": 1, - "b": ["1", 2, None], - "c": {"d": 1} -} - -json_data = json.dumps(test_dict) -print(type(json_data), json_data) +import requests +import json +#from urllib.parse import quote, unquote #urlencode +#print(“鼠标") +def request_jd(keyword): + f = open("search information.html", "w", encoding="utf-8") + url = "https://search.jd.com/Search" + params = { + "keyword" : keyword + } + headers = { + "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" + } + response = requests.get(url=url, params=params, headers=headers) + f.write(response.text) + f.close() + print(response.text) + + +if __name__ == "__main__": + i = ["鼠标","键盘","主机","显示器","ipad","显卡","电竞椅", "VR","游戏机", "笔记本"] + for a in i: + request_jd(a) + +#详情页面 +def request_jd(keyword): + f = open("detailled information.html", "w", encoding="utf-8") + url = "https://search.jd.com/Search" + params = { + "keyword" : keyword + } + headers = { + "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" + } + response = requests.get(url=url, params=params, headers=headers) + f.write(response.text) + f.close() + print(response.text) + + +if __name__ == "__main__": + request_jd(a) + + + +# +test_dict = { + "a": 1, + "b": ["1", 2, None], + "c": {"d": 1} +} + +json_data = json.dumps(test_dict) +print(type(json_data), json_data) print(json.loads(json_data)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\211\350\212\202/Search1.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\211\350\212\202/Search1.html" index 7e4fe4aca0f31537120de8196afcca26e066cb48..30780f4955cac18578c31669f225ce4b49dbabf7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\211\350\212\202/Search1.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255---\351\231\266\345\206\266---\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232 -\347\254\254\344\270\211\350\212\202/Search1.html" @@ -135,145 +135,145 @@ SEARCH.base_url="keyword=%E9%BC%A0%E6%A0%87&wq=%E9%BC%A0%E6%A0%87"; - -
                  -
                  - - - -
                  -
                  -
                  -
                  -
                  - -
                  -
                  -
                    -
                    - - -
                    -
                    -
                    -
                    - - - 我的购物车 -
                    -
                    -
                    -
                    - -
                    -
                    -
                    -
                    - -
                    - + +
                    +
                    + + + +
                    +
                    +
                    +
                    +
                    + +
                    +
                    +
                      +
                      + + +
                      +
                      +
                      +
                      + + + 我的购物车 +
                      +
                      +
                      +
                      + +
                      +
                      +
                      +
                      + +
                      +
                      @@ -6138,252 +6138,252 @@ href="//item.jd.com/100002304436.html#comment"
                      - -
                      -
                      -
                        -
                      1. - 品类齐全,轻松购物 -
                      2. -
                      3. - 多仓直发,极速配送 -
                      4. -
                      5. - 正品行货,精致服务 -
                      6. -
                      7. - 天天低价,畅选无忧 -
                      8. -
                      -
                      -
                      -
                      -
                      -
                      -
                      购物指南
                      -
                      - 购物流程 -
                      -
                      - 会员介绍 -
                      -
                      - 生活旅行/团购 -
                      -
                      - 常见问题 -
                      -
                      - 大家电 -
                      -
                      - 联系客服 -
                      -
                      -
                      -
                      配送方式
                      -
                      - 上门自提 -
                      -
                      - 211限时达 -
                      -
                      - 配送服务查询 -
                      -
                      - 配送费收取标准 -
                      -
                      - 海外配送 -
                      -
                      -
                      -
                      支付方式
                      -
                      - 货到付款 -
                      -
                      - 在线支付 -
                      -
                      - 分期付款 -
                      -
                      - 公司转账 -
                      -
                      -
                      -
                      售后服务
                      -
                      - 售后政策 -
                      -
                      - 价格保护 -
                      -
                      - 退款说明 -
                      -
                      - 返修/退换货 -
                      -
                      - 取消订单 -
                      -
                      -
                      -
                      特色服务
                      -
                      - 夺宝岛 -
                      -
                      - DIY装机 -
                      -
                      - 延保服务 -
                      -
                      - 京东E卡 -
                      -
                      - 京东通信 -
                      -
                      - 京鱼座智能 -
                      -
                      - -
                      -
                      -
                      -
                      - - -
                      - - + 可信网站信用评估 + 网络警察提醒你 + 诚信网站 + 网上有害信息举报专区 + 网络举报APP下载 +

                      +
                      + +
                      + + - - - - - - - - -
                      -
                      - - - -
                      -
                      -
                      - - - -
                      -
                      - -
                      -
                      -
                      - -
                      - -
                      -
                      -
                      -
                      - -
                      -
                        -
                        - - - -
                        -
                        -
                        -
                        - - > - 我的购物车 -
                        -
                        -
                        -
                        - -
                        -
                        -
                        -
                        - - -
                        - - - -
                        -
                        -
                        - -
                        >
                        - -
                        >
                        - -
                        >
                        - -
                        >
                        -
                        AppleiPhone 11
                        -
                        -
                        -
                        - - 自营 - -
                        -
                        - -
                        -
                        -
                        -
                        -
                        -
                        -
                        - -
                        -
                        -
                        -
                        -
                        -
                        客服
                        -
                        -
                        -
                        -
                        -
                        -
                        - -
                        -
                        -
                        - 关注微店 -

                        关注微店

                        -
                        -
                        -
                        -

                        手机下单

                        -
                        -
                        - -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                          -
                        • - -
                        • -
                        - Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待 - -
                        -
                        - -
                        -
                        - -
                        - -
                        - - -
                        -
                          -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        • -
                        -
                        -
                        - - -
                        -
                        -
                        -
                        - Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                        -
                        -
                        -
                        -
                        - -
                        -
                        -
                        -
                        京 东 价
                        -
                        - - - - - 降价通知 -
                        - - - - fans - -
                        - - - - - - - - - - -
                        -
                        - - - -
                        -
                        -

                        累计评价

                        - 0 -
                        -
                        -
                        -
                        -
                        -
                        促  销
                        -
                        -
                        - - - - - - - - - - -
                        - 展开促销 - -
                        -
                        -
                        -
                        -
                        -
                        -
                        - -
                        - -
                        -
                        增值业务
                        -
                        -
                          -
                        -
                        -
                        -
                        -
                        配 送 至
                        -
                        -
                        -
                        -
                        -
                        -
                        --请选择--
                        - -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        -
                        支持
                        -
                        -
                          - -
                          -
                          -
                          -
                          -
                          -
                          - - - - -
                          - -
                          -
                          -
                          选择颜色
                          - -
                          -
                          -
                          选择版本
                          -
                          -
                          - - - 64GB -
                          -
                          - - - 128GB -
                          -
                          - - - 256GB -
                          -
                          -
                          - - -
                          - - - - - - - - - - - -
                          - -
                          -
                          本地活动
                          -
                          -
                            -
                            -
                            - -
                            -
                            -
                            -
                            - - -
                            -
                            -
                            -

                            为你推荐

                            -
                            -
                            -
                            -
                            -
                            - -
                            - -
                            -
                            -
                            - -
                            -
                            -
                            -
                              -
                            • 人气配件
                            • -
                            -
                            -
                            -
                            - -
                            -
                            -
                            - - -
                            -
                            -
                              -
                              -
                              -
                              - -
                              -
                              已选择0个配件
                              -
                              - 组合价 - ¥暂无报价 -
                              - - 配件选购中心 - = -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                                -
                              • 店长推荐
                              • -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              - -
                              -
                              - - - - -
                              -
                              -
                              -
                              -
                                -
                              • 店铺热销
                              • -
                              • 热门关注
                              • -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              - -
                              - -
                              -
                              - -
                              -
                              -
                              -
                              -
                              -
                              -
                                -
                              • 商品介绍
                              • -
                              • 规格与包装
                              • -
                              • 质检报告
                              • -
                              • 售后保障
                              • -
                              • 商品评价
                              • -
                              • - 手机社区
                              • -
                              • 京东试用new
                              • -
                              -
                              -
                              -
                              -
                              - -
                              -
                              -
                              - -
                              -
                              -
                              Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                              -
                              - X -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                              -
                                -
                              -
                                -
                              • 品牌: Apple - -
                              • -
                              -
                                -
                              • 商品名称:AppleiPhone 11
                              • -
                              • 商品编号:100008348542
                              • -
                              • 商品毛重:368.00g
                              • -
                              • 商品产地:中国大陆
                              • -
                              • CPU型号:其他
                              • -
                              • 运行内存:其他
                              • -
                              • 机身存储:128GB
                              • -
                              • 存储卡:不支持存储卡
                              • -
                              • 摄像头数量:后置双摄
                              • -
                              • 后摄主摄像素:1200万像素
                              • -
                              • 前摄主摄像素:1200万像素
                              • -
                              • 主屏幕尺寸(英寸):6.1英寸
                              • -
                              • 分辨率:其它分辨率
                              • -
                              • 屏幕比例:其它屏幕比例
                              • -
                              • 屏幕前摄组合:刘海屏
                              • -
                              • 充电器:其他
                              • -
                              • 热点:人脸识别
                              • -
                              • 特殊功能:语音命令
                              • -
                              • 操作系统:iOS(Apple)
                              • -
                              -

                              - 更多参数>> -

                              -
                              - -
                              -
                              -
                              -
                              -
                              - -
                              -
                              -
                              - -
                              -
                              -
                              -
                              商品介绍加载中...
                              -
                              - -
                              -
                              -
                              -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -

                                主体

                                -
                                -
                                -
                                产品名称
                                iPhone 11
                                -
                                -
                                -
                                上市月份
                                9月
                                -
                                -
                                -
                                上市年份
                                2019年
                                -
                                -
                                -
                                品牌
                                Apple
                                -
                                -
                                -
                                首销日期
                                以官网信息为准
                                -
                                -
                                -
                                入网型号
                                -
                                - -
                                -
                                -
                                -

                                工业代号或者入网型号

                                -
                                -
                                -
                                -
                                A2223
                                -
                                -
                                -
                                -
                                -

                                基本信息

                                -
                                -
                                -
                                机身宽度(mm)
                                75.7
                                -
                                -
                                -
                                机身厚度(mm)
                                8.3
                                -
                                -
                                -
                                机身重量(g)
                                194
                                -
                                -
                                -
                                运营商标志或内容
                                -
                                - -
                                -
                                -
                                -

                                定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                机身材质分类
                                玻璃后盖
                                -
                                -
                                -
                                机身长度(mm)
                                150.9
                                -
                                -
                                -
                                机身材质工艺
                                玻璃搭配铝金属设计
                                -
                                -
                                -
                                -
                                -

                                主芯片

                                -
                                -
                                -
                                CPU品牌
                                以官网信息为准
                                -
                                -
                                -
                                -
                                -

                                屏幕

                                -
                                -
                                -
                                主屏幕尺寸(英寸)
                                6.1英寸
                                -
                                -
                                -
                                屏幕像素密度(ppi)
                                -
                                - -
                                -
                                -
                                -

                                格式: 320PPI

                                -
                                -
                                -
                                -
                                326
                                -
                                -
                                -
                                屏幕材质类型
                                LCD
                                -
                                -
                                -
                                屏幕刷新率
                                其他
                                -
                                -
                                -
                                -
                                -

                                后置摄像头

                                -
                                -
                                -
                                闪光灯
                                其他闪光灯
                                -
                                -
                                -
                                后摄主摄光圈
                                f/2.4
                                -
                                -
                                -
                                拍照特点
                                数码变焦;光学防抖;HDR
                                -
                                -
                                -
                                后摄主摄光学防抖
                                支持光学防抖
                                -
                                -
                                -
                                -
                                -

                                前置摄像头

                                -
                                -
                                -
                                拍照特点
                                数码变焦;人像模式;HDR
                                -
                                -
                                -
                                前摄主摄光圈
                                f/2.2
                                -
                                -
                                -
                                -
                                -

                                电池信息

                                -
                                -
                                -
                                电池是否可拆卸
                                -
                                - -
                                -
                                -
                                -

                                不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                -
                                -
                                -
                                -
                                电池不可拆卸
                                -
                                -
                                -
                                无线充电
                                -
                                - -
                                -
                                -
                                -

                                无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                -
                                -
                                -
                                -
                                支持无线充电
                                -
                                -
                                -
                                充电器
                                其他
                                -
                                -
                                -
                                -
                                -

                                网络支持

                                -
                                -
                                -
                                网络频率(2G/3G)
                                以官网信息为准
                                -
                                -
                                -
                                最大支持SIM卡数量
                                2个
                                -
                                -
                                -
                                SIM卡类型
                                -
                                - -
                                -
                                -
                                -

                                sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                -
                                -
                                -
                                -
                                Nano SIM
                                -
                                -
                                -
                                4G网络
                                -
                                - -
                                -
                                -
                                -

                                单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                -
                                -
                                -
                                -
                                4G FDD-LTE(联通);4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                -
                                -
                                -
                                3G/2G网络
                                3G TD-SCDMA(移动);3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                -
                                -
                                -
                                5G网络
                                不支持5G
                                -
                                -
                                -
                                双卡机类型
                                双卡双待
                                -
                                -
                                -
                                -
                                -

                                数据接口

                                -
                                -
                                -
                                数据传输接口
                                其他
                                -
                                -
                                -
                                NFC/NFC模式
                                支持(读卡器模式)
                                -
                                -
                                -
                                充电接口类型
                                Lightning(iPhone)
                                -
                                -
                                -
                                耳机接口类型
                                Lightning
                                -
                                -
                                -
                                -
                                -

                                手机特性

                                -
                                -
                                -
                                三防标准
                                IP68
                                -
                                -
                                -
                                生物识别
                                人脸识别
                                -
                                -
                                -
                                -
                                -

                                辅助功能

                                -
                                -
                                -
                                常用功能
                                重力感应;语音识别
                                -
                                -
                                -
                                -
                                -
                                -

                                包装清单

                                -

                                iPhone*1、USB-C 转闪电连接线*1、资料*1

                                -
                                -
                                -
                                - -
                                -
                                - -
                                -
                                - -
                                -
                                - -
                                -
                                -
                                -
                                - -
                                -
                                -

                                售后保障

                                -
                                -
                                - -
                                -
                                -
                                -
                                -

                                商品评价

                                -
                                -
                                -
                                -
                                -
                                - -
                                -
                                -
                                推荐排序
                                -
                                -
                                推荐排序
                                -
                                  -
                                • 推荐排序
                                • -
                                • 时间排序
                                • -
                                -
                                -
                                -
                                -
                                -
                                -
                                全部评论
                                -
                                正在加载中,请稍候...
                                -
                                正在加载中,请稍候...
                                -
                                正在加载中,请稍候...
                                -
                                正在加载中,请稍候...
                                -
                                -
                                -
                                -
                                -
                                -
                                -

                                商品问答

                                -
                                -
                                -
                                - 心中疑惑就问问买过此商品的同学吧~我要提问 -
                                -
                                -
                                -
                                -
                                -
                                - -
                                -
                                -
                                -

                                购买咨询

                                -
                                - -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                -
                                  -
                                • 全部
                                • -
                                • 商品咨询
                                • -
                                • 库存配送
                                • -
                                • 支付
                                • -
                                • 发票保修
                                • -
                                • -
                                -
                                -
                                - -
                                -
                                -
                                -
                                -
                                - -
                                -
                                -
                                -
                                - - - - - - - -
                                - - - - - - -
                                - - - - + + + + + + 【AppleiPhone 11】Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待【行情 报价 价格 评测】-京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                +
                                + + + +
                                +
                                +
                                + + + +
                                +
                                + +
                                +
                                +
                                + +
                                + +
                                +
                                +
                                +
                                + +
                                +
                                  +
                                  + + + +
                                  +
                                  +
                                  +
                                  + + > + 我的购物车 +
                                  +
                                  +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  + + +
                                  + + + +
                                  +
                                  +
                                  + +
                                  >
                                  + +
                                  >
                                  + +
                                  >
                                  + +
                                  >
                                  +
                                  AppleiPhone 11
                                  +
                                  +
                                  +
                                  + + 自营 + +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  客服
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  + +
                                  +
                                  +
                                  + 关注微店 +

                                  关注微店

                                  +
                                  +
                                  +
                                  +

                                  手机下单

                                  +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                    +
                                  • + +
                                  • +
                                  + Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待 + +
                                  +
                                  + +
                                  +
                                  + +
                                  + +
                                  + + +
                                  +
                                    +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  • Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  • +
                                  +
                                  +
                                  + + +
                                  +
                                  +
                                  +
                                  + Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                  +
                                  +
                                  +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  京 东 价
                                  +
                                  + + + + + 降价通知 +
                                  + + + + fans + +
                                  + + + + + + + + + + +
                                  +
                                  + + + +
                                  +
                                  +

                                  累计评价

                                  + 0 +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  促  销
                                  +
                                  +
                                  + + + + + + + + + + +
                                  + 展开促销 + +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  + +
                                  + +
                                  +
                                  增值业务
                                  +
                                  +
                                    +
                                  +
                                  +
                                  +
                                  +
                                  配 送 至
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  --请选择--
                                  + +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  支持
                                  +
                                  +
                                    + +
                                    +
                                    +
                                    +
                                    +
                                    +
                                    + + + + +
                                    + +
                                    +
                                    +
                                    选择颜色
                                    + +
                                    +
                                    +
                                    选择版本
                                    +
                                    +
                                    + + + 64GB +
                                    +
                                    + + + 128GB +
                                    +
                                    + + + 256GB +
                                    +
                                    +
                                    + + +
                                    + + + + + + + + + + + +
                                    + +
                                    +
                                    本地活动
                                    +
                                    +
                                      +
                                      +
                                      + +
                                      +
                                      +
                                      +
                                      + + +
                                      +
                                      +
                                      +

                                      为你推荐

                                      +
                                      +
                                      +
                                      +
                                      +
                                      + +
                                      + +
                                      +
                                      +
                                      + +
                                      +
                                      +
                                      +
                                        +
                                      • 人气配件
                                      • +
                                      +
                                      +
                                      +
                                      + +
                                      +
                                      +
                                      + + +
                                      +
                                      +
                                        +
                                        +
                                        +
                                        + +
                                        +
                                        已选择0个配件
                                        +
                                        + 组合价 + ¥暂无报价 +
                                        + + 配件选购中心 + = +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                          +
                                        • 店长推荐
                                        • +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        + +
                                        +
                                        + + + + +
                                        +
                                        +
                                        +
                                        +
                                          +
                                        • 店铺热销
                                        • +
                                        • 热门关注
                                        • +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        + +
                                        + +
                                        +
                                        + +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                          +
                                        • 商品介绍
                                        • +
                                        • 规格与包装
                                        • +
                                        • 质检报告
                                        • +
                                        • 售后保障
                                        • +
                                        • 商品评价
                                        • +
                                        • + 手机社区
                                        • +
                                        • 京东试用new
                                        • +
                                        +
                                        +
                                        +
                                        +
                                        + +
                                        +
                                        +
                                        + +
                                        +
                                        +
                                        Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待
                                        +
                                        + X +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        +
                                          +
                                        +
                                          +
                                        • 品牌: Apple + +
                                        • +
                                        +
                                          +
                                        • 商品名称:AppleiPhone 11
                                        • +
                                        • 商品编号:100008348542
                                        • +
                                        • 商品毛重:368.00g
                                        • +
                                        • 商品产地:中国大陆
                                        • +
                                        • CPU型号:其他
                                        • +
                                        • 运行内存:其他
                                        • +
                                        • 机身存储:128GB
                                        • +
                                        • 存储卡:不支持存储卡
                                        • +
                                        • 摄像头数量:后置双摄
                                        • +
                                        • 后摄主摄像素:1200万像素
                                        • +
                                        • 前摄主摄像素:1200万像素
                                        • +
                                        • 主屏幕尺寸(英寸):6.1英寸
                                        • +
                                        • 分辨率:其它分辨率
                                        • +
                                        • 屏幕比例:其它屏幕比例
                                        • +
                                        • 屏幕前摄组合:刘海屏
                                        • +
                                        • 充电器:其他
                                        • +
                                        • 热点:人脸识别
                                        • +
                                        • 特殊功能:语音命令
                                        • +
                                        • 操作系统:iOS(Apple)
                                        • +
                                        +

                                        + 更多参数>> +

                                        +
                                        + +
                                        +
                                        +
                                        +
                                        +
                                        + +
                                        +
                                        +
                                        + +
                                        +
                                        +
                                        +
                                        商品介绍加载中...
                                        +
                                        + +
                                        +
                                        +
                                        +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +

                                          主体

                                          +
                                          +
                                          +
                                          产品名称
                                          iPhone 11
                                          +
                                          +
                                          +
                                          上市月份
                                          9月
                                          +
                                          +
                                          +
                                          上市年份
                                          2019年
                                          +
                                          +
                                          +
                                          品牌
                                          Apple
                                          +
                                          +
                                          +
                                          首销日期
                                          以官网信息为准
                                          +
                                          +
                                          +
                                          入网型号
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          工业代号或者入网型号

                                          +
                                          +
                                          +
                                          +
                                          A2223
                                          +
                                          +
                                          +
                                          +
                                          +

                                          基本信息

                                          +
                                          +
                                          +
                                          机身宽度(mm)
                                          75.7
                                          +
                                          +
                                          +
                                          机身厚度(mm)
                                          8.3
                                          +
                                          +
                                          +
                                          机身重量(g)
                                          194
                                          +
                                          +
                                          +
                                          运营商标志或内容
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          机身材质分类
                                          玻璃后盖
                                          +
                                          +
                                          +
                                          机身长度(mm)
                                          150.9
                                          +
                                          +
                                          +
                                          机身材质工艺
                                          玻璃搭配铝金属设计
                                          +
                                          +
                                          +
                                          +
                                          +

                                          主芯片

                                          +
                                          +
                                          +
                                          CPU品牌
                                          以官网信息为准
                                          +
                                          +
                                          +
                                          +
                                          +

                                          屏幕

                                          +
                                          +
                                          +
                                          主屏幕尺寸(英寸)
                                          6.1英寸
                                          +
                                          +
                                          +
                                          屏幕像素密度(ppi)
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          格式: 320PPI

                                          +
                                          +
                                          +
                                          +
                                          326
                                          +
                                          +
                                          +
                                          屏幕材质类型
                                          LCD
                                          +
                                          +
                                          +
                                          屏幕刷新率
                                          其他
                                          +
                                          +
                                          +
                                          +
                                          +

                                          后置摄像头

                                          +
                                          +
                                          +
                                          闪光灯
                                          其他闪光灯
                                          +
                                          +
                                          +
                                          后摄主摄光圈
                                          f/2.4
                                          +
                                          +
                                          +
                                          拍照特点
                                          数码变焦;光学防抖;HDR
                                          +
                                          +
                                          +
                                          后摄主摄光学防抖
                                          支持光学防抖
                                          +
                                          +
                                          +
                                          +
                                          +

                                          前置摄像头

                                          +
                                          +
                                          +
                                          拍照特点
                                          数码变焦;人像模式;HDR
                                          +
                                          +
                                          +
                                          前摄主摄光圈
                                          f/2.2
                                          +
                                          +
                                          +
                                          +
                                          +

                                          电池信息

                                          +
                                          +
                                          +
                                          电池是否可拆卸
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                          +
                                          +
                                          +
                                          +
                                          电池不可拆卸
                                          +
                                          +
                                          +
                                          无线充电
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                          +
                                          +
                                          +
                                          +
                                          支持无线充电
                                          +
                                          +
                                          +
                                          充电器
                                          其他
                                          +
                                          +
                                          +
                                          +
                                          +

                                          网络支持

                                          +
                                          +
                                          +
                                          网络频率(2G/3G)
                                          以官网信息为准
                                          +
                                          +
                                          +
                                          最大支持SIM卡数量
                                          2个
                                          +
                                          +
                                          +
                                          SIM卡类型
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                          +
                                          +
                                          +
                                          +
                                          Nano SIM
                                          +
                                          +
                                          +
                                          4G网络
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                          +
                                          +
                                          +
                                          +
                                          4G FDD-LTE(联通);4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                          +
                                          +
                                          +
                                          3G/2G网络
                                          3G TD-SCDMA(移动);3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                          +
                                          +
                                          +
                                          5G网络
                                          不支持5G
                                          +
                                          +
                                          +
                                          双卡机类型
                                          双卡双待
                                          +
                                          +
                                          +
                                          +
                                          +

                                          数据接口

                                          +
                                          +
                                          +
                                          数据传输接口
                                          其他
                                          +
                                          +
                                          +
                                          NFC/NFC模式
                                          支持(读卡器模式)
                                          +
                                          +
                                          +
                                          充电接口类型
                                          Lightning(iPhone)
                                          +
                                          +
                                          +
                                          耳机接口类型
                                          Lightning
                                          +
                                          +
                                          +
                                          +
                                          +

                                          手机特性

                                          +
                                          +
                                          +
                                          三防标准
                                          IP68
                                          +
                                          +
                                          +
                                          生物识别
                                          人脸识别
                                          +
                                          +
                                          +
                                          +
                                          +

                                          辅助功能

                                          +
                                          +
                                          +
                                          常用功能
                                          重力感应;语音识别
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +

                                          包装清单

                                          +

                                          iPhone*1、USB-C 转闪电连接线*1、资料*1

                                          +
                                          +
                                          +
                                          + +
                                          +
                                          + +
                                          +
                                          + +
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          + +
                                          +
                                          +

                                          售后保障

                                          +
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          +

                                          商品评价

                                          +
                                          +
                                          +
                                          +
                                          +
                                          + +
                                          +
                                          +
                                          推荐排序
                                          +
                                          +
                                          推荐排序
                                          +
                                            +
                                          • 推荐排序
                                          • +
                                          • 时间排序
                                          • +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          全部评论
                                          +
                                          正在加载中,请稍候...
                                          +
                                          正在加载中,请稍候...
                                          +
                                          正在加载中,请稍候...
                                          +
                                          正在加载中,请稍候...
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +

                                          商品问答

                                          +
                                          +
                                          +
                                          + 心中疑惑就问问买过此商品的同学吧~我要提问 +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          + +
                                          +
                                          +
                                          +

                                          购买咨询

                                          +
                                          + +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          +
                                            +
                                          • 全部
                                          • +
                                          • 商品咨询
                                          • +
                                          • 库存配送
                                          • +
                                          • 支付
                                          • +
                                          • 发票保修
                                          • +
                                          • +
                                          +
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          + + + + + + + +
                                          + + + + + + +
                                          + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/OPPO A52 5000mAh\350\266\205\345\244\247\347\224\265\346\261\240 \351\225\277\347\273\255\350\210\252 18W\347\226\276\351\200\237\345\277\253\345\205\205 \346\230\237\351\230\265AI\345\233\233\346\221\204 \347\276\216\351\242\234\346\213\215\347\205\247\346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 8GB+128GB \346\230\237\350\200\200\347\231\275-\350\257\246\346\203\205.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/OPPO A52 5000mAh\350\266\205\345\244\247\347\224\265\346\261\240 \351\225\277\347\273\255\350\210\252 18W\347\226\276\351\200\237\345\277\253\345\205\205 \346\230\237\351\230\265AI\345\233\233\346\221\204 \347\276\216\351\242\234\346\213\215\347\205\247\346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 8GB+128GB \346\230\237\350\200\200\347\231\275-\350\257\246\346\203\205.html" index f924d34134bb7448563e2df29cb710c0547e0f26..592b0f40fc4e55aeb116188bd330ca02ea8539de 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/OPPO A52 5000mAh\350\266\205\345\244\247\347\224\265\346\261\240 \351\225\277\347\273\255\350\210\252 18W\347\226\276\351\200\237\345\277\253\345\205\205 \346\230\237\351\230\265AI\345\233\233\346\221\204 \347\276\216\351\242\234\346\213\215\347\205\247\346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 8GB+128GB \346\230\237\350\200\200\347\231\275-\350\257\246\346\203\205.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/OPPO A52 5000mAh\350\266\205\345\244\247\347\224\265\346\261\240 \351\225\277\347\273\255\350\210\252 18W\347\226\276\351\200\237\345\277\253\345\205\205 \346\230\237\351\230\265AI\345\233\233\346\221\204 \347\276\216\351\242\234\346\213\215\347\205\247\346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 8GB+128GB \346\230\237\350\200\200\347\231\275-\350\257\246\346\203\205.html" @@ -1,3690 +1,3690 @@ - - - - - - 【OPPOA52】OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白【行情 报价 价格 评测】-京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                          -
                                          - - - -
                                          -
                                          -
                                          - - - -
                                          -
                                          - -
                                          -
                                          -
                                          - -
                                          - -
                                          -
                                          -
                                          -
                                          - -
                                          -
                                            -
                                            - - - -
                                            -
                                            -
                                            -
                                            - - > - 我的购物车 -
                                            -
                                            -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            - - -
                                            - - - -
                                            -
                                            -
                                            - -
                                            >
                                            - -
                                            >
                                            - -
                                            >
                                            - -
                                            >
                                            -
                                            OPPOA52
                                            -
                                            -
                                            -
                                            - - 自营 - -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            客服
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            - -
                                            -
                                            -
                                            - 关注微店 -

                                            关注微店

                                            -
                                            -
                                            -
                                            -

                                            手机下单

                                            -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                              -
                                            - OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白 - -
                                            -
                                            - - -
                                            - - -
                                            -
                                              -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            • -
                                            -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            - 门店有售 - OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                            -
                                            -
                                            -
                                            -
                                            - -
                                            -
                                            -
                                            -
                                            京 东 价
                                            -
                                            - - - - - 降价通知 -
                                            - - - - fans - -
                                            - - - - - - - - - - -
                                            -
                                            - - - -
                                            -
                                            -

                                            累计评价

                                            - 0 -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            促  销
                                            -
                                            -
                                            - - - - - - - - - - -
                                            - 展开促销 - -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            - -
                                            - -
                                            -
                                            增值业务
                                            -
                                            -
                                              -
                                            -
                                            -
                                            -
                                            -
                                            配 送 至
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            --请选择--
                                            - -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            -
                                            支持
                                            -
                                            -
                                              - -
                                              -
                                              -
                                              -
                                              -
                                              -
                                              - - - - -
                                              - -
                                              -
                                              -
                                              选择颜色
                                              - -
                                              - -
                                              - - - - - - - - - - - -
                                              - -
                                              -
                                              本地活动
                                              -
                                              -
                                                -
                                                -
                                                - -
                                                -
                                                -
                                                -
                                                - - -
                                                -
                                                -
                                                -

                                                为你推荐

                                                -
                                                -
                                                -
                                                -
                                                -
                                                - -
                                                - -
                                                -
                                                -
                                                - -
                                                -
                                                -
                                                -
                                                  -
                                                • 人气配件
                                                • -
                                                -
                                                -
                                                -
                                                - -
                                                -
                                                -
                                                - - -
                                                -
                                                -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  已选择0个配件
                                                  -
                                                  - 组合价 - ¥暂无报价 -
                                                  - - 配件选购中心 - = -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                    -
                                                  • 店长推荐
                                                  • -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  - -
                                                  - -
                                                  -
                                                  -
                                                  -

                                                  手机热销榜

                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                    -
                                                  • 同价位
                                                  • -
                                                  • 同品牌
                                                  • -
                                                  • 总排行
                                                  • -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                    -
                                                  • 商品介绍
                                                  • -
                                                  • 规格与包装
                                                  • -
                                                  • 质检报告
                                                  • -
                                                  • 售后保障
                                                  • -
                                                  • 商品评价
                                                  • -
                                                  • - 手机社区
                                                  • -
                                                  • 京东试用new
                                                  • -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                  -
                                                  - X -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  -
                                                    -
                                                  -
                                                    -
                                                  • 品牌: OPPO - -
                                                  • -
                                                  -
                                                    -
                                                  • 商品名称:OPPOA52
                                                  • -
                                                  • 商品编号:100012725248
                                                  • -
                                                  • 商品毛重:480.00g
                                                  • -
                                                  • 商品产地:中国大陆
                                                  • -
                                                  • CPU型号:骁龙665
                                                  • -
                                                  • 运行内存:8GB
                                                  • -
                                                  • 机身存储:128GB
                                                  • -
                                                  • 存储卡:支持MicroSD(TF)
                                                  • -
                                                  • 摄像头数量:后置四摄
                                                  • -
                                                  • 后摄主摄像素:1200万像素
                                                  • -
                                                  • 前摄主摄像素:800万像素
                                                  • -
                                                  • 主屏幕尺寸(英寸):6.5英寸
                                                  • -
                                                  • 分辨率:其它分辨率
                                                  • -
                                                  • 屏幕比例:20.6~21:9
                                                  • -
                                                  • 屏幕前摄组合:正常屏幕
                                                  • -
                                                  • 充电器:9V/2A
                                                  • -
                                                  • 热点:快速充电,超高屏占比
                                                  • -
                                                  • 特殊功能:超大音量
                                                  • -
                                                  • 屏占比:≥90%
                                                  • -
                                                  • 充电功率:18-19W
                                                  • -
                                                  • 操作系统:Android(安卓)
                                                  • -
                                                  -

                                                  - 更多参数>> -

                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                  -
                                                  - -
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                  商品介绍加载中...
                                                  -
                                                  - -
                                                  -
                                                  -
                                                  -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    主体

                                                    -
                                                    -
                                                    -
                                                    产品名称
                                                    A52
                                                    -
                                                    -
                                                    -
                                                    上市月份
                                                    4月
                                                    -
                                                    -
                                                    -
                                                    上市年份
                                                    2020年
                                                    -
                                                    -
                                                    -
                                                    品牌
                                                    OPPO
                                                    -
                                                    -
                                                    -
                                                    首销日期
                                                    20日
                                                    -
                                                    -
                                                    -
                                                    入网型号
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    工业代号或者入网型号

                                                    -
                                                    -
                                                    -
                                                    -
                                                    PDAM10
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    基本信息

                                                    -
                                                    -
                                                    -
                                                    机身宽度(mm)
                                                    75.5
                                                    -
                                                    -
                                                    -
                                                    机身厚度(mm)
                                                    8.9
                                                    -
                                                    -
                                                    -
                                                    机身重量(g)
                                                    192
                                                    -
                                                    -
                                                    -
                                                    运营商标志或内容
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    机身材质分类
                                                    复合材料
                                                    -
                                                    -
                                                    -
                                                    机身长度(mm)
                                                    162
                                                    -
                                                    -
                                                    -
                                                    机身材质工艺
                                                    UV纹理+电镀+丝印油墨
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    主芯片

                                                    -
                                                    -
                                                    -
                                                    GPU型号
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    GPU英文全称GraphicProcessingUnit,中文翻译为图形处理器。

                                                    -
                                                    -
                                                    -
                                                    -
                                                    高通骁龙665
                                                    -
                                                    -
                                                    -
                                                    详细参数
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    文本录入,格式:4 x A73 2.2GHz + 4 x A53 1.7GHz,Mali-72

                                                    -
                                                    -
                                                    -
                                                    -
                                                    Adreno 610
                                                    -
                                                    -
                                                    -
                                                    CPU品牌
                                                    高通(Qualcomm)
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    屏幕

                                                    -
                                                    -
                                                    -
                                                    屏幕材质类型
                                                    TFT LCD(IPS)
                                                    -
                                                    -
                                                    -
                                                    屏幕刷新率
                                                    其他
                                                    -
                                                    -
                                                    -
                                                    主屏幕尺寸(英寸)
                                                    6.5英寸
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    后置摄像头

                                                    -
                                                    -
                                                    -
                                                    后摄主摄光圈
                                                    f/1.8
                                                    -
                                                    -
                                                    -
                                                    闪光灯
                                                    其他闪光灯
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    前置摄像头

                                                    -
                                                    -
                                                    -
                                                    前摄主摄光圈
                                                    f/2.0
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    电池信息

                                                    -
                                                    -
                                                    -
                                                    电池是否可拆卸
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                                    -
                                                    -
                                                    -
                                                    -
                                                    电池不可拆卸
                                                    -
                                                    -
                                                    -
                                                    无线充电
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                                    -
                                                    -
                                                    -
                                                    -
                                                    不支持反向无线充电
                                                    -
                                                    -
                                                    -
                                                    充电器
                                                    9V/2A
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    网络支持

                                                    -
                                                    -
                                                    -
                                                    网络频率(2G/3G)
                                                    以官网信息为准
                                                    -
                                                    -
                                                    -
                                                    最大支持SIM卡数量
                                                    2个
                                                    -
                                                    -
                                                    -
                                                    SIM卡类型
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                                    -
                                                    -
                                                    -
                                                    -
                                                    以官网信息为准
                                                    -
                                                    -
                                                    -
                                                    4G网络
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                                    -
                                                    -
                                                    -
                                                    -
                                                    4G FDD-LTE(联通);4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                                    -
                                                    -
                                                    -
                                                    3G/2G网络
                                                    3G TD-SCDMA(移动);3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                                    -
                                                    -
                                                    -
                                                    5G网络
                                                    不支持5G
                                                    -
                                                    -
                                                    -
                                                    双卡机类型
                                                    双卡双待
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    数据接口

                                                    -
                                                    -
                                                    -
                                                    数据传输接口
                                                    WIFI;WiFi热点
                                                    -
                                                    -
                                                    -
                                                    NFC/NFC模式
                                                    不支持NFC
                                                    -
                                                    -
                                                    -
                                                    充电接口类型
                                                    Type-C
                                                    -
                                                    -
                                                    -
                                                    耳机接口类型
                                                    3.5mm
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    辅助功能

                                                    -
                                                    -
                                                    -
                                                    常用功能
                                                    便签;计算器
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    包装清单

                                                    -

                                                    主机 x1 - -数据线 x1 - -充电器 x1 - -SIM卡通针x1 - -保护套x1 - -快速入门指南x1 - -保修卡x1

                                                    -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    - -
                                                    -
                                                    - -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -

                                                    售后保障

                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    商品评价

                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    推荐排序
                                                    -
                                                    -
                                                    推荐排序
                                                    -
                                                      -
                                                    • 推荐排序
                                                    • -
                                                    • 时间排序
                                                    • -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    全部评论
                                                    -
                                                    正在加载中,请稍候...
                                                    -
                                                    正在加载中,请稍候...
                                                    -
                                                    正在加载中,请稍候...
                                                    -
                                                    正在加载中,请稍候...
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -

                                                    商品问答

                                                    -
                                                    -
                                                    -
                                                    - 心中疑惑就问问买过此商品的同学吧~我要提问 -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -

                                                    购买咨询

                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    -
                                                      -
                                                    • 全部
                                                    • -
                                                    • 商品咨询
                                                    • -
                                                    • 库存配送
                                                    • -
                                                    • 支付
                                                    • -
                                                    • 发票保修
                                                    • -
                                                    • -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -
                                                    -
                                                    - -
                                                    -
                                                    -
                                                    -
                                                    - - - - - - - -
                                                    - - - - - - -
                                                    - - - - + + + + + + 【OPPOA52】OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白【行情 报价 价格 评测】-京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    +
                                                    + + + +
                                                    +
                                                    +
                                                    + + + +
                                                    +
                                                    + +
                                                    +
                                                    +
                                                    + +
                                                    + +
                                                    +
                                                    +
                                                    +
                                                    + +
                                                    +
                                                      +
                                                      + + + +
                                                      +
                                                      +
                                                      +
                                                      + + > + 我的购物车 +
                                                      +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      + + +
                                                      + + + +
                                                      +
                                                      +
                                                      + +
                                                      >
                                                      + +
                                                      >
                                                      + +
                                                      >
                                                      + +
                                                      >
                                                      +
                                                      OPPOA52
                                                      +
                                                      +
                                                      +
                                                      + + 自营 + +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      客服
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      + 关注微店 +

                                                      关注微店

                                                      +
                                                      +
                                                      +
                                                      +

                                                      手机下单

                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                        +
                                                      + OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白 + +
                                                      +
                                                      + + +
                                                      + + +
                                                      +
                                                        +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      • OPPO A52 5000mAh超大电池 长续航 18W疾速快充  星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      • +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      + 门店有售 + OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      京 东 价
                                                      +
                                                      + + + + + 降价通知 +
                                                      + + + + fans + +
                                                      + + + + + + + + + + +
                                                      +
                                                      + + + +
                                                      +
                                                      +

                                                      累计评价

                                                      + 0 +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      促  销
                                                      +
                                                      +
                                                      + + + + + + + + + + +
                                                      + 展开促销 + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + +
                                                      + +
                                                      +
                                                      增值业务
                                                      +
                                                      +
                                                        +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      配 送 至
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      --请选择--
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      支持
                                                      +
                                                      +
                                                        + +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        + + + + +
                                                        + +
                                                        +
                                                        +
                                                        选择颜色
                                                        + +
                                                        + +
                                                        + + + + + + + + + + + +
                                                        + +
                                                        +
                                                        本地活动
                                                        +
                                                        +
                                                          +
                                                          +
                                                          + +
                                                          +
                                                          +
                                                          +
                                                          + + +
                                                          +
                                                          +
                                                          +

                                                          为你推荐

                                                          +
                                                          +
                                                          +
                                                          +
                                                          +
                                                          + +
                                                          + +
                                                          +
                                                          +
                                                          + +
                                                          +
                                                          +
                                                          +
                                                            +
                                                          • 人气配件
                                                          • +
                                                          +
                                                          +
                                                          +
                                                          + +
                                                          +
                                                          +
                                                          + + +
                                                          +
                                                          +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            已选择0个配件
                                                            +
                                                            + 组合价 + ¥暂无报价 +
                                                            + + 配件选购中心 + = +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                              +
                                                            • 店长推荐
                                                            • +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            + +
                                                            + +
                                                            +
                                                            +
                                                            +

                                                            手机热销榜

                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                              +
                                                            • 同价位
                                                            • +
                                                            • 同品牌
                                                            • +
                                                            • 总排行
                                                            • +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                              +
                                                            • 商品介绍
                                                            • +
                                                            • 规格与包装
                                                            • +
                                                            • 质检报告
                                                            • +
                                                            • 售后保障
                                                            • +
                                                            • 商品评价
                                                            • +
                                                            • + 手机社区
                                                            • +
                                                            • 京东试用new
                                                            • +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            OPPO A52 5000mAh超大电池 长续航 18W疾速快充 星阵AI四摄 美颜拍照游戏智能手机 8GB+128GB 星耀白
                                                            +
                                                            + X +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                              +
                                                            +
                                                              +
                                                            • 品牌: OPPO + +
                                                            • +
                                                            +
                                                              +
                                                            • 商品名称:OPPOA52
                                                            • +
                                                            • 商品编号:100012725248
                                                            • +
                                                            • 商品毛重:480.00g
                                                            • +
                                                            • 商品产地:中国大陆
                                                            • +
                                                            • CPU型号:骁龙665
                                                            • +
                                                            • 运行内存:8GB
                                                            • +
                                                            • 机身存储:128GB
                                                            • +
                                                            • 存储卡:支持MicroSD(TF)
                                                            • +
                                                            • 摄像头数量:后置四摄
                                                            • +
                                                            • 后摄主摄像素:1200万像素
                                                            • +
                                                            • 前摄主摄像素:800万像素
                                                            • +
                                                            • 主屏幕尺寸(英寸):6.5英寸
                                                            • +
                                                            • 分辨率:其它分辨率
                                                            • +
                                                            • 屏幕比例:20.6~21:9
                                                            • +
                                                            • 屏幕前摄组合:正常屏幕
                                                            • +
                                                            • 充电器:9V/2A
                                                            • +
                                                            • 热点:快速充电,超高屏占比
                                                            • +
                                                            • 特殊功能:超大音量
                                                            • +
                                                            • 屏占比:≥90%
                                                            • +
                                                            • 充电功率:18-19W
                                                            • +
                                                            • 操作系统:Android(安卓)
                                                            • +
                                                            +

                                                            + 更多参数>> +

                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            商品介绍加载中...
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              主体

                                                              +
                                                              +
                                                              +
                                                              产品名称
                                                              A52
                                                              +
                                                              +
                                                              +
                                                              上市月份
                                                              4月
                                                              +
                                                              +
                                                              +
                                                              上市年份
                                                              2020年
                                                              +
                                                              +
                                                              +
                                                              品牌
                                                              OPPO
                                                              +
                                                              +
                                                              +
                                                              首销日期
                                                              20日
                                                              +
                                                              +
                                                              +
                                                              入网型号
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              工业代号或者入网型号

                                                              +
                                                              +
                                                              +
                                                              +
                                                              PDAM10
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              基本信息

                                                              +
                                                              +
                                                              +
                                                              机身宽度(mm)
                                                              75.5
                                                              +
                                                              +
                                                              +
                                                              机身厚度(mm)
                                                              8.9
                                                              +
                                                              +
                                                              +
                                                              机身重量(g)
                                                              192
                                                              +
                                                              +
                                                              +
                                                              运营商标志或内容
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              机身材质分类
                                                              复合材料
                                                              +
                                                              +
                                                              +
                                                              机身长度(mm)
                                                              162
                                                              +
                                                              +
                                                              +
                                                              机身材质工艺
                                                              UV纹理+电镀+丝印油墨
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              主芯片

                                                              +
                                                              +
                                                              +
                                                              GPU型号
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              GPU英文全称GraphicProcessingUnit,中文翻译为图形处理器。

                                                              +
                                                              +
                                                              +
                                                              +
                                                              高通骁龙665
                                                              +
                                                              +
                                                              +
                                                              详细参数
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              文本录入,格式:4 x A73 2.2GHz + 4 x A53 1.7GHz,Mali-72

                                                              +
                                                              +
                                                              +
                                                              +
                                                              Adreno 610
                                                              +
                                                              +
                                                              +
                                                              CPU品牌
                                                              高通(Qualcomm)
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              屏幕

                                                              +
                                                              +
                                                              +
                                                              屏幕材质类型
                                                              TFT LCD(IPS)
                                                              +
                                                              +
                                                              +
                                                              屏幕刷新率
                                                              其他
                                                              +
                                                              +
                                                              +
                                                              主屏幕尺寸(英寸)
                                                              6.5英寸
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              后置摄像头

                                                              +
                                                              +
                                                              +
                                                              后摄主摄光圈
                                                              f/1.8
                                                              +
                                                              +
                                                              +
                                                              闪光灯
                                                              其他闪光灯
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              前置摄像头

                                                              +
                                                              +
                                                              +
                                                              前摄主摄光圈
                                                              f/2.0
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              电池信息

                                                              +
                                                              +
                                                              +
                                                              电池是否可拆卸
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                                              +
                                                              +
                                                              +
                                                              +
                                                              电池不可拆卸
                                                              +
                                                              +
                                                              +
                                                              无线充电
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                                              +
                                                              +
                                                              +
                                                              +
                                                              不支持反向无线充电
                                                              +
                                                              +
                                                              +
                                                              充电器
                                                              9V/2A
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              网络支持

                                                              +
                                                              +
                                                              +
                                                              网络频率(2G/3G)
                                                              以官网信息为准
                                                              +
                                                              +
                                                              +
                                                              最大支持SIM卡数量
                                                              2个
                                                              +
                                                              +
                                                              +
                                                              SIM卡类型
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                                              +
                                                              +
                                                              +
                                                              +
                                                              以官网信息为准
                                                              +
                                                              +
                                                              +
                                                              4G网络
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                                              +
                                                              +
                                                              +
                                                              +
                                                              4G FDD-LTE(联通);4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                                              +
                                                              +
                                                              +
                                                              3G/2G网络
                                                              3G TD-SCDMA(移动);3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                                              +
                                                              +
                                                              +
                                                              5G网络
                                                              不支持5G
                                                              +
                                                              +
                                                              +
                                                              双卡机类型
                                                              双卡双待
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              数据接口

                                                              +
                                                              +
                                                              +
                                                              数据传输接口
                                                              WIFI;WiFi热点
                                                              +
                                                              +
                                                              +
                                                              NFC/NFC模式
                                                              不支持NFC
                                                              +
                                                              +
                                                              +
                                                              充电接口类型
                                                              Type-C
                                                              +
                                                              +
                                                              +
                                                              耳机接口类型
                                                              3.5mm
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              辅助功能

                                                              +
                                                              +
                                                              +
                                                              常用功能
                                                              便签;计算器
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              包装清单

                                                              +

                                                              主机 x1 + +数据线 x1 + +充电器 x1 + +SIM卡通针x1 + +保护套x1 + +快速入门指南x1 + +保修卡x1

                                                              +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              + +
                                                              +
                                                              + +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +

                                                              售后保障

                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              商品评价

                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              推荐排序
                                                              +
                                                              +
                                                              推荐排序
                                                              +
                                                                +
                                                              • 推荐排序
                                                              • +
                                                              • 时间排序
                                                              • +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              全部评论
                                                              +
                                                              正在加载中,请稍候...
                                                              +
                                                              正在加载中,请稍候...
                                                              +
                                                              正在加载中,请稍候...
                                                              +
                                                              正在加载中,请稍候...
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +

                                                              商品问答

                                                              +
                                                              +
                                                              +
                                                              + 心中疑惑就问问买过此商品的同学吧~我要提问 +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +

                                                              购买咨询

                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                                +
                                                              • 全部
                                                              • +
                                                              • 商品咨询
                                                              • +
                                                              • 库存配送
                                                              • +
                                                              • 支付
                                                              • +
                                                              • 发票保修
                                                              • +
                                                              • +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              + + + + + + + +
                                                              + + + + + + +
                                                              + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/Redmi Note 9 5G \345\244\251\347\216\221800U 18W\345\277\253\345\205\205 4800\344\270\207\350\266\205\346\270\205\344\270\211\346\221\204 \344\272\221\345\242\250\347\201\260 6GB+128GB \346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 \345\260\217\347\261\263 \347\272\242\347\261\263-\350\257\246\346\203\205.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/Redmi Note 9 5G \345\244\251\347\216\221800U 18W\345\277\253\345\205\205 4800\344\270\207\350\266\205\346\270\205\344\270\211\346\221\204 \344\272\221\345\242\250\347\201\260 6GB+128GB \346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 \345\260\217\347\261\263 \347\272\242\347\261\263-\350\257\246\346\203\205.html" index 57f7a72a18483d215f9c7785d7aef50fdb7f730e..804051213138e8432e0e7c7633ea553add12f090 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/Redmi Note 9 5G \345\244\251\347\216\221800U 18W\345\277\253\345\205\205 4800\344\270\207\350\266\205\346\270\205\344\270\211\346\221\204 \344\272\221\345\242\250\347\201\260 6GB+128GB \346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 \345\260\217\347\261\263 \347\272\242\347\261\263-\350\257\246\346\203\205.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_detail_html/Redmi Note 9 5G \345\244\251\347\216\221800U 18W\345\277\253\345\205\205 4800\344\270\207\350\266\205\346\270\205\344\270\211\346\221\204 \344\272\221\345\242\250\347\201\260 6GB+128GB \346\270\270\346\210\217\346\231\272\350\203\275\346\211\213\346\234\272 \345\260\217\347\261\263 \347\272\242\347\261\263-\350\257\246\346\203\205.html" @@ -1,4655 +1,4655 @@ - - - - - - 【小米Redmi Note9 5G】Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米【行情 报价 价格 评测】-京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                              -
                                                              - - - -
                                                              -
                                                              -
                                                              - - - -
                                                              -
                                                              - -
                                                              -
                                                              -
                                                              - -
                                                              - -
                                                              -
                                                              -
                                                              -
                                                              - -
                                                              -
                                                                -
                                                                - - - -
                                                                -
                                                                -
                                                                -
                                                                - - > - 我的购物车 -
                                                                -
                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                - - -
                                                                - - - -
                                                                -
                                                                -
                                                                - -
                                                                >
                                                                - -
                                                                >
                                                                - -
                                                                >
                                                                - -
                                                                >
                                                                -
                                                                小米Redmi Note9 5G
                                                                -
                                                                -
                                                                -
                                                                - - 自营 - -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                客服
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                - 关注微店 -

                                                                关注微店

                                                                -
                                                                -
                                                                -
                                                                -

                                                                手机下单

                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                  -
                                                                - Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米 - -
                                                                -
                                                                - - -
                                                                - - -
                                                                -
                                                                  -
                                                                • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                • -
                                                                • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                • -
                                                                • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                • -
                                                                • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                • -
                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                - 当季新品 - Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                -
                                                                -
                                                                -
                                                                -
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                京 东 价
                                                                -
                                                                - - - - - 降价通知 -
                                                                - - - - fans - -
                                                                - - - - - - - - - - -
                                                                -
                                                                - - - -
                                                                -
                                                                -

                                                                累计评价

                                                                - 0 -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                促  销
                                                                -
                                                                -
                                                                - - - - - - - - - - -
                                                                - 展开促销 - -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                - -
                                                                - -
                                                                -
                                                                增值业务
                                                                -
                                                                -
                                                                  -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                配 送 至
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                --请选择--
                                                                - -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                -
                                                                支持
                                                                -
                                                                -
                                                                  - -
                                                                  -
                                                                  -
                                                                  -
                                                                  -
                                                                  -
                                                                  - - - - -
                                                                  - -
                                                                  -
                                                                  -
                                                                  选择颜色
                                                                  - -
                                                                  -
                                                                  -
                                                                  选择版本
                                                                  - -
                                                                  - -
                                                                  - - - - - - - - - - - -
                                                                  - -
                                                                  -
                                                                  本地活动
                                                                  -
                                                                  -
                                                                    -
                                                                    -
                                                                    - -
                                                                    -
                                                                    -
                                                                    -
                                                                    - - -
                                                                    -
                                                                    -
                                                                    -

                                                                    为你推荐

                                                                    -
                                                                    -
                                                                    -
                                                                    -
                                                                    -
                                                                    - -
                                                                    - -
                                                                    -
                                                                    -
                                                                    - -
                                                                    -
                                                                    -
                                                                    -
                                                                      -
                                                                    • 人气配件
                                                                    • -
                                                                    -
                                                                    -
                                                                    -
                                                                    - -
                                                                    -
                                                                    -
                                                                    - - -
                                                                    -
                                                                    -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      已选择0个配件
                                                                      -
                                                                      - 组合价 - ¥暂无报价 -
                                                                      - - 配件选购中心 - = -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                        -
                                                                      • 店长推荐
                                                                      • -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      - -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -

                                                                      手机热销榜

                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                        -
                                                                      • 同价位
                                                                      • -
                                                                      • 同品牌
                                                                      • -
                                                                      • 总排行
                                                                      • -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                        -
                                                                      • 商品介绍
                                                                      • -
                                                                      • 规格与包装
                                                                      • -
                                                                      • 质检报告
                                                                      • -
                                                                      • 售后保障
                                                                      • -
                                                                      • 商品评价
                                                                      • -
                                                                      • - 手机社区
                                                                      • -
                                                                      • 京东试用new
                                                                      • -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                      -
                                                                      - X -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                        -
                                                                      - -
                                                                        -
                                                                      • 商品名称:小米Redmi Note9 5G
                                                                      • -
                                                                      • 商品编号:100016773624
                                                                      • -
                                                                      • 商品毛重:450.00g
                                                                      • -
                                                                      • 商品产地:中国大陆
                                                                      • -
                                                                      • CPU型号:天玑800U
                                                                      • -
                                                                      • 运行内存:6GB
                                                                      • -
                                                                      • 机身存储:128GB
                                                                      • -
                                                                      • 存储卡:支持MicroSD(TF)
                                                                      • -
                                                                      • 摄像头数量:后置三摄
                                                                      • -
                                                                      • 后摄主摄像素:4800万像素
                                                                      • -
                                                                      • 前摄主摄像素:1300万像素
                                                                      • -
                                                                      • 主屏幕尺寸(英寸):6.53英寸
                                                                      • -
                                                                      • 分辨率:全高清FHD+
                                                                      • -
                                                                      • 屏幕比例:19.1~19.5:9
                                                                      • -
                                                                      • 屏幕前摄组合:盲孔屏
                                                                      • -
                                                                      • 充电器:其他
                                                                      • -
                                                                      • 屏占比:≥90%
                                                                      • -
                                                                      • 操作系统:Android(安卓)
                                                                      • -
                                                                      • 游戏性能:其他
                                                                      • -
                                                                      -

                                                                      - 更多参数>> -

                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                      -
                                                                      - -
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                      商品介绍加载中...
                                                                      -
                                                                      - -
                                                                      -
                                                                      -
                                                                      -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        主体

                                                                        -
                                                                        -
                                                                        -
                                                                        产品名称
                                                                        Redmi Note9 5G
                                                                        -
                                                                        -
                                                                        -
                                                                        上市月份
                                                                        11月
                                                                        -
                                                                        -
                                                                        -
                                                                        上市年份
                                                                        2020年
                                                                        -
                                                                        -
                                                                        -
                                                                        品牌
                                                                        小米(MI)
                                                                        -
                                                                        -
                                                                        -
                                                                        首销日期
                                                                        以官网信息为准
                                                                        -
                                                                        -
                                                                        -
                                                                        入网型号
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        工业代号或者入网型号

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        以官网信息为准
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        基本信息

                                                                        -
                                                                        -
                                                                        -
                                                                        机身宽度(mm)
                                                                        77.25mm
                                                                        -
                                                                        -
                                                                        -
                                                                        机身厚度(mm)
                                                                        9.2mm (流影紫、青山外) / 9mm(云墨灰)
                                                                        -
                                                                        -
                                                                        -
                                                                        输入方式
                                                                        触控
                                                                        -
                                                                        -
                                                                        -
                                                                        机身重量(g)
                                                                        199g
                                                                        -
                                                                        -
                                                                        -
                                                                        运营商标志或内容
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        机身材质分类
                                                                        其他
                                                                        -
                                                                        -
                                                                        -
                                                                        机身长度(mm)
                                                                        161.96mm
                                                                        -
                                                                        -
                                                                        -
                                                                        机身材质工艺
                                                                        以官网信息为准
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        主芯片

                                                                        -
                                                                        -
                                                                        -
                                                                        CPU核数
                                                                        八核
                                                                        -
                                                                        -
                                                                        -
                                                                        CPU品牌
                                                                        联发科(MTK)
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        存储

                                                                        -
                                                                        -
                                                                        -
                                                                        最大存储扩展容量
                                                                        512GB
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        屏幕

                                                                        -
                                                                        -
                                                                        -
                                                                        触摸屏实现方式
                                                                        IN-CELL
                                                                        -
                                                                        -
                                                                        -
                                                                        触摸屏类型
                                                                        电容屏
                                                                        -
                                                                        -
                                                                        -
                                                                        屏幕色彩
                                                                        1600万
                                                                        -
                                                                        -
                                                                        -
                                                                        主屏幕尺寸(英寸)
                                                                        6.53英寸
                                                                        -
                                                                        -
                                                                        -
                                                                        屏幕材质类型
                                                                        LCD
                                                                        -
                                                                        -
                                                                        -
                                                                        屏幕刷新率
                                                                        60Hz
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        后置摄像头

                                                                        -
                                                                        -
                                                                        -
                                                                        闪光灯
                                                                        LED灯
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄主摄光圈
                                                                        f/1.79
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄主摄光学防抖
                                                                        不支持光学防抖
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄2摄像头的功能
                                                                        超广角
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄2摄像素
                                                                        800万像素
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄2摄光圈
                                                                        f/2.2
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄3摄像头的功能
                                                                        微距
                                                                        -
                                                                        -
                                                                        -
                                                                        后摄3摄像素
                                                                        200万像素
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        前置摄像头

                                                                        -
                                                                        -
                                                                        -
                                                                        前摄主摄光圈
                                                                        其他
                                                                        -
                                                                        -
                                                                        -
                                                                        闪光灯
                                                                        其他
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        电池信息

                                                                        -
                                                                        -
                                                                        -
                                                                        电池是否可拆卸
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        电池不可拆卸
                                                                        -
                                                                        -
                                                                        -
                                                                        无线充电
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        不支持无线充电
                                                                        -
                                                                        -
                                                                        -
                                                                        充电器
                                                                        其他
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        网络支持

                                                                        -
                                                                        -
                                                                        -
                                                                        网络频率(2G/3G)
                                                                        以官网信息为准
                                                                        -
                                                                        -
                                                                        -
                                                                        副卡网络频率
                                                                        以官网信息为准
                                                                        -
                                                                        -
                                                                        -
                                                                        最大支持SIM卡数量
                                                                        2个
                                                                        -
                                                                        -
                                                                        -
                                                                        SIM卡类型
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        Nano SIM
                                                                        -
                                                                        -
                                                                        -
                                                                        4G网络
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                                                        -
                                                                        -
                                                                        -
                                                                        3G/2G网络
                                                                        3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                                                        -
                                                                        -
                                                                        -
                                                                        5G网络
                                                                        移动5G;联通5G;电信5G
                                                                        -
                                                                        -
                                                                        -
                                                                        双卡机类型
                                                                        双卡双待单通
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        数据接口

                                                                        -
                                                                        -
                                                                        -
                                                                        数据传输接口
                                                                        WIFI;蓝牙;红外
                                                                        -
                                                                        -
                                                                        -
                                                                        NFC/NFC模式
                                                                        不支持NFC
                                                                        -
                                                                        -
                                                                        -
                                                                        充电接口类型
                                                                        Type-C
                                                                        -
                                                                        -
                                                                        -
                                                                        耳机接口类型
                                                                        3.5mm
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        手机特性

                                                                        -
                                                                        -
                                                                        -
                                                                        三防标准
                                                                        生活防水
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        娱乐功能

                                                                        -
                                                                        -
                                                                        -
                                                                        听筒扬声器
                                                                        听筒可作为扬声器使用立体声
                                                                        -
                                                                        -
                                                                        -
                                                                        mic数量
                                                                        2个
                                                                        -
                                                                        -
                                                                        -
                                                                        喇叭数量
                                                                        2个
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        辅助功能

                                                                        -
                                                                        -
                                                                        -
                                                                        常用功能
                                                                        便签;计算器;超大字体
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        包装清单

                                                                        -

                                                                        手机*1,手机保护套*1,电源适配器*1,USB Type-c数据线*1,SIM卡插针*1,三包凭证/入门指南*1

                                                                        -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        - -
                                                                        -
                                                                        - -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -

                                                                        售后保障

                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        商品评价

                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        推荐排序
                                                                        -
                                                                        -
                                                                        推荐排序
                                                                        -
                                                                          -
                                                                        • 推荐排序
                                                                        • -
                                                                        • 时间排序
                                                                        • -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        全部评论
                                                                        -
                                                                        正在加载中,请稍候...
                                                                        -
                                                                        正在加载中,请稍候...
                                                                        -
                                                                        正在加载中,请稍候...
                                                                        -
                                                                        正在加载中,请稍候...
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -

                                                                        商品问答

                                                                        -
                                                                        -
                                                                        -
                                                                        - 心中疑惑就问问买过此商品的同学吧~我要提问 -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -

                                                                        购买咨询

                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                          -
                                                                        • 全部
                                                                        • -
                                                                        • 商品咨询
                                                                        • -
                                                                        • 库存配送
                                                                        • -
                                                                        • 支付
                                                                        • -
                                                                        • 发票保修
                                                                        • -
                                                                        • -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -
                                                                        -
                                                                        - -
                                                                        -
                                                                        -
                                                                        -
                                                                        - - - - - - - -
                                                                        - - - - - - -
                                                                        - - - - + + + + + + 【小米Redmi Note9 5G】Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米【行情 报价 价格 评测】-京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        +
                                                                        + + + +
                                                                        +
                                                                        +
                                                                        + + + +
                                                                        +
                                                                        + +
                                                                        +
                                                                        +
                                                                        + +
                                                                        + +
                                                                        +
                                                                        +
                                                                        +
                                                                        + +
                                                                        +
                                                                          +
                                                                          + + + +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + > + 我的购物车 +
                                                                          +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + +
                                                                          + + + +
                                                                          +
                                                                          +
                                                                          + +
                                                                          >
                                                                          + +
                                                                          >
                                                                          + +
                                                                          >
                                                                          + +
                                                                          >
                                                                          +
                                                                          小米Redmi Note9 5G
                                                                          +
                                                                          +
                                                                          +
                                                                          + + 自营 + +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          客服
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          + 关注微店 +

                                                                          关注微店

                                                                          +
                                                                          +
                                                                          +
                                                                          +

                                                                          手机下单

                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                            +
                                                                          + Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米 + +
                                                                          +
                                                                          + + +
                                                                          + + +
                                                                          +
                                                                            +
                                                                          • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                          • +
                                                                          • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                          • +
                                                                          • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                          • +
                                                                          • Redmi Note 9 5G 天玑800U  18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                          • +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          + 当季新品 + Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          京 东 价
                                                                          +
                                                                          + + + + + 降价通知 +
                                                                          + + + + fans + +
                                                                          + + + + + + + + + + +
                                                                          +
                                                                          + + + +
                                                                          +
                                                                          +

                                                                          累计评价

                                                                          + 0 +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          促  销
                                                                          +
                                                                          +
                                                                          + + + + + + + + + + +
                                                                          + 展开促销 + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + +
                                                                          + +
                                                                          +
                                                                          增值业务
                                                                          +
                                                                          +
                                                                            +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          配 送 至
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          --请选择--
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          支持
                                                                          +
                                                                          +
                                                                            + +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            + + + + +
                                                                            + +
                                                                            +
                                                                            +
                                                                            选择颜色
                                                                            + +
                                                                            +
                                                                            +
                                                                            选择版本
                                                                            + +
                                                                            + +
                                                                            + + + + + + + + + + + +
                                                                            + +
                                                                            +
                                                                            本地活动
                                                                            +
                                                                            +
                                                                              +
                                                                              +
                                                                              + +
                                                                              +
                                                                              +
                                                                              +
                                                                              + + +
                                                                              +
                                                                              +
                                                                              +

                                                                              为你推荐

                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              + +
                                                                              + +
                                                                              +
                                                                              +
                                                                              + +
                                                                              +
                                                                              +
                                                                              +
                                                                                +
                                                                              • 人气配件
                                                                              • +
                                                                              +
                                                                              +
                                                                              +
                                                                              + +
                                                                              +
                                                                              +
                                                                              + + +
                                                                              +
                                                                              +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                已选择0个配件
                                                                                +
                                                                                + 组合价 + ¥暂无报价 +
                                                                                + + 配件选购中心 + = +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                  +
                                                                                • 店长推荐
                                                                                • +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                + +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +

                                                                                手机热销榜

                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                  +
                                                                                • 同价位
                                                                                • +
                                                                                • 同品牌
                                                                                • +
                                                                                • 总排行
                                                                                • +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                  +
                                                                                • 商品介绍
                                                                                • +
                                                                                • 规格与包装
                                                                                • +
                                                                                • 质检报告
                                                                                • +
                                                                                • 售后保障
                                                                                • +
                                                                                • 商品评价
                                                                                • +
                                                                                • + 手机社区
                                                                                • +
                                                                                • 京东试用new
                                                                                • +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                Redmi Note 9 5G 天玑800U 18W快充 4800万超清三摄 云墨灰 6GB+128GB 游戏智能手机 小米 红米
                                                                                +
                                                                                + X +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                  +
                                                                                + +
                                                                                  +
                                                                                • 商品名称:小米Redmi Note9 5G
                                                                                • +
                                                                                • 商品编号:100016773624
                                                                                • +
                                                                                • 商品毛重:450.00g
                                                                                • +
                                                                                • 商品产地:中国大陆
                                                                                • +
                                                                                • CPU型号:天玑800U
                                                                                • +
                                                                                • 运行内存:6GB
                                                                                • +
                                                                                • 机身存储:128GB
                                                                                • +
                                                                                • 存储卡:支持MicroSD(TF)
                                                                                • +
                                                                                • 摄像头数量:后置三摄
                                                                                • +
                                                                                • 后摄主摄像素:4800万像素
                                                                                • +
                                                                                • 前摄主摄像素:1300万像素
                                                                                • +
                                                                                • 主屏幕尺寸(英寸):6.53英寸
                                                                                • +
                                                                                • 分辨率:全高清FHD+
                                                                                • +
                                                                                • 屏幕比例:19.1~19.5:9
                                                                                • +
                                                                                • 屏幕前摄组合:盲孔屏
                                                                                • +
                                                                                • 充电器:其他
                                                                                • +
                                                                                • 屏占比:≥90%
                                                                                • +
                                                                                • 操作系统:Android(安卓)
                                                                                • +
                                                                                • 游戏性能:其他
                                                                                • +
                                                                                +

                                                                                + 更多参数>> +

                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                商品介绍加载中...
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  主体

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  产品名称
                                                                                  Redmi Note9 5G
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  上市月份
                                                                                  11月
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  上市年份
                                                                                  2020年
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  品牌
                                                                                  小米(MI)
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  首销日期
                                                                                  以官网信息为准
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  入网型号
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  工业代号或者入网型号

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  以官网信息为准
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  基本信息

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身宽度(mm)
                                                                                  77.25mm
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身厚度(mm)
                                                                                  9.2mm (流影紫、青山外) / 9mm(云墨灰)
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  输入方式
                                                                                  触控
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身重量(g)
                                                                                  199g
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  运营商标志或内容
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  定制机往往会有运营商的元素在手机的某些位置,该属性会介绍这些元素出现的位置。

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身材质分类
                                                                                  其他
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身长度(mm)
                                                                                  161.96mm
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  机身材质工艺
                                                                                  以官网信息为准
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  主芯片

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  CPU核数
                                                                                  八核
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  CPU品牌
                                                                                  联发科(MTK)
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  存储

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  最大存储扩展容量
                                                                                  512GB
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  屏幕

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  触摸屏实现方式
                                                                                  IN-CELL
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  触摸屏类型
                                                                                  电容屏
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  屏幕色彩
                                                                                  1600万
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  主屏幕尺寸(英寸)
                                                                                  6.53英寸
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  屏幕材质类型
                                                                                  LCD
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  屏幕刷新率
                                                                                  60Hz
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  后置摄像头

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  闪光灯
                                                                                  LED灯
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄主摄光圈
                                                                                  f/1.79
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄主摄光学防抖
                                                                                  不支持光学防抖
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄2摄像头的功能
                                                                                  超广角
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄2摄像素
                                                                                  800万像素
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄2摄光圈
                                                                                  f/2.2
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄3摄像头的功能
                                                                                  微距
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  后摄3摄像素
                                                                                  200万像素
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  前置摄像头

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  前摄主摄光圈
                                                                                  其他
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  闪光灯
                                                                                  其他
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  电池信息

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  电池是否可拆卸
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  不可拆卸电池手机更加节省内部空间,密封性更好,请勿在没有专业人士的帮助下自行拆卸。

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  电池不可拆卸
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  无线充电
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  无线充电只是个功能,请注意支持无线充电的产品其包装是否带有无线充电的配件,如没有需要自行单配哦。

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  不支持无线充电
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  充电器
                                                                                  其他
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  网络支持

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  网络频率(2G/3G)
                                                                                  以官网信息为准
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  副卡网络频率
                                                                                  以官网信息为准
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  最大支持SIM卡数量
                                                                                  2个
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  SIM卡类型
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  sim卡的规格,大卡、小卡或者nano卡。如果副卡有不同可在下方副卡规格中填写或显示

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  Nano SIM
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  4G网络
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  单卡手机或者主卡的4G网络在这里填写,副卡的网络在副sim卡4G网络中填写。

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  4G TD-LTE(移动);4G FDD-LTE(联通、电信)
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  3G/2G网络
                                                                                  3G WCDMA(联通);3G CDMA2000(电信);2G GSM(移动/联通);2G CDMA(电信)
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  5G网络
                                                                                  移动5G;联通5G;电信5G
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  双卡机类型
                                                                                  双卡双待单通
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  数据接口

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  数据传输接口
                                                                                  WIFI;蓝牙;红外
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  NFC/NFC模式
                                                                                  不支持NFC
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  充电接口类型
                                                                                  Type-C
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  耳机接口类型
                                                                                  3.5mm
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  手机特性

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  三防标准
                                                                                  生活防水
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  娱乐功能

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  听筒扬声器
                                                                                  听筒可作为扬声器使用立体声
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  mic数量
                                                                                  2个
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  喇叭数量
                                                                                  2个
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  辅助功能

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  常用功能
                                                                                  便签;计算器;超大字体
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  包装清单

                                                                                  +

                                                                                  手机*1,手机保护套*1,电源适配器*1,USB Type-c数据线*1,SIM卡插针*1,三包凭证/入门指南*1

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +

                                                                                  售后保障

                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  商品评价

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  推荐排序
                                                                                  +
                                                                                  +
                                                                                  推荐排序
                                                                                  +
                                                                                    +
                                                                                  • 推荐排序
                                                                                  • +
                                                                                  • 时间排序
                                                                                  • +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  全部评论
                                                                                  +
                                                                                  正在加载中,请稍候...
                                                                                  +
                                                                                  正在加载中,请稍候...
                                                                                  +
                                                                                  正在加载中,请稍候...
                                                                                  +
                                                                                  正在加载中,请稍候...
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  商品问答

                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + 心中疑惑就问问买过此商品的同学吧~我要提问 +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +

                                                                                  购买咨询

                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                    +
                                                                                  • 全部
                                                                                  • +
                                                                                  • 商品咨询
                                                                                  • +
                                                                                  • 库存配送
                                                                                  • +
                                                                                  • 支付
                                                                                  • +
                                                                                  • 发票保修
                                                                                  • +
                                                                                  • +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + + + + + + + +
                                                                                  + + + + + + +
                                                                                  + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_search_html.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_search_html.py" index 4a45f91e3c26249fc2028f0b2893d166c779c93c..10dfe7b12c45638e1947c7202bac279e9bba78b4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_search_html.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/jd_search_html.py" @@ -1,29 +1,29 @@ -import requests -import urllib3 - -from pathlib import Path - -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - -p = Path('jd_search_html') -p.mkdir(exist_ok=True) - -def search_jd(keyword): - url = "https://search.jd.com/Search" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers, verify=False) - f = open("./jd_search_html/" + keyword + "-搜索结果.html", "w", encoding="utf-8") - f.write(response.text) - f.close() - - -if __name__ == "__main__": - key = ["手机", "电脑", "声卡", "显卡", "兰博基尼", "宾利", "华强北", "苹果", "索尼", "手办"] - for i in key: - search_jd(i) - print(f"{i}-OK") +import requests +import urllib3 + +from pathlib import Path + +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +p = Path('jd_search_html') +p.mkdir(exist_ok=True) + +def search_jd(keyword): + url = "https://search.jd.com/Search" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers, verify=False) + f = open("./jd_search_html/" + keyword + "-搜索结果.html", "w", encoding="utf-8") + f.write(response.text) + f.close() + + +if __name__ == "__main__": + key = ["手机", "电脑", "声卡", "显卡", "兰博基尼", "宾利", "华强北", "苹果", "索尼", "手办"] + for i in key: + search_jd(i) + print(f"{i}-OK") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/json_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/json_test.py" index c78ab760ca85c3c3561264b6f9bfc94352a670ea..4e9474705cef68ff2bdb890c2f325cb6a1d020f2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/json_test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\200\350\212\202/json_test.py" @@ -1,14 +1,14 @@ -import json - -test_dict = { - "a": 1, - "b": ["1", 2, None], - "c": {"d": 1} -} -# json格式数据其实是个字符串 -# 将python字典转变为json数据格式 -json_data = json.dumps(test_dict) -print(type(json_data), json_data) - -# 将json数据格式转变为字典 +import json + +test_dict = { + "a": 1, + "b": ["1", 2, None], + "c": {"d": 1} +} +# json格式数据其实是个字符串 +# 将python字典转变为json数据格式 +json_data = json.dumps(test_dict) +print(type(json_data), json_data) + +# 将json数据格式转变为字典 print(json.loads(json_data)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" index c0c2096cfd9b6cf5043f79a671695f0608334491..6ffdc86a5c6793cd7bb11b2c2000f95412108f97 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" @@ -1,37 +1,37 @@ -import requests -import pymysql -from week9.lesson3.parser.search import parser_jd_item -from week9.lesson3.settings import MYSQL_CONF, HEADERS - -def saver(item_array): - cursor = mysql_con.cursor() - SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) - VALUES (%s, %s, %s, %s, %s, %s)""" - cursor.executemany(SQL, item_array) - mysql_con.commit() - cursor.close() - -def donwloader(task): - url = "https://search.jd.com/Search" - params = { - "keyword": task - } - res = requests.get(url=url, params=params, headers=HEADERS) - return res - - - -def main(task_array): - for task in task_array: - result = donwloader(task) - item_array = parser_jd_item(result.text) - print(item_array) - print("GET ITEMS", item_array) - saver(item_array) - -if __name__ == "__main__": - mysql_con = pymysql.connect(**MYSQL_CONF) - task_array = ["手机", "电脑", "相机", "书籍"] - main(task_array) - - +import requests +import pymysql +from week9.lesson3.parser.search import parser_jd_item +from week9.lesson3.settings import MYSQL_CONF, HEADERS + +def saver(item_array): + cursor = mysql_con.cursor() + SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) + VALUES (%s, %s, %s, %s, %s, %s)""" + cursor.executemany(SQL, item_array) + mysql_con.commit() + cursor.close() + +def donwloader(task): + url = "https://search.jd.com/Search" + params = { + "keyword": task + } + res = requests.get(url=url, params=params, headers=HEADERS) + return res + + + +def main(task_array): + for task in task_array: + result = donwloader(task) + item_array = parser_jd_item(result.text) + print(item_array) + print("GET ITEMS", item_array) + saver(item_array) + +if __name__ == "__main__": + mysql_con = pymysql.connect(**MYSQL_CONF) + task_array = ["手机", "电脑", "相机", "书籍"] + main(task_array) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/parser/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/parser/search.py" index 77963830c14286d6e7cca85b451b9d4eb810d3d5..bc2612bba28e360e7b61901196f863b1243e92d6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/parser/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/parser/search.py" @@ -1,33 +1,33 @@ -import json - -from bs4 import BeautifulSoup - -def parser_jd_item(html): - result = [] - soup = BeautifulSoup(html, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name']") - # title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].a.attrs['title'] if shop else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' - - result.append((sku_id, img, price, title, shop, icons)) - return result - - -if __name__ == "__main__": - with open(r"F:\PY Project\newstart\week9\lesson1\jd_search_html\手机-搜索结果.html", "r", encoding="utf-8") as f: - html = f.read() - result = parser_jd_item(html) - print(result) - +import json + +from bs4 import BeautifulSoup + +def parser_jd_item(html): + result = [] + soup = BeautifulSoup(html, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name']") + # title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].a.attrs['title'] if shop else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' + + result.append((sku_id, img, price, title, shop, icons)) + return result + + +if __name__ == "__main__": + with open(r"F:\PY Project\newstart\week9\lesson1\jd_search_html\手机-搜索结果.html", "r", encoding="utf-8") as f: + html = f.read() + result = parser_jd_item(html) + print(result) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/settings.py" index 33b23e155fa99f040f9a67214b90b69184623482..e57e1cde4b940d1a11ee0c89104da0d606ed0185 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\270\211\350\212\202/settings.py" @@ -1,11 +1,11 @@ -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36", - # "upgrade-insecure-requests": "1" -} - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "0000", - "db": "tunan_class_4" +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36", + # "upgrade-insecure-requests": "1" +} + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "0000", + "db": "tunan_class_4" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\272\214\350\212\202/beautifulsoup_cssSelector.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\272\214\350\212\202/beautifulsoup_cssSelector.py" index 22d9da3ad8d69ac4f427079299750653dc466cea..c94ebf4c35062df7becdb0d3418c456ea547c3a1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\272\214\350\212\202/beautifulsoup_cssSelector.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\271\235\345\221\250/\347\254\254\344\272\214\350\212\202/beautifulsoup_cssSelector.py" @@ -1,39 +1,39 @@ -from bs4 import BeautifulSoup -import requests - - -def search_jd(kw): - url = "https://search.jd.com/Search" - params = { - "keyword": kw - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers, verify=False) - soup = BeautifulSoup(response.text, "html.parser") - goods_list = soup.find_all('li', class_='gl-item') - for li in goods_list: # 遍历父节点 - # 商品编号 - id = li['data-sku'] - # 商品名称 - name = li.find(class_='p-name p-name-type-2').find('em').get_text() - # 图片路径 - img_url = li.find(class_='p-img').find('img')['data-lazy-img'] - # 价格 - price = li.find(class_='p-price').find('i').get_text() - # 商家 - shop = li.find(class_='p-shop').find('a').get_text() - # 商品详情地址 - detail_addr = li.find(class_='p-name p-name-type-2').find('a')['href'] - # 打印结果 - print("===================分割线=========================") - print("商品编号 = " + id) - print("商品名称 = " + name) - print("图片路径 = " + img_url) - print("价格 = " + price) - print("商家 = " + shop) - print("商品详情地址 = " + detail_addr) - -if __name__ == "__main__": - search_jd("手机") +from bs4 import BeautifulSoup +import requests + + +def search_jd(kw): + url = "https://search.jd.com/Search" + params = { + "keyword": kw + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers, verify=False) + soup = BeautifulSoup(response.text, "html.parser") + goods_list = soup.find_all('li', class_='gl-item') + for li in goods_list: # 遍历父节点 + # 商品编号 + id = li['data-sku'] + # 商品名称 + name = li.find(class_='p-name p-name-type-2').find('em').get_text() + # 图片路径 + img_url = li.find(class_='p-img').find('img')['data-lazy-img'] + # 价格 + price = li.find(class_='p-price').find('i').get_text() + # 商家 + shop = li.find(class_='p-shop').find('a').get_text() + # 商品详情地址 + detail_addr = li.find(class_='p-name p-name-type-2').find('a')['href'] + # 打印结果 + print("===================分割线=========================") + print("商品编号 = " + id) + print("商品名称 = " + name) + print("图片路径 = " + img_url) + print("价格 = " + price) + print("商家 = " + shop) + print("商品详情地址 = " + detail_addr) + +if __name__ == "__main__": + search_jd("手机") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/my_calculator.py" index 3aeddcb8f994ed8e9e1b50fa925b88b014aea822..3607bb110e38574be31739dfbeac74bce529726f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/my_calculator.py" @@ -1,57 +1,57 @@ -from math import sqrt - -def add(a, b): - return a+b - -def sub(a, b): - return a-b - -def mul(a, b): - return a*b - -def div(a, b): - return a/b - -def exdiv(a, b): - return a//b - -def rem(a, b): - return a%b - -def pow(a, b): - return a**b - -if __name__ == "__main__": - print("请问要做什么运算:") - print("1:加法 2:减法 3:乘法 4:除法 5:整除 6:取余 7:乘方 8:开二次方 q:退出") - while 1: - print("输入运算方式:") - i = input() - if i =="q": - break - elif i=='1'or i=='2'or i=='3'or i=='4'or i=='5'or i=='6'or i=='7': - print("第一个数:") - a = float(input()) - print("第二个数:") - b = float(input()) - if i=='1': - print(str(a)+"+"+str(b)+"="+str(add(a, b))) - if i=='2': - print(str(a)+"-"+str(b)+"="+str(sub(a, b))) - if i=='3': - print(str(a)+"*"+str(b)+"="+str(mul(a, b))) - if i=='4': - print(str(a)+"/"+str(b)+"="+str(div(a, b))) - if i=='5': - print(str(a)+"//"+str(b)+"="+str(exdiv(a, b))) - if i=='6': - print(str(a)+"%"+str(b)+"="+str(rem(a, b))) - if i=='7': - print(str(a)+"**"+str(b)+"="+str(pow(a, b))) - elif i=='8': - print("输入数字:") - a = int(input()) - print(sqrt(a)) - else: - print("请输入正确的指令!") - +from math import sqrt + +def add(a, b): + return a+b + +def sub(a, b): + return a-b + +def mul(a, b): + return a*b + +def div(a, b): + return a/b + +def exdiv(a, b): + return a//b + +def rem(a, b): + return a%b + +def pow(a, b): + return a**b + +if __name__ == "__main__": + print("请问要做什么运算:") + print("1:加法 2:减法 3:乘法 4:除法 5:整除 6:取余 7:乘方 8:开二次方 q:退出") + while 1: + print("输入运算方式:") + i = input() + if i =="q": + break + elif i=='1'or i=='2'or i=='3'or i=='4'or i=='5'or i=='6'or i=='7': + print("第一个数:") + a = float(input()) + print("第二个数:") + b = float(input()) + if i=='1': + print(str(a)+"+"+str(b)+"="+str(add(a, b))) + if i=='2': + print(str(a)+"-"+str(b)+"="+str(sub(a, b))) + if i=='3': + print(str(a)+"*"+str(b)+"="+str(mul(a, b))) + if i=='4': + print(str(a)+"/"+str(b)+"="+str(div(a, b))) + if i=='5': + print(str(a)+"//"+str(b)+"="+str(exdiv(a, b))) + if i=='6': + print(str(a)+"%"+str(b)+"="+str(rem(a, b))) + if i=='7': + print(str(a)+"**"+str(b)+"="+str(pow(a, b))) + elif i=='8': + print("输入数字:") + a = int(input()) + print(sqrt(a)) + else: + print("请输入正确的指令!") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/data_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/data_test.py" index fa97cc96598ee2e857d0514ad2965de65f940b00..3f4c46c14da8c0ef7479ba62b5fa3cb6cb3ea640 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/data_test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/data_test.py" @@ -1,89 +1,89 @@ -def list_test(): - # 增加 - list_1 = [1, 2, 3, 4, 5] - list_2 = ['a', 'b', 'c', 'd', 'e'] - list_1 += list_2 - a = ['a'] - list_3 = [a] * 3 - print(list_3) - a[0] = 'x' - print(list_3) - list_1.append("xxxxxxx") - print(list_1) - list_1.insert(4, "KK") - print(list_1) - - # 检索 - print(list_1[3]) - print(list_1[1:5]) - print(list_1.index('a')) - - # 更新 - list_1[0] = "A" - list_1[1:3] = ["B", "C"] - print(list_1) - - # 删除 - list_1.pop() - list_1.remove('a') - print(list_1) - - -def tuple_test(): - tuple_1 = (1, 2, 3, 4, 5, 6, 7, 8, 9) - print(tuple_1[1:3]) - print(tuple_1.index(1)) - - -def dict_test(): - # 增加 - dict_1 = {"a": 1} - dict_1["b"] = 2 - dict_2 = {"c": 3, "d": 4} - dict_1.update(dict_2) - dict_1.setdefault("f", 5) - print(dict_1) - - # 检索 - print(dict_1["a"]) - print(dict_1.get("g", 22)) - print(dict_1.keys()) - print(dict_1.values()) - print(dict_1.items()) - - # 更新 - dict_1["a"] = 56 - dict_1.update({"x": 12, "y": 13, "z": 14}) - print(dict_1) - - # 删除 - dict_1.pop("a") - dict_1.popitem() - print(dict_1) - - -def set_test(): - #增加检索 - set_1 = {"a", "b"} - set_2 = {"c", "d"} - set_1.add(1) - print(set_1) - print("a" in set_1) - - #更新删除 - set_1.update(set_2) - set_3 = set_1.union(set_2) - print(set_1) - print(set_3) - set_3.remove("a") - set_3.pop() - print(set_3) - - - - -if __name__ == "__main__": - list_test() - tuple_test() - dict_test() - set_test() +def list_test(): + # 增加 + list_1 = [1, 2, 3, 4, 5] + list_2 = ['a', 'b', 'c', 'd', 'e'] + list_1 += list_2 + a = ['a'] + list_3 = [a] * 3 + print(list_3) + a[0] = 'x' + print(list_3) + list_1.append("xxxxxxx") + print(list_1) + list_1.insert(4, "KK") + print(list_1) + + # 检索 + print(list_1[3]) + print(list_1[1:5]) + print(list_1.index('a')) + + # 更新 + list_1[0] = "A" + list_1[1:3] = ["B", "C"] + print(list_1) + + # 删除 + list_1.pop() + list_1.remove('a') + print(list_1) + + +def tuple_test(): + tuple_1 = (1, 2, 3, 4, 5, 6, 7, 8, 9) + print(tuple_1[1:3]) + print(tuple_1.index(1)) + + +def dict_test(): + # 增加 + dict_1 = {"a": 1} + dict_1["b"] = 2 + dict_2 = {"c": 3, "d": 4} + dict_1.update(dict_2) + dict_1.setdefault("f", 5) + print(dict_1) + + # 检索 + print(dict_1["a"]) + print(dict_1.get("g", 22)) + print(dict_1.keys()) + print(dict_1.values()) + print(dict_1.items()) + + # 更新 + dict_1["a"] = 56 + dict_1.update({"x": 12, "y": 13, "z": 14}) + print(dict_1) + + # 删除 + dict_1.pop("a") + dict_1.popitem() + print(dict_1) + + +def set_test(): + #增加检索 + set_1 = {"a", "b"} + set_2 = {"c", "d"} + set_1.add(1) + print(set_1) + print("a" in set_1) + + #更新删除 + set_1.update(set_2) + set_3 = set_1.union(set_2) + print(set_1) + print(set_3) + set_3.remove("a") + set_3.pop() + print(set_3) + + + + +if __name__ == "__main__": + list_test() + tuple_test() + dict_test() + set_test() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_main.py" index 4a2b00d70344780d4710d5025bcd256ada87b1a5..40d2a8cdda63b7da50aeda81ec2c2dd8b215a865 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_main.py" @@ -1,99 +1,99 @@ -content = ''' -#什么是码位: ->>> '你好呀'.encode("unicode_escape").decode() -'\\u4f60\\u597d\\u5440' ->>> '\u4f60\u597d\u5440' -'你好呀' - -#编码: ->>> "你好呀".encode("utf-8") -b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80' - -#解码: ->>> b = "你好呀".encode("utf-8") ->>> b.decode("utf") -'你好呀' - -#检测编码: ->>> import chardet ->>> chardet.detect(b) -{'encoding': 'utf-8', 'confidence': 0.87625, 'language': ''} - -#忽略错误编码: ->>> b_2 = "你好呀".encode("utf-8")+"我很好".encode("gbk") ->>> b_2 -b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80\xce\xd2\xba\xdc\xba\xc3' ->>> b_2.decode("utf-8", errors='ignore') -'你好呀Һܺ' - -#利用鬼符来替换: ->>> b_2.decode("utf-8", errors='replace') -'你好呀�Һܺ�' - -#字符串的CRUD操作: -#Create ->>> a = "Hello World!" ->>> id(a) -2333141953392 ->>> a += "I am Macintosh" ->>> id(a) -2333141149216 ->>> a -'Hello World!I am Macintosh' - -#Retrieve ->>> a[10] -'d' ->>> a.find("Macintosh") -17 ->>> a.index("M") -17 ->>> a.find("m") -15 ->>> a.startswith("hello") -False ->>> a.startswith("Hello") -True ->>> a.endswith("s") -False ->>> a.endswith("h") -True - -#Update ->>> a.replace("I am", "My name is") -'Hello World!My name is Macintosh' ->>> a.split("!") -['Hello World', 'I am Macintosh'] ->>> b = a.split("!") ->>> ".".join(b) -'Hello World.I am Macintosh' - -#Delete ->>> c = " Hello, World!! " ->>> c.strip() -'Hello, World!!' ->>> c.rstrip() -' Hello, World!!' ->>> c.lstrip().lstrip('Hello') -', World!! ' - -#字符串格式化输出 ->>> a = "China" ->>> b = "Chendu" ->>> "come to {} {}".format(a,b) -'come to China Chendu' ->>> "come to {0} {1} {1} {0}".format(a,b) -'come to China Chendu Chendu China' ->>> "come to {c} {d} {d} {c}".format(c='china',d='chengdu') -'come to china chengdu chengdu china' ->>> print(f"come {a} {b}") -come China Chendu ->>> "{:.2f}".format(3.1415926) -'3.14' ->>> "let's go to %s" % ("Shanghai!") -"let's go to Shanghai!" - -''' -fw = open("第二周_第二节课_输出文件.txt", "w", encoding="utf-8") -fw.write(content) +content = ''' +#什么是码位: +>>> '你好呀'.encode("unicode_escape").decode() +'\\u4f60\\u597d\\u5440' +>>> '\u4f60\u597d\u5440' +'你好呀' + +#编码: +>>> "你好呀".encode("utf-8") +b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80' + +#解码: +>>> b = "你好呀".encode("utf-8") +>>> b.decode("utf") +'你好呀' + +#检测编码: +>>> import chardet +>>> chardet.detect(b) +{'encoding': 'utf-8', 'confidence': 0.87625, 'language': ''} + +#忽略错误编码: +>>> b_2 = "你好呀".encode("utf-8")+"我很好".encode("gbk") +>>> b_2 +b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80\xce\xd2\xba\xdc\xba\xc3' +>>> b_2.decode("utf-8", errors='ignore') +'你好呀Һܺ' + +#利用鬼符来替换: +>>> b_2.decode("utf-8", errors='replace') +'你好呀�Һܺ�' + +#字符串的CRUD操作: +#Create +>>> a = "Hello World!" +>>> id(a) +2333141953392 +>>> a += "I am Macintosh" +>>> id(a) +2333141149216 +>>> a +'Hello World!I am Macintosh' + +#Retrieve +>>> a[10] +'d' +>>> a.find("Macintosh") +17 +>>> a.index("M") +17 +>>> a.find("m") +15 +>>> a.startswith("hello") +False +>>> a.startswith("Hello") +True +>>> a.endswith("s") +False +>>> a.endswith("h") +True + +#Update +>>> a.replace("I am", "My name is") +'Hello World!My name is Macintosh' +>>> a.split("!") +['Hello World', 'I am Macintosh'] +>>> b = a.split("!") +>>> ".".join(b) +'Hello World.I am Macintosh' + +#Delete +>>> c = " Hello, World!! " +>>> c.strip() +'Hello, World!!' +>>> c.rstrip() +' Hello, World!!' +>>> c.lstrip().lstrip('Hello') +', World!! ' + +#字符串格式化输出 +>>> a = "China" +>>> b = "Chendu" +>>> "come to {} {}".format(a,b) +'come to China Chendu' +>>> "come to {0} {1} {1} {0}".format(a,b) +'come to China Chendu Chendu China' +>>> "come to {c} {d} {d} {c}".format(c='china',d='chengdu') +'come to china chengdu chengdu china' +>>> print(f"come {a} {b}") +come China Chendu +>>> "{:.2f}".format(3.1415926) +'3.14' +>>> "let's go to %s" % ("Shanghai!") +"let's go to Shanghai!" + +''' +fw = open("第二周_第二节课_输出文件.txt", "w", encoding="utf-8") +fw.write(content) fw.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276_\350\276\223\345\207\272\346\226\207\344\273\266.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276_\350\276\223\345\207\272\346\226\207\344\273\266.txt" index 1ad3370878862eeaa957ff60e00a4b38a4cdaf80..326742d1c064fc475cf6589f53064c21e927c197 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276_\350\276\223\345\207\272\346\226\207\344\273\266.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276_\350\276\223\345\207\272\346\226\207\344\273\266.txt" @@ -1,95 +1,95 @@ - -#什么是码位: ->>> '你好呀'.encode("unicode_escape").decode() -'\u4f60\u597d\u5440' ->>> '你好呀' -'你好呀' - -#编码: ->>> "你好呀".encode("utf-8") -b'你好呀' - -#解码: ->>> b = "你好呀".encode("utf-8") ->>> b.decode("utf") -'你好呀' - -#检测编码: ->>> import chardet ->>> chardet.detect(b) -{'encoding': 'utf-8', 'confidence': 0.87625, 'language': ''} - -#忽略错误编码: ->>> b_2 = "你好呀".encode("utf-8")+"我很好".encode("gbk") ->>> b_2 -b'你好呀ÎҺܺÃ' ->>> b_2.decode("utf-8", errors='ignore') -'你好呀Һܺ' - -#利用鬼符来替换: ->>> b_2.decode("utf-8", errors='replace') -'你好呀�Һܺ�' - -#字符串的CRUD操作: -#Create ->>> a = "Hello World!" ->>> id(a) -2333141953392 ->>> a += "I am Macintosh" ->>> id(a) -2333141149216 ->>> a -'Hello World!I am Macintosh' - -#Retrieve ->>> a[10] -'d' ->>> a.find("Macintosh") -17 ->>> a.index("M") -17 ->>> a.find("m") -15 ->>> a.startswith("hello") -False ->>> a.startswith("Hello") -True ->>> a.endswith("s") -False ->>> a.endswith("h") -True - -#Update ->>> a.replace("I am", "My name is") -'Hello World!My name is Macintosh' ->>> a.split("!") -['Hello World', 'I am Macintosh'] ->>> b = a.split("!") ->>> ".".join(b) -'Hello World.I am Macintosh' - -#Delete ->>> c = " Hello, World!! " ->>> c.strip() -'Hello, World!!' ->>> c.rstrip() -' Hello, World!!' ->>> c.lstrip().lstrip('Hello') -', World!! ' - -#字符串格式化输出 ->>> a = "China" ->>> b = "Chendu" ->>> "come to {} {}".format(a,b) -'come to China Chendu' ->>> "come to {0} {1} {1} {0}".format(a,b) -'come to China Chendu Chendu China' ->>> "come to {c} {d} {d} {c}".format(c='china',d='chengdu') -'come to china chengdu chengdu china' ->>> print(f"come {a} {b}") -come China Chendu ->>> "{:.2f}".format(3.1415926) -'3.14' ->>> "let's go to %s" % ("Shanghai!") -"let's go to Shanghai!" - + +#什么是码位: +>>> '你好呀'.encode("unicode_escape").decode() +'\u4f60\u597d\u5440' +>>> '你好呀' +'你好呀' + +#编码: +>>> "你好呀".encode("utf-8") +b'你好呀' + +#解码: +>>> b = "你好呀".encode("utf-8") +>>> b.decode("utf") +'你好呀' + +#检测编码: +>>> import chardet +>>> chardet.detect(b) +{'encoding': 'utf-8', 'confidence': 0.87625, 'language': ''} + +#忽略错误编码: +>>> b_2 = "你好呀".encode("utf-8")+"我很好".encode("gbk") +>>> b_2 +b'你好呀ÎҺܺÃ' +>>> b_2.decode("utf-8", errors='ignore') +'你好呀Һܺ' + +#利用鬼符来替换: +>>> b_2.decode("utf-8", errors='replace') +'你好呀�Һܺ�' + +#字符串的CRUD操作: +#Create +>>> a = "Hello World!" +>>> id(a) +2333141953392 +>>> a += "I am Macintosh" +>>> id(a) +2333141149216 +>>> a +'Hello World!I am Macintosh' + +#Retrieve +>>> a[10] +'d' +>>> a.find("Macintosh") +17 +>>> a.index("M") +17 +>>> a.find("m") +15 +>>> a.startswith("hello") +False +>>> a.startswith("Hello") +True +>>> a.endswith("s") +False +>>> a.endswith("h") +True + +#Update +>>> a.replace("I am", "My name is") +'Hello World!My name is Macintosh' +>>> a.split("!") +['Hello World', 'I am Macintosh'] +>>> b = a.split("!") +>>> ".".join(b) +'Hello World.I am Macintosh' + +#Delete +>>> c = " Hello, World!! " +>>> c.strip() +'Hello, World!!' +>>> c.rstrip() +' Hello, World!!' +>>> c.lstrip().lstrip('Hello') +', World!! ' + +#字符串格式化输出 +>>> a = "China" +>>> b = "Chendu" +>>> "come to {} {}".format(a,b) +'come to China Chendu' +>>> "come to {0} {1} {1} {0}".format(a,b) +'come to China Chendu Chendu China' +>>> "come to {c} {d} {d} {c}".format(c='china',d='chengdu') +'come to china chengdu chengdu china' +>>> print(f"come {a} {b}") +come China Chendu +>>> "{:.2f}".format(3.1415926) +'3.14' +>>> "let's go to %s" % ("Shanghai!") +"let's go to Shanghai!" + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\200\350\212\202/threading_multiprocessing1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\200\350\212\202/threading_multiprocessing1.py" index cbb244345f56b2933cbf7a351168d44298ee3622..93a2043ab2786a26ed359530b83ee6104204df0d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\200\350\212\202/threading_multiprocessing1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\200\350\212\202/threading_multiprocessing1.py" @@ -1,46 +1,46 @@ -import requests -from threading import Thread -from multiprocessing import Process -import time - - -def request_bilibili(): - url = "https://www.bilibili.com/" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(response) - -def math_test(): - number = 2 - while number<10000000: - number**=2 - print("math_test done") - - - -if __name__ == '__main__': - start_time = time.time() - thread_array = [] - for i in range(10): - t = Thread(target=request_bilibili) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - end_time = time.time() - print(f"多线程获取10次bilibili首页运行了{end_time-start_time} s") - - start_time2 = time.time() - process_array = [] - for j in range(10): - p = Process(target=math_test) - process_array.append(p) - p.start() - for p in process_array: - p.join() - end_time2 = time.time() - print(f"多进程运行10次计算密集型程序math_test用了{end_time2-start_time2} s") - - +import requests +from threading import Thread +from multiprocessing import Process +import time + + +def request_bilibili(): + url = "https://www.bilibili.com/" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(response) + +def math_test(): + number = 2 + while number<10000000: + number**=2 + print("math_test done") + + + +if __name__ == '__main__': + start_time = time.time() + thread_array = [] + for i in range(10): + t = Thread(target=request_bilibili) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + end_time = time.time() + print(f"多线程获取10次bilibili首页运行了{end_time-start_time} s") + + start_time2 = time.time() + process_array = [] + for j in range(10): + p = Process(target=math_test) + process_array.append(p) + p.start() + for p in process_array: + p.join() + end_time2 = time.time() + print(f"多进程运行10次计算密集型程序math_test用了{end_time2-start_time2} s") + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\211\350\212\202/Coroutine_asynchronous_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\211\350\212\202/Coroutine_asynchronous_test.py" index 056d7ca6145a2a8594ae7619dacc2bff474d9667..2ed0b2f6d070c4e6bd0e8866295db42e67efd2ec 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\211\350\212\202/Coroutine_asynchronous_test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\270\211\350\212\202/Coroutine_asynchronous_test.py" @@ -1,52 +1,52 @@ -import asyncio -import requests -import aiohttp - - -# 协程实现平均数 -def coro_avg(): - total = 0 - lengh = 0 - while True: - try: - value = yield total/lengh - except ZeroDivisionError: - value = yield 0 - total += value - lengh += 1 - -my_avg = coro_avg() -next(my_avg) -print(my_avg.send(1)) -print(my_avg.send(2)) -print(my_avg.send(3)) - - -# asyncio异步程序 -async def do_something(index): - print(f"第{index}个任务启动") - await asyncio.sleep(1) - print(f"第{index}个任务完成") - -loop = asyncio.get_event_loop() -task_array = [] -for i in range(10): - task_array.append(do_something(i)) -loop.run_until_complete(asyncio.wait(task_array)) - - -# aiohttp异步请求网页 -async def fetch(session, url): - async with session.get(url) as response: - return await response.text() - -async def bilibili_request(index): - print(f"第{index}个网页抓取启动") - async with aiohttp.ClientSession() as session: - html = await fetch(session, "https://www.bilibili.com/") - print(html) -task_array2 = [] -for i in range(10): - task_array2.append(bilibili_request(i)) -loop.run_until_complete(asyncio.wait(task_array2)) -loop.close() +import asyncio +import requests +import aiohttp + + +# 协程实现平均数 +def coro_avg(): + total = 0 + lengh = 0 + while True: + try: + value = yield total/lengh + except ZeroDivisionError: + value = yield 0 + total += value + lengh += 1 + +my_avg = coro_avg() +next(my_avg) +print(my_avg.send(1)) +print(my_avg.send(2)) +print(my_avg.send(3)) + + +# asyncio异步程序 +async def do_something(index): + print(f"第{index}个任务启动") + await asyncio.sleep(1) + print(f"第{index}个任务完成") + +loop = asyncio.get_event_loop() +task_array = [] +for i in range(10): + task_array.append(do_something(i)) +loop.run_until_complete(asyncio.wait(task_array)) + + +# aiohttp异步请求网页 +async def fetch(session, url): + async with session.get(url) as response: + return await response.text() + +async def bilibili_request(index): + print(f"第{index}个网页抓取启动") + async with aiohttp.ClientSession() as session: + html = await fetch(session, "https://www.bilibili.com/") + print(html) +task_array2 = [] +for i in range(10): + task_array2.append(bilibili_request(i)) +loop.run_until_complete(asyncio.wait(task_array2)) +loop.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/test.log" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/test.log" index 88f83b05a8dc65b65b8faecbf0cc1dffe5c585c2..7ffb29fc486725f424dc85e4d11e333734bd72f7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/test.log" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/test.log" @@ -1,10 +1,10 @@ -:2 -:6 -:1 -:4 -:9 -:0 -:8 -:7 -:3 -:5 +:2 +:6 +:1 +:4 +:9 +:0 +:8 +:7 +:3 +:5 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/threading_multiprocessing2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/threading_multiprocessing2.py" index 37fd73f017d70096dd1ffc00aeeae23b3c3de716..cf06571c168ac175cb72f13021c08e2121ac89e2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/threading_multiprocessing2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\214\350\212\202/threading_multiprocessing2.py" @@ -1,69 +1,69 @@ -import requests -from threading import Thread -from multiprocessing import Process, Lock, Queue -import time - - -def request_bilibili(index, lock): - url = "https://www.bilibili.com/" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(response) - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(response) + ":" + str(index) + "\n") - -zero = 0 -lock2 = Lock() -def math_test(): - global zero - number = 2 - while number<10000000: - number**=2 - with lock2: - zero += 1 - zero -= 1 - print("math_test done") - -def save_to_queue(index, my_queue): - my_queue.put(index) - -if __name__ == '__main__': - start_time = time.time() - thread_array = [] - lock = Lock() - for i in range(10): - t = Thread(target=request_bilibili, args=(i, lock)) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - end_time = time.time() - print(f"加锁多线程获取10次bilibili首页运行了{end_time-start_time} s") - - start_time2 = time.time() - process_array = [] - for j in range(10): - p = Process(target=math_test) - process_array.append(p) - p.start() - for p in process_array: - p.join() - end_time2 = time.time() - print(f"加锁多进程运行10次计算密集型程序math_test用了{end_time2-start_time2} s, zero = {zero}") - - start_time3 = time.time() - process_array2 = [] - my_queue = Queue() - for k in range(10): - p2 = Process(target=save_to_queue, args=(k, my_queue)) - process_array2.append(p2) - p2.start() - for p2 in process_array2: - p2.join() - for l in range(10): - print(my_queue.get()) - end_time3 = time.time() - print(f"使用queue进行多线程通信用了{end_time3-start_time3} s") +import requests +from threading import Thread +from multiprocessing import Process, Lock, Queue +import time + + +def request_bilibili(index, lock): + url = "https://www.bilibili.com/" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(response) + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(response) + ":" + str(index) + "\n") + +zero = 0 +lock2 = Lock() +def math_test(): + global zero + number = 2 + while number<10000000: + number**=2 + with lock2: + zero += 1 + zero -= 1 + print("math_test done") + +def save_to_queue(index, my_queue): + my_queue.put(index) + +if __name__ == '__main__': + start_time = time.time() + thread_array = [] + lock = Lock() + for i in range(10): + t = Thread(target=request_bilibili, args=(i, lock)) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + end_time = time.time() + print(f"加锁多线程获取10次bilibili首页运行了{end_time-start_time} s") + + start_time2 = time.time() + process_array = [] + for j in range(10): + p = Process(target=math_test) + process_array.append(p) + p.start() + for p in process_array: + p.join() + end_time2 = time.time() + print(f"加锁多进程运行10次计算密集型程序math_test用了{end_time2-start_time2} s, zero = {zero}") + + start_time3 = time.time() + process_array2 = [] + my_queue = Queue() + for k in range(10): + p2 = Process(target=save_to_queue, args=(k, my_queue)) + process_array2.append(p2) + p2.start() + for p2 in process_array2: + p2.join() + for l in range(10): + print(my_queue.get()) + end_time3 = time.time() + print(f"使用queue进行多线程通信用了{end_time3-start_time3} s") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\253\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\253\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" index e57a06e3a297c6e03d5c35ff67d6fc086cb144fe..27786a5aa760f9021b29cd837feddacb54142002 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\253\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\253\345\221\250/\347\254\254\344\270\211\350\212\202/main.py" @@ -1,74 +1,74 @@ -from week5.lesson9.main import clock_it_deco -import pymysql -import random -import time - - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "0000", - "db": "tunan_class_4" -} - -# 连接数据库 -mysql_con = pymysql.connect(**MYSQL_CONF) - -# 执行语句的线程 -mysql_cursor = mysql_con.cursor() - -def insert_one(): - for i in range(10 ** 4): - store_name = f"店铺_{i}" - amount = format(random.uniform(10 ** 3, 10 ** 6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES ('{store_name}', {amount},'{department}', '{sta_date}')""" - print(SQL) - mysql_cursor.execute(SQL) - - # 显示执行commit,避免cursor执行,但是数据库未收到执行指令的情况 - mysql_con.commit() - -@clock_it_deco -def insert_many(): - values = [] - for i in range(10**6): - store_name = f"店铺_{i}" - amount = format(random.uniform(10 ** 3, 10 ** 6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - values.append((store_name, amount, department, sta_date)) - - SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES (%s, %s, %s, %s)""" - print(values) - mysql_cursor.executemany(SQL) - mysql_con.commit() - -def get_shops(): - SQL = "select store_name from store_perf where department='事业部_1'" - mysql_cursor.execute(SQL) - query_set = mysql_cursor.fetchall() - print(query_set) - -def transaction(): - try: - SQL = "DELETE FROM class_2 where name='name_15'" - mysql_cursor.execute(SQL) - SQL_2 = "INSERT INTO class_1 VALUES(name)" - mysql_cursor.execute(SQL_2) - except Exception as e: - print("raise Exception", e.args[0]) - print("rollback") - #mysql_con.rollback() - finally: - mysql_con.commit() - -if __name__ == "__main__": - # insert_one() - insert_many() - get_shops() +from week5.lesson9.main import clock_it_deco +import pymysql +import random +import time + + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "0000", + "db": "tunan_class_4" +} + +# 连接数据库 +mysql_con = pymysql.connect(**MYSQL_CONF) + +# 执行语句的线程 +mysql_cursor = mysql_con.cursor() + +def insert_one(): + for i in range(10 ** 4): + store_name = f"店铺_{i}" + amount = format(random.uniform(10 ** 3, 10 ** 6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES ('{store_name}', {amount},'{department}', '{sta_date}')""" + print(SQL) + mysql_cursor.execute(SQL) + + # 显示执行commit,避免cursor执行,但是数据库未收到执行指令的情况 + mysql_con.commit() + +@clock_it_deco +def insert_many(): + values = [] + for i in range(10**6): + store_name = f"店铺_{i}" + amount = format(random.uniform(10 ** 3, 10 ** 6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + values.append((store_name, amount, department, sta_date)) + + SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES (%s, %s, %s, %s)""" + print(values) + mysql_cursor.executemany(SQL) + mysql_con.commit() + +def get_shops(): + SQL = "select store_name from store_perf where department='事业部_1'" + mysql_cursor.execute(SQL) + query_set = mysql_cursor.fetchall() + print(query_set) + +def transaction(): + try: + SQL = "DELETE FROM class_2 where name='name_15'" + mysql_cursor.execute(SQL) + SQL_2 = "INSERT INTO class_1 VALUES(name)" + mysql_cursor.execute(SQL_2) + except Exception as e: + print("raise Exception", e.args[0]) + print("rollback") + #mysql_con.rollback() + finally: + mysql_con.commit() + +if __name__ == "__main__": + # insert_one() + insert_many() + get_shops() transaction() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\344\272\224\345\261\202\345\215\217\350\256\256.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\344\272\224\345\261\202\345\215\217\350\256\256.md" index acb612e03880ddcd455361020410c96acb5e67df..6a6bd43433c8b5b06160ea58d24f9a21205ccf80 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\344\272\224\345\261\202\345\215\217\350\256\256.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\344\272\224\345\261\202\345\215\217\350\256\256.md" @@ -1,148 +1,148 @@ -# 第六周-第一节课 - -- ## 输入网址后发生了什么 - - - 输入`url` - - 统一资源定位器`uniform resource locator` - - - `url`组成 - - ``` - https://www.baidu.com/ - 协议://域名[:端口]/路径 - ``` - - - `url`作用 - - 定位指定的资源. - - > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. - - - DNS解析 - - 域名系统`Domain Name System`, 将域名解析为`IP`地址 - - - 域名解析流程 - - 域名([www.baidu.com](http://www.baidu.com/)) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 - - - 客户端与服务器建立连接. - - 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 - - - 客户端正式向服务端发送请求. - - - 服务端处理请求并返回结果 - - - 浏览器接收到响应后, 做相应的渲染 - -## TCP/IP的五层协议 - -![TCPIP五层协议](C:\Users\pingp\Desktop\TCPIP五层协议.png) - -- 应用层 - - 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. - - ``` - 浏览网页 - 网易云 - 用python模拟请求 - ``` - - - 应用层协议 - - HTTP/HTTPS(超文本传输协议) - - DNS(域名系统) - - FTP(文件传输协议) - - SMTP(邮箱传输协议) - -- 传输层 - - 负责向两个主机应用进程的通信提供服务. - - > 一个主机可以开启不同的因看应用, 同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 - - ``` - 进程 <---> 进程 - ``` - - - 传输层协议 - - - TCP(传输控制协议) - - 提供面向连接, (尽可能)可靠的数据传输服务. - - ``` - 一对一 - ``` - - ``` - 面向连接指的就是, 客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. - ``` - - - 文件传输(FTP) - - 浏览网页(HTTP) - - - UDP(用户数据协议) - - 提供无连接的, 不保证数据传输的可靠性 - - ``` - 一对多, 一对一, 多对多... - ``` - - - 直播 - - 实况游戏 - -- 网络层 - - 决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. - - ``` - 主机 <---> 主机 - ``` - - - 网络层协议 - - - IP协议 - - - 公网IP - - 也就是指的传统IP地址, 是唯一的. - - - 局域网IP - - ``` - ipconfig - ``` - -- 数据链路层 - - 负责两台主机之间的数据传输, 向网路层提供数据传输服务 - - ``` - 网卡 <---> 网卡 - ``` - - - 数据链路层的作用 - - 比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是检错和纠错 - - - *流量控制 - - 差错检测 - - 差错控制 - -- 物理层 - - 物理层再局部局域网上传送数据帧, 在设备节点传输比特流. - - ``` - 光纤 <---> 光纤 - ``` - - - 物理层和数据链路层 - - ``` - 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. +# 第六周-第一节课 + +- ## 输入网址后发生了什么 + + - 输入`url` + + 统一资源定位器`uniform resource locator` + + - `url`组成 + + ``` + https://www.baidu.com/ + 协议://域名[:端口]/路径 + ``` + + - `url`作用 + + 定位指定的资源. + + > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. + + - DNS解析 + + 域名系统`Domain Name System`, 将域名解析为`IP`地址 + + - 域名解析流程 + + 域名([www.baidu.com](http://www.baidu.com/)) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 + + - 客户端与服务器建立连接. + + 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 + + - 客户端正式向服务端发送请求. + + - 服务端处理请求并返回结果 + + - 浏览器接收到响应后, 做相应的渲染 + +## TCP/IP的五层协议 + +![TCPIP五层协议](C:\Users\pingp\Desktop\TCPIP五层协议.png) + +- 应用层 + + 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. + + ``` + 浏览网页 + 网易云 + 用python模拟请求 + ``` + + - 应用层协议 + - HTTP/HTTPS(超文本传输协议) + - DNS(域名系统) + - FTP(文件传输协议) + - SMTP(邮箱传输协议) + +- 传输层 + + 负责向两个主机应用进程的通信提供服务. + + > 一个主机可以开启不同的因看应用, 同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 + + ``` + 进程 <---> 进程 + ``` + + - 传输层协议 + + - TCP(传输控制协议) + + 提供面向连接, (尽可能)可靠的数据传输服务. + + ``` + 一对一 + ``` + + ``` + 面向连接指的就是, 客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. + ``` + + - 文件传输(FTP) + - 浏览网页(HTTP) + + - UDP(用户数据协议) + + 提供无连接的, 不保证数据传输的可靠性 + + ``` + 一对多, 一对一, 多对多... + ``` + + - 直播 + - 实况游戏 + +- 网络层 + + 决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. + + ``` + 主机 <---> 主机 + ``` + + - 网络层协议 + + - IP协议 + + - 公网IP + + 也就是指的传统IP地址, 是唯一的. + + - 局域网IP + + ``` + ipconfig + ``` + +- 数据链路层 + + 负责两台主机之间的数据传输, 向网路层提供数据传输服务 + + ``` + 网卡 <---> 网卡 + ``` + + - 数据链路层的作用 + + 比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是检错和纠错 + + - *流量控制 + - 差错检测 + - 差错控制 + +- 物理层 + + 物理层再局部局域网上传送数据帧, 在设备节点传输比特流. + + ``` + 光纤 <---> 光纤 + ``` + + - 物理层和数据链路层 + + ``` + 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. ``` \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\350\277\233\351\230\266\345\217\212HTTPS\345\212\240\345\257\206.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\350\277\233\351\230\266\345\217\212HTTPS\345\212\240\345\257\206.md" index 27867f3e606823c777e19ac932ef2d357fde61d0..bcd8d62c67f26af52d8d6e0e3d736174cceb226b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\350\277\233\351\230\266\345\217\212HTTPS\345\212\240\345\257\206.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/TCPIP\350\277\233\351\230\266\345\217\212HTTPS\345\212\240\345\257\206.md" @@ -1,85 +1,85 @@ -# 第六周-第二节课 - -## 理解TCP/IP协议 - -- 什么是TCP/IP协议 - - `TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. - -- TCP/IP的作用 - - 起到了应用和硬件的之间承上启下的作用. - - ``` - 手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 - ``` - -## TCP/IP三次握手 - -为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. - -![img](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) - -- 三次握手的过程 - - - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 - - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 - - 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 - -- 第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? - - 为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. - -## TCP/IP四次挥手 - -![img](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) - -- 四次挥手的过程 - - ``` - 我们以客户端作为主动关闭方来描述四次挥手过程 - ``` - - - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 - - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 - - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 - - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 - -## HTTPS - -![img](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) - -- https加密的过程 - - - 客户端向服务端发送通信请求 - - - 服务端返回给客户端证书和密钥 - - - 客户端通过CA中心验证证书的真实性 - - - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. - - - 非对称加密 - - ``` - 16 = 2* 8 也可以是 4 * 4 - 公钥就是拿到了16这个结果 - 私钥就是某个因数2 - 通过这样的方式才可以得出唯一解8 - ``` - - - 服务端收到加密后的请求数据后, 使用私钥进行解密. - - - 服务器和客户端使用**对称加密**进行通信 - -- 中间人攻击 - - ![img](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) - - 插入到客户端和服务端之间的通信, 对服务端伪造客户都安, 对客户端伪造服务端, 拦截通信产生的数据. - - - 产生的条件 - - 我们的客户端要主动信任中间人的证书 - +# 第六周-第二节课 + +## 理解TCP/IP协议 + +- 什么是TCP/IP协议 + + `TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. + +- TCP/IP的作用 + + 起到了应用和硬件的之间承上启下的作用. + + ``` + 手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 + ``` + +## TCP/IP三次握手 + +为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. + +![img](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) + +- 三次握手的过程 + + - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 + - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 + - 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 + +- 第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? + + 为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. + +## TCP/IP四次挥手 + +![img](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) + +- 四次挥手的过程 + + ``` + 我们以客户端作为主动关闭方来描述四次挥手过程 + ``` + + - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 + - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 + - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 + - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 + +## HTTPS + +![img](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) + +- https加密的过程 + + - 客户端向服务端发送通信请求 + + - 服务端返回给客户端证书和密钥 + + - 客户端通过CA中心验证证书的真实性 + + - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. + + - 非对称加密 + + ``` + 16 = 2* 8 也可以是 4 * 4 + 公钥就是拿到了16这个结果 + 私钥就是某个因数2 + 通过这样的方式才可以得出唯一解8 + ``` + + - 服务端收到加密后的请求数据后, 使用私钥进行解密. + + - 服务器和客户端使用**对称加密**进行通信 + +- 中间人攻击 + + ![img](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) + + 插入到客户端和服务端之间的通信, 对服务端伪造客户都安, 对客户端伪造服务端, 拦截通信产生的数据. + + - 产生的条件 + + 我们的客户端要主动信任中间人的证书 + ### 评论 ( 0 ) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/\346\212\223\345\214\205\344\270\216\346\250\241\346\213\237\350\257\267\346\261\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/\346\212\223\345\214\205\344\270\216\346\250\241\346\213\237\350\257\267\346\261\202.md" index 65eb36926707b66e677a0e67db1bec99409554e1..affec64de0f0949689798b9b44765fad19fccce6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/\346\212\223\345\214\205\344\270\216\346\250\241\346\213\237\350\257\267\346\261\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\205\255\345\221\250/\346\212\223\345\214\205\344\270\216\346\250\241\346\213\237\350\257\267\346\261\202.md" @@ -1,90 +1,90 @@ -# 第六周-第三节课 - -## 抓包 - -抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. - -对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. - -- 抓包软件 - - - Fiddler - - ``` - https://www.telerik.com/fiddler - ``` - - - Charles - - - wireshark - -- web端抓包 - - 现代互联网环境几乎都是https协议的网站 - - - 信任证书 - - ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) - - ``` - Rules -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -- App端抓包 - - ``` - 下载夜神模拟器 - ``` - - - 打开远程终端连接 - - ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) - - Rules -> Options -> Connections -> Allow remote computes to connect - - ``` - - 把手机/模拟器的代理指向fiddler - ``` - - - wifi调出设置的时候要长按 - - - 查看当前fiddler所在pc本地局域网ip - - - ipconfig/ifconfig - - - 在代理项中填写ip地址和fiddler端口, 默认是8888 - - - 信任证书 - - - App有一定的反爬措施, 第一件事就是修改请求协议 - - - 双向验证 - - 需要客户端也带上证书 - - - 解决请求协议上的反爬措施 - - - 安装VirtualXposed_0.18.2, JustTrustMe - -## 模拟请求 - -- PostMan简单使用 - - - GET - - - POST - - - form_data - - 参数表单 - - - x-www-form-urlencoded - - 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 - - - raw - +# 第六周-第三节课 + +## 抓包 + +抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. + +对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. + +- 抓包软件 + + - Fiddler + + ``` + https://www.telerik.com/fiddler + ``` + + - Charles + + - wireshark + +- web端抓包 + + 现代互联网环境几乎都是https协议的网站 + + - 信任证书 + + ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) + + ``` + Rules -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +- App端抓包 + + ``` + 下载夜神模拟器 + ``` + + - 打开远程终端连接 + + ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) + + Rules -> Options -> Connections -> Allow remote computes to connect + + ``` + - 把手机/模拟器的代理指向fiddler + ``` + + - wifi调出设置的时候要长按 + + - 查看当前fiddler所在pc本地局域网ip + + - ipconfig/ifconfig + + - 在代理项中填写ip地址和fiddler端口, 默认是8888 + + - 信任证书 + + - App有一定的反爬措施, 第一件事就是修改请求协议 + + - 双向验证 + + 需要客户端也带上证书 + + - 解决请求协议上的反爬措施 + + - 安装VirtualXposed_0.18.2, JustTrustMe + +## 模拟请求 + +- PostMan简单使用 + + - GET + + - POST + + - form_data + + 参数表单 + + - x-www-form-urlencoded + + 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 + + - raw + 请求的真实body内容. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" index eddb8fff38e17f66486e0bedfea0275b1f8656cd..7b150cb8355ac05062a1dba1a6e7ad609a031443 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" @@ -1,56 +1,56 @@ -import scrapy -from bs4 import BeautifulSoup -import json -from jd_crawler_scrapy.items import JdCrawlerScrapyItem - - -class JdSearch(scrapy.Spider): - name = "jd_search" - - def start_requests(self): - for keyword in ["手机", "电脑", "相机", "书籍"]: - for page_number in range(1, 11): - url = f"https://search.jd.com/Search?keyword={keyword}&page={page_number}" - - # 选用FormRequest是可以发送GET和POST请求 - yield scrapy.FormRequest( - url=url, - method='GET', - # formdata=data #如果是post请求,携带数据使用formdata参数 - callback=self.parse_search # 指定回调函数处理response对象 - ) - break - - def parse_search(self, response): - print(response) - soup = BeautifulSoup(response.text, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - try: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - # title = item.select("div[class='p-name']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].a.attrs['title'] if shop else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' - - item = JdCrawlerScrapyItem() - item["sku_id"] = sku_id - item["img"] = img - item["price"] = price - item["title"] = title - item["shop"] = shop - item["icons"] = icons - yield item - - - except Exception as e: - print(e.args) - +import scrapy +from bs4 import BeautifulSoup +import json +from jd_crawler_scrapy.items import JdCrawlerScrapyItem + + +class JdSearch(scrapy.Spider): + name = "jd_search" + + def start_requests(self): + for keyword in ["手机", "电脑", "相机", "书籍"]: + for page_number in range(1, 11): + url = f"https://search.jd.com/Search?keyword={keyword}&page={page_number}" + + # 选用FormRequest是可以发送GET和POST请求 + yield scrapy.FormRequest( + url=url, + method='GET', + # formdata=data #如果是post请求,携带数据使用formdata参数 + callback=self.parse_search # 指定回调函数处理response对象 + ) + break + + def parse_search(self, response): + print(response) + soup = BeautifulSoup(response.text, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + try: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + # title = item.select("div[class='p-name']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].a.attrs['title'] if shop else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' + + item = JdCrawlerScrapyItem() + item["sku_id"] = sku_id + item["img"] = img + item["price"] = price + item["title"] = title + item["shop"] = shop + item["icons"] = icons + yield item + + + except Exception as e: + print(e.args) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" index 066217194c3487124795dec380bafafd114ef6b0..d65b88a0b2aeb9dfeeb123844ab46fd82295043f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\343\200\201\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" @@ -1,4 +1,4 @@ -from scrapy import cmdline - -command = "scrapy crawl jd_search".split() +from scrapy import cmdline + +command = "scrapy crawl jd_search".split() cmdline.execute(command) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/time.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/time.py" index efa197095b785c65ef1cb0ff9569d0efcaa4a970..04241cdc013ce7023418eb2f69a1e903c0b625bf 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/time.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\200\350\212\202\350\257\276/time.py" @@ -1,23 +1,23 @@ -import datetime - -# 时间戳和datetime.datetime对象之间的转换 -timestamp = datetime.datetime.now().timestamp() -date = datetime.datetime.fromtimestamp(timestamp) - -# 时间戳和字符串之间的转换 -timestamp2 = datetime.datetime.now().timestamp() -date2 = datetime.datetime.fromtimestamp(timestamp2) -str2 = date.strftime('%Y-%m-%d %H:%M:%S') -datestamp = datetime.datetime.strptime(str2, '%Y-%m-%d %H:%M:%S') -timestamp4 = datestamp.timestamp() - -# 字符串和datetime之间的转换 -str3 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') -date3 = datetime.datetime.strptime(str3, '%Y-%m-%d %H:%M:%S') - -# 函数get_date() -def get_date(day_delta): - print(datetime.datetime.now() + datetime.timedelta(days=day_delta)) - - -get_date(-1) +import datetime + +# 时间戳和datetime.datetime对象之间的转换 +timestamp = datetime.datetime.now().timestamp() +date = datetime.datetime.fromtimestamp(timestamp) + +# 时间戳和字符串之间的转换 +timestamp2 = datetime.datetime.now().timestamp() +date2 = datetime.datetime.fromtimestamp(timestamp2) +str2 = date.strftime('%Y-%m-%d %H:%M:%S') +datestamp = datetime.datetime.strptime(str2, '%Y-%m-%d %H:%M:%S') +timestamp4 = datestamp.timestamp() + +# 字符串和datetime之间的转换 +str3 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +date3 = datetime.datetime.strptime(str3, '%Y-%m-%d %H:%M:%S') + +# 函数get_date() +def get_date(day_delta): + print(datetime.datetime.now() + datetime.timedelta(days=day_delta)) + + +get_date(-1) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/classtest2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/classtest2.py" index adba79bf6c178ee15c8fb499bd0d2e5987f8527a..e932453813b6a38fad5c5b040db88984b2f62055 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/classtest2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\270\211\350\212\202\350\257\276/classtest2.py" @@ -1,56 +1,56 @@ -# 计算器静态实现 -class MyMath: - @staticmethod - def add(a, b): - return a + b - - @staticmethod - def sub(a, b): - return a - b - - @staticmethod - def mul(a, b): - return a * b - - @staticmethod - def div(a, b): - return a / b - - @staticmethod - def exdiv(a, b): - return a // b - - @staticmethod - def rem(a, b): - return a % b - - @staticmethod - def pow(a, b): - return a ** b - -print(MyMath.mul(1,2)) - -# 类进阶练习 -class Person: - earth_creature = True - __gender = None - def eat(self): - print("I can eat") - def sleep(self): - print("I can sleep") - def __init__(self, name, age): - self.name = name - self.__age = age - - @classmethod - def __new__(cls, *args, **kwargs): - print("I am smart") - return super().__new__(cls) - - def __str__(self): - return f"我的名字是{self.name},年龄是{self.__age}" - -jack = Person("jack", 22) -jack._Person__gender = "Man" -print(jack._Person__gender) +# 计算器静态实现 +class MyMath: + @staticmethod + def add(a, b): + return a + b + + @staticmethod + def sub(a, b): + return a - b + + @staticmethod + def mul(a, b): + return a * b + + @staticmethod + def div(a, b): + return a / b + + @staticmethod + def exdiv(a, b): + return a // b + + @staticmethod + def rem(a, b): + return a % b + + @staticmethod + def pow(a, b): + return a ** b + +print(MyMath.mul(1,2)) + +# 类进阶练习 +class Person: + earth_creature = True + __gender = None + def eat(self): + print("I can eat") + def sleep(self): + print("I can sleep") + def __init__(self, name, age): + self.name = name + self.__age = age + + @classmethod + def __new__(cls, *args, **kwargs): + print("I am smart") + return super().__new__(cls) + + def __str__(self): + return f"我的名字是{self.name},年龄是{self.__age}" + +jack = Person("jack", 22) +jack._Person__gender = "Man" +print(jack._Person__gender) print(jack) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/classtest.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/classtest.py" index b408e759a1c8bd4b4ab0cfa22924c3abbe8933ed..401cabf0e11f63cb6a93dfa3474b2ab8faeaccc2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/classtest.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_LiPing/\347\254\254\345\233\233\345\221\250/\347\254\254\344\272\214\350\212\202\350\257\276/classtest.py" @@ -1,47 +1,47 @@ -# 类实现计算器 -class MyMath: - def add(self, a, b): - return a + b - - def sub(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - return a / b - - def exdiv(self, a, b): - return a // b - - def rem(self, a, b): - return a % b - - def pow(self, a, b): - return a ** b - -# 类的实现 -class Person(object): - def eat(self): - print("I can eat") - def sleep(self): - print("I can sleep") - def __init__(self, name): - self.name = name -# 类的实例化 -jack = Person("Jack") -Lihua = Person("Lihua") - - -# 类的继承 -class Chinese(Person): - def unity(self): - print("我们团结一心") - -class Japanese(Person): - def baga(self): - print("八嘎呀路") - - - +# 类实现计算器 +class MyMath: + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def exdiv(self, a, b): + return a // b + + def rem(self, a, b): + return a % b + + def pow(self, a, b): + return a ** b + +# 类的实现 +class Person(object): + def eat(self): + print("I can eat") + def sleep(self): + print("I can sleep") + def __init__(self, name): + self.name = name +# 类的实例化 +jack = Person("Jack") +Lihua = Person("Lihua") + + +# 类的继承 +class Chinese(Person): + def unity(self): + print("我们团结一心") + +class Japanese(Person): + def baga(self): + print("八嘎呀路") + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202" index 45579b9756fdaa21a6449ffafac3231cabb74d44..e07b6384f015581516dee8b3cdd1373252dc509b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202" @@ -1,7 +1,7 @@ -问题一:list、dict、set可变,tuple不可变 -问题二:list、tuple有序,dict、set无序 -问题三: -[1, 1.0, 'a', True, b'str', None] -(1, 1.0, 'a', True, b'str', None) -{1:1, 1.0:1, 'a':1, True:1, b'str':1, None:1} +问题一:list、dict、set可变,tuple不可变 +问题二:list、tuple有序,dict、set无序 +问题三: +[1, 1.0, 'a', True, b'str', None] +(1, 1.0, 'a', True, b'str', None) +{1:1, 1.0:1, 'a':1, True:1, b'str':1, None:1} {1, 1.0, 'a', True, b'str', None} \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\200\350\212\202" index 340cb068200e80b81473d8cae74e64b8a7539396..84142335b35d90a09efc714429993dcc0a3f471a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,10 +1,10 @@ -create database test; //创建数据库 -drop database test; //删除数据库 -use test; //进入数据库 -create table username (id, name); //创建表 -drop table username; //删除表 -insert into username -{id, name} -values -("1", "lisi"); //插入数据 +create database test; //创建数据库 +drop database test; //删除数据库 +use test; //进入数据库 +create table username (id, name); //创建表 +drop table username; //删除表 +insert into username +{id, name} +values +("1", "lisi"); //插入数据 select * from username; //查询表 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\211\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\211\350\212\202" index a4e4c6dc3f158b5f3dfc8a2e8c64afdc3e0a2607..de00c58d02569fb6fa41736bfe89e2ea6cc6dbc6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\211\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\203\345\221\250_\347\254\254\344\270\211\350\212\202" @@ -1,50 +1,50 @@ -select name from class_1; - -select * from class_1 where name like '%1'; - -select * from class_1 where name like '%1' limit 1; - -select distince name from class_1; - -select * from class_1 order by create_time DESC - -select count(*) from class_1; - -update class_1 set id='10' where name='test1'; - -delete from class_1 where id='1'; - -select name from class1 where name is not NULL -union -select name from class2 where name is not NULL -//交集 -select t1.name from -(select name from class1 where name is not NULL) as t1 -join -(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name //where性能差,建议使用on -//差集(LEFT JOIN, RIGHT JOIN) -select t1.name from -(select name from class1 where name is not NULL) as t1 -left join -(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name -where s2.name is NULL - -select t2.name from -(select name from class1 where name is not NULL) as t1 -right join -(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name -where s1.name is NULL -//补集 -//等于A对B的差集 + B对A的差集 -select t1.name from -(select name from class1 where name is not NULL) as t1 -left join -(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name -where s2.name is NULL -union -select t2.name from -(select name from class1 where name is not NULL) as t1 -right join -(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name -where s1.name is NULL - +select name from class_1; + +select * from class_1 where name like '%1'; + +select * from class_1 where name like '%1' limit 1; + +select distince name from class_1; + +select * from class_1 order by create_time DESC + +select count(*) from class_1; + +update class_1 set id='10' where name='test1'; + +delete from class_1 where id='1'; + +select name from class1 where name is not NULL +union +select name from class2 where name is not NULL +//交集 +select t1.name from +(select name from class1 where name is not NULL) as t1 +join +(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name //where性能差,建议使用on +//差集(LEFT JOIN, RIGHT JOIN) +select t1.name from +(select name from class1 where name is not NULL) as t1 +left join +(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name +where s2.name is NULL + +select t2.name from +(select name from class1 where name is not NULL) as t1 +right join +(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name +where s1.name is NULL +//补集 +//等于A对B的差集 + B对A的差集 +select t1.name from +(select name from class1 where name is not NULL) as t1 +left join +(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name +where s2.name is NULL +union +select t2.name from +(select name from class1 where name is not NULL) as t1 +right join +(select name from class2 where name is not NULL) as t2 on/where t1.name = t2.name +where s1.name is NULL + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" index 8afa93fc9c1ba77d45b7ad3f89c4e4bad3a537cb..dc7aec390eea2171ef77050392e0709159f51962 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/count.py" @@ -1,9 +1,9 @@ -#使用for循环计数100之内 -for i in range(100): - print(f'{i} ',end='') -print('') -#使用while循环计数100之内 -i = 0 -while i < 100: - print(f'{i} ',end='') +#使用for循环计数100之内 +for i in range(100): + print(f'{i} ',end='') +print('') +#使用while循环计数100之内 +i = 0 +while i < 100: + print(f'{i} ',end='') i += 1 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/fibonacci.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/fibonacci.py" index 45a8888bf98f6ff5b1cfa83e6d0a9abdc906c4d4..e43c07dda8e2b7ee813fcb4fc184dcb30f0dbdc3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/fibonacci.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202/fibonacci.py" @@ -1,31 +1,31 @@ -#实现斐波那契数列for实现 -def fibonacci_for(): - L = [0, 1] #初始化列表 - i = 0 #定义一个初始的index - for i in range(100): #定义0-99数值 - if i == 0 or i == 1: - continue - else: - sum = L[i-2] + L[i-1] - L.append(sum) - return L - -#实现斐波那契数列while实现 -def fibonacci_while(): - L = [0, 1] - i = 0 - while i < 100: - if i == 0 or i == 1: - i += 1 - continue - else: - sum = L[i-2] + L[i-1] - L.append(sum) - i += 1 - return L - -if __name__ == '__main__': - L1 = fibonacci_for() - L2 = fibonacci_while() - print(f"for实现:{L1}") +#实现斐波那契数列for实现 +def fibonacci_for(): + L = [0, 1] #初始化列表 + i = 0 #定义一个初始的index + for i in range(100): #定义0-99数值 + if i == 0 or i == 1: + continue + else: + sum = L[i-2] + L[i-1] + L.append(sum) + return L + +#实现斐波那契数列while实现 +def fibonacci_while(): + L = [0, 1] + i = 0 + while i < 100: + if i == 0 or i == 1: + i += 1 + continue + else: + sum = L[i-2] + L[i-1] + L.append(sum) + i += 1 + return L + +if __name__ == '__main__': + L1 = fibonacci_for() + L2 = fibonacci_while() + print(f"for实现:{L1}") print(f"while实现:{L2}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202" index ec37531962ad959bd223d79caee42b745a11f4bd..e8eddd7ca847a5b8a75c50040e2b9efc0195da83 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202" @@ -1,28 +1,28 @@ -#实现斐波那契数列递归函数实现 -def mem_cache(func): - cache = {} - def wrapper(*args): - print(cache) - if args not in cache: - cache[args] = func(*args) - return cache[args] - return wrapper - -@mem_cache -def Fibonacci_Recursion_tool(n): - if n <= 0: - return 0 - elif n == 1: - return 1 - else: - return Fibonacci_Recursion_tool(n - 1) + Fibonacci_Recursion_tool(n - 2) - -def Fibonacci_Recursion(n): - result_list = [] - for i in range(0, n + 1): - result_list.append(Fibonacci_Recursion_tool(i)) - return result_list - -if __name__ == '__main__': - L3 = Fibonacci_Recursion(10) +#实现斐波那契数列递归函数实现 +def mem_cache(func): + cache = {} + def wrapper(*args): + print(cache) + if args not in cache: + cache[args] = func(*args) + return cache[args] + return wrapper + +@mem_cache +def Fibonacci_Recursion_tool(n): + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return Fibonacci_Recursion_tool(n - 1) + Fibonacci_Recursion_tool(n - 2) + +def Fibonacci_Recursion(n): + result_list = [] + for i in range(0, n + 1): + result_list.append(Fibonacci_Recursion_tool(i)) + return result_list + +if __name__ == '__main__': + L3 = Fibonacci_Recursion(10) print(f"递归实现: {L3}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/ rec_fib.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/ rec_fib.py" index 8f9e26e5587c1b864dc74366536ae4264be55554..1b32b84ed7fc906ca48a673b92ab3d5e1fdfbb7d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/ rec_fib.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/ rec_fib.py" @@ -1,18 +1,18 @@ -#实现斐波那契数列递归函数实现 -def Fibonacci_Recursion_tool(n): - if n <= 0: - return 0 - elif n == 1: - return 1 - else: - return Fibonacci_Recursion_tool(n - 1) + Fibonacci_Recursion_tool(n - 2) - -def Fibonacci_Recursion(n): - result_list = [] - for i in range(0, n + 1): - result_list.append(Fibonacci_Recursion_tool(i)) - return result_list - -if __name__ == '__main__': - L3 = Fibonacci_Recursion(10) +#实现斐波那契数列递归函数实现 +def Fibonacci_Recursion_tool(n): + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return Fibonacci_Recursion_tool(n - 1) + Fibonacci_Recursion_tool(n - 2) + +def Fibonacci_Recursion(n): + result_list = [] + for i in range(0, n + 1): + result_list.append(Fibonacci_Recursion_tool(i)) + return result_list + +if __name__ == '__main__': + L3 = Fibonacci_Recursion(10) print(f"递归实现: {L3}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/grade.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/grade.py" index 9f53040508c9794e2f46b8077c965b560b803b39..d6ba98770d087befbe2e07f65bab5c40d49a9515 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/grade.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202/grade.py" @@ -1,22 +1,22 @@ -classes = [ - {"name": 'n1', "age": 24, "grade": "A"}, - {"name": 'n2', "age": 23, "grade": "C"}, - {"name": 'n3', "age": 21, "grade": "D"}, - {"name": 'n4', "age": 26, "grade": "A"}, - {"name": 'n5', "age": 29, "grade": "B"}, - {"name": 'n6', "age": 20, "grade": "B"}, - {"name": 'n7', "age": 22, "grade": "C"} -] - - -def age(d): - d['age'] = d['age'] + 1 - return d - -#使用filter筛选出grade为A的同学 -L = filter(lambda x: True if x['grade'] == 'A' else False, classes) -print(list(L)) - -#使用map使age加1 -m = map(age, classes) +classes = [ + {"name": 'n1', "age": 24, "grade": "A"}, + {"name": 'n2', "age": 23, "grade": "C"}, + {"name": 'n3', "age": 21, "grade": "D"}, + {"name": 'n4', "age": 26, "grade": "A"}, + {"name": 'n5', "age": 29, "grade": "B"}, + {"name": 'n6', "age": 20, "grade": "B"}, + {"name": 'n7', "age": 22, "grade": "C"} +] + + +def age(d): + d['age'] = d['age'] + 1 + return d + +#使用filter筛选出grade为A的同学 +L = filter(lambda x: True if x['grade'] == 'A' else False, classes) +print(list(L)) + +#使用map使age加1 +m = map(age, classes) print(list(m)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" index c36b65b2b414e72c709efc38f3a39eeed2c4db8c..dc1824cf1e13277d2330d5f1e52b3d0a02287f2e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/main.py" @@ -1,59 +1,59 @@ -from threading import Thread -import random -import requests -import pymysql -import time -from settings import MYSQL_CONF, HEADERS -import sys -sys.path.append(r"E:\PycharmProjects\pythonProject\venv\jd_crawler\parser") -from search import parse_jd_item - -def clock_it_deco(func): - def wrapper(*args): - start_time = time.time() - result = func(*args) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time-start_time), '.2f'}s") - return result - return wrapper - -def save(item_array): - pass - -def server(item_array): - cursor = mysql_con.cursor() - SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) - VALUES (%s, %s, %s, %s, %s, %s)""" - cursor.executemany(SQL, item_array) - mysql_con.commit() - cursor.close() - -def downloader(task): - url = "https://search.jd.com/Search" - proxies = { - "http": "144.255.48.62:9999", - "https": "144.255.48.62:9999" - } - params = { - "keyword": task - } - res = requests.get(url=url, params=params, headers=HEADERS) - return res - -@clock_it_deco -def main(task_array): - for task in task_array: - result = downloader(task) - item_array = parse_jd_item(result.text) - server(item_array) - -if __name__ == "__main__": - thread_array = [] - mysql_con = pymysql.connect(**MYSQL_CONF) - task_array = ['鼠标', '键盘', '显卡', '耳机'] - for i in range(4): - t = Thread(target=main(task_array[i]), args=(i, )) - thread_array.append(t) - t.start() - for t in thread_array: +from threading import Thread +import random +import requests +import pymysql +import time +from settings import MYSQL_CONF, HEADERS +import sys +sys.path.append(r"E:\PycharmProjects\pythonProject\venv\jd_crawler\parser") +from search import parse_jd_item + +def clock_it_deco(func): + def wrapper(*args): + start_time = time.time() + result = func(*args) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time-start_time), '.2f'}s") + return result + return wrapper + +def save(item_array): + pass + +def server(item_array): + cursor = mysql_con.cursor() + SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) + VALUES (%s, %s, %s, %s, %s, %s)""" + cursor.executemany(SQL, item_array) + mysql_con.commit() + cursor.close() + +def downloader(task): + url = "https://search.jd.com/Search" + proxies = { + "http": "144.255.48.62:9999", + "https": "144.255.48.62:9999" + } + params = { + "keyword": task + } + res = requests.get(url=url, params=params, headers=HEADERS) + return res + +@clock_it_deco +def main(task_array): + for task in task_array: + result = downloader(task) + item_array = parse_jd_item(result.text) + server(item_array) + +if __name__ == "__main__": + thread_array = [] + mysql_con = pymysql.connect(**MYSQL_CONF) + task_array = ['鼠标', '键盘', '显卡', '耳机'] + for i in range(4): + t = Thread(target=main(task_array[i]), args=(i, )) + thread_array.append(t) + t.start() + for t in thread_array: t.join() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser/search.py" index 479b80228612cef422ab8d6138fba6efdbe3ce35..9f4f6ea6c4cebf5682c3736cf561927a324f4524 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/parser/search.py" @@ -1,29 +1,29 @@ -from bs4 import BeautifulSoup -import json - -def parse_jd_item(html): - result = [] - soup = BeautifulSoup(html, "lxml") - #print(soup) - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' - result.append((sku_id, img, price, title, shop, icons)) - return result - -if __name__ == "__main__": - with open("./test/search.html", "r", encoding="utf-8") as f: - html = f.read() - result = parse_jd_item(html) +from bs4 import BeautifulSoup +import json + +def parse_jd_item(html): + result = [] + soup = BeautifulSoup(html, "lxml") + #print(soup) + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' + result.append((sku_id, img, price, title, shop, icons)) + return result + +if __name__ == "__main__": + with open("./test/search.html", "r", encoding="utf-8") as f: + html = f.read() + result = parse_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/settings.py" index 3f8d4fce1a2663a2eb60026e6d539d54c6452671..32af3e63a0869dadd368bf9b980bd64817128638 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\271\235\345\221\250_\347\254\254\344\270\211\350\212\202/settings.py" @@ -1,11 +1,11 @@ -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "qwe123", - "db": "test" -} - -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", - "upgrade-insecure-requests": "1" +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "qwe123", + "db": "test" +} + +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", + "upgrade-insecure-requests": "1" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202" index 80a1a2fd9f12084cd501cf18356dc0081be320af..5cf41ae76ac21ff61e030e0ea6dc42601f2890a8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,34 +1,34 @@ -#!/usr/bin/python3 - -def add(a, b): - return a + b - -def less(a, b): - return a - b - -def mult(a, b): - return a * b - -def exce(a, b): - return a / b - -def divi(a, b): - return a // b - -def rema(a, b): - return a % b - -def power(a, b): - return a ** b - -def sqrt(a, b): - return a ** (1/b) - -print(add(10,2)) -print(less(10,2)) -print(mult(10,2)) -print(exce(10,2)) -print(divi(11,2)) -print(rema(11,2)) -print(power(10,2)) +#!/usr/bin/python3 + +def add(a, b): + return a + b + +def less(a, b): + return a - b + +def mult(a, b): + return a * b + +def exce(a, b): + return a / b + +def divi(a, b): + return a // b + +def rema(a, b): + return a % b + +def power(a, b): + return a ** b + +def sqrt(a, b): + return a ** (1/b) + +print(add(10,2)) +print(less(10,2)) +print(mult(10,2)) +print(exce(10,2)) +print(divi(11,2)) +print(rema(11,2)) +print(power(10,2)) print(sqrt(9,2)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202" index 0a1c78782c9bf5a8e114383b39095b1b602bd3be..b2e50b728e04ffe43c91176076e395fbfbb31de3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202" @@ -1,79 +1,79 @@ -#基础数据结构CRUD操作 -#List列表 -# create -L = [] #创建一个空列表 -L.append('a') #追加元素'a' - -L1 = ['a'] -L2 = ['b'] -L = L1 + L2 #L1和L2相加生成新列表L['a', 'b'] -L +='b' #L自增字符'b' -L = ['a'] * 5 #创建一个有5个a元素的列表 -L = ['a'] -L *= 5 #自增五个a元素 -L.insert(1, 'd') #在下标1的位置插入d元素 -# retireve -L = ['a', 'b', 'c'] -L[1] #获取下标1的元素b -L[::] #获取所有元素 -L[-1] #获取最后一个元素c -L[0:1] #获取a和b元素 -L[::2] #获取a和c元素 - -L.insert(L.index['a'], 'd') #在元素a的位置插入d元素 -# update -L = ['a', 'b', 'c'] -L[1] = 'd' #给下标1重新赋值为d -L[::] = 'd' #列表重新赋值为d -# delete -L = ['a', 'b', 'c'] -L.pop() #删除最后一个元素 -L.pop(1) #删除下标1的元素 -L.clear() #清除列表所有元素 - -# sort排序 -L = ['c', 'a', 'b'] -L.sort() #按照ascii排序,正序 -L.sorted() #正序排序,生成一个新列表 -L.reverse() #倒序排序 -L.reversed() #倒序排序,生成一个新列表 - -#元组 -T = ('a', 'c', 'c') -T[1] #返回下标1的元素 -T.index('c') #返回元素c的下标 -T[::] #返回元组的所有元素 -#字典 -# create -D = {'a':1, 'b':2, 'c':3} -D[d] = 4#赋值一个不存在的key,否则会覆盖原有key的value -D.update({'b':2}) -D.setdefault('b', 0) -# retrieve -D = {'a':1, 'b':2, 'c':3} -D['a'] #访问key为a的value -D.get('a') #key不存在会不报错 -D.keys() #返回所有的key -D.value() #返回所有的value -D.items() #返回所有的键值对 -# update -D = {'a':1, 'b':2, 'c':3} -D['a'] = 0 -D.update({'d':4}) -# delete -D = {'a':1, 'b':2, 'c':3} -D.pop('a') #删除key为a的键值对 -D.popitem() #随机删除一个键值对 -#set集合 -S = {'a', 'b', 'c'} -S.add('d') -# retrieve -'a' in S #判读'a'是否在S集合中,存在返回True否则False -# update -S.update({'d', 'e'}) #添加多个元素 -S.union(S1) #合并S1到S中 -# delete -S = {'a', 'b', 'c'} -S.remote('d') #不存在会报错 -S.discard('d') #不存在不会报错 +#基础数据结构CRUD操作 +#List列表 +# create +L = [] #创建一个空列表 +L.append('a') #追加元素'a' + +L1 = ['a'] +L2 = ['b'] +L = L1 + L2 #L1和L2相加生成新列表L['a', 'b'] +L +='b' #L自增字符'b' +L = ['a'] * 5 #创建一个有5个a元素的列表 +L = ['a'] +L *= 5 #自增五个a元素 +L.insert(1, 'd') #在下标1的位置插入d元素 +# retireve +L = ['a', 'b', 'c'] +L[1] #获取下标1的元素b +L[::] #获取所有元素 +L[-1] #获取最后一个元素c +L[0:1] #获取a和b元素 +L[::2] #获取a和c元素 + +L.insert(L.index['a'], 'd') #在元素a的位置插入d元素 +# update +L = ['a', 'b', 'c'] +L[1] = 'd' #给下标1重新赋值为d +L[::] = 'd' #列表重新赋值为d +# delete +L = ['a', 'b', 'c'] +L.pop() #删除最后一个元素 +L.pop(1) #删除下标1的元素 +L.clear() #清除列表所有元素 + +# sort排序 +L = ['c', 'a', 'b'] +L.sort() #按照ascii排序,正序 +L.sorted() #正序排序,生成一个新列表 +L.reverse() #倒序排序 +L.reversed() #倒序排序,生成一个新列表 + +#元组 +T = ('a', 'c', 'c') +T[1] #返回下标1的元素 +T.index('c') #返回元素c的下标 +T[::] #返回元组的所有元素 +#字典 +# create +D = {'a':1, 'b':2, 'c':3} +D[d] = 4#赋值一个不存在的key,否则会覆盖原有key的value +D.update({'b':2}) +D.setdefault('b', 0) +# retrieve +D = {'a':1, 'b':2, 'c':3} +D['a'] #访问key为a的value +D.get('a') #key不存在会不报错 +D.keys() #返回所有的key +D.value() #返回所有的value +D.items() #返回所有的键值对 +# update +D = {'a':1, 'b':2, 'c':3} +D['a'] = 0 +D.update({'d':4}) +# delete +D = {'a':1, 'b':2, 'c':3} +D.pop('a') #删除key为a的键值对 +D.popitem() #随机删除一个键值对 +#set集合 +S = {'a', 'b', 'c'} +S.add('d') +# retrieve +'a' in S #判读'a'是否在S集合中,存在返回True否则False +# update +S.update({'d', 'e'}) #添加多个元素 +S.union(S1) #合并S1到S中 +# delete +S = {'a', 'b', 'c'} +S.remote('d') #不存在会报错 +S.discard('d') #不存在不会报错 S.pop() #随机弹出 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202" index f68f108c87c0fecbc3d288fac3b2e65db3653e08..1b9e2602f8251ab866cf9d0ce003b56bd33490a9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202" @@ -1,34 +1,34 @@ -content = """ -#在计算机内存中统一使用unicode编码,当需要保存到硬盘或传输转化成对应的编码,python3版本字符串已unicode编码 -'测试'.encode("unicode_escape").decode() -'\\u6d4b\\u8bd5' -#对字符串进行utf-8编码 -'测试'.encode("utf-8") -'\u6d4b\u8bd5'.encode("utf-8") -b'\xe6\xb5\x8b\xe8\xaf\x95' -#对字节进行解码 -b'\xe6\xb5\x8b\xe8\xaf\x95'.decode("utf-8") -'测试' -#Create练习 -str1 = 'abc' -str1 = str1 + 'def' -str1 += 'def' -#retrieve练习 -str1 = 'abcdef' -str1[1] #下标查找 -str1.find('a') #find函数查找 -str1.index('a') #index函数查找 -str1.startswith('abc') #startswitch函数查找 -str1.endswith('ef') #endswitch函数查找 -#update练习 -'abc'.replace('a', 'b') -'a,bc'.split(',') -'-'.join(['a', 'b']) -delete练习 -' abc '.strip() -' abc'.lstrip() -'abc '.rstrip() -""" -output = open("output.txt", "w", encoding="utf-8") -output.write(content) +content = """ +#在计算机内存中统一使用unicode编码,当需要保存到硬盘或传输转化成对应的编码,python3版本字符串已unicode编码 +'测试'.encode("unicode_escape").decode() +'\\u6d4b\\u8bd5' +#对字符串进行utf-8编码 +'测试'.encode("utf-8") +'\u6d4b\u8bd5'.encode("utf-8") +b'\xe6\xb5\x8b\xe8\xaf\x95' +#对字节进行解码 +b'\xe6\xb5\x8b\xe8\xaf\x95'.decode("utf-8") +'测试' +#Create练习 +str1 = 'abc' +str1 = str1 + 'def' +str1 += 'def' +#retrieve练习 +str1 = 'abcdef' +str1[1] #下标查找 +str1.find('a') #find函数查找 +str1.index('a') #index函数查找 +str1.startswith('abc') #startswitch函数查找 +str1.endswith('ef') #endswitch函数查找 +#update练习 +'abc'.replace('a', 'b') +'a,bc'.split(',') +'-'.join(['a', 'b']) +delete练习 +' abc '.strip() +' abc'.lstrip() +'abc '.rstrip() +""" +output = open("output.txt", "w", encoding="utf-8") +output.write(content) output.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202" index a1113e755d2827bae7980646face41ab32f64940..cbf75cb433725d4967ff355a5129638c629620a6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,23 +1,23 @@ -import time,os -from threading import Thread -from multiprocessing import Process - -def run(n): - print('task',n) - time.sleep(1) - print('2s') - time.sleep(1) - print('1s') - time.sleep(1) - print('0s') - time.sleep(1) - -if __name__ == '__main__': - #t1 = Thread(target=run, args=('t1',)) #target是要执行的函数名(不是函数),args是函数对应的参数,以元组的形式存在 - #t2 = Thread(target=run, args=('t2',)) - #t1.start() - #t2.start() - p1 = Process(target=run, args=('t1',)) - p2 = Process(target=run, args=('t2',)) - p1.start() +import time,os +from threading import Thread +from multiprocessing import Process + +def run(n): + print('task',n) + time.sleep(1) + print('2s') + time.sleep(1) + print('1s') + time.sleep(1) + print('0s') + time.sleep(1) + +if __name__ == '__main__': + #t1 = Thread(target=run, args=('t1',)) #target是要执行的函数名(不是函数),args是函数对应的参数,以元组的形式存在 + #t2 = Thread(target=run, args=('t2',)) + #t1.start() + #t2.start() + p1 = Process(target=run, args=('t1',)) + p2 = Process(target=run, args=('t2',)) + p1.start() p2.start() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/avg.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/avg.py" index cefd1c5efacc15dcc54546ef028b131bbf366843..507a293f046aa031ae95e3b8fe9d9ef55c152056 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/avg.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/avg.py" @@ -1,30 +1,30 @@ -def calc_avg(): - total = 0 - length = 0 - while True: - try: - avg = yield total / length - except ZeroDivisionError: - avg = yield 0 - total += avg - length += 1 -""" -my_avg = calc_avg() -next(my_avg) -print(my_avg.send(4)) -print(my_avg.send(5)) -print(my_avg.send(6)) -""" -def total(my_avg, value): - avg = my_avg.send(value) - print(f"avg value: {avg}") - -if __name__ == "__main__": - my_avg = calc_avg() - my_avg.send(None) - while True: - read = input("input: ") - read = int(read) - if read == 0: - break +def calc_avg(): + total = 0 + length = 0 + while True: + try: + avg = yield total / length + except ZeroDivisionError: + avg = yield 0 + total += avg + length += 1 +""" +my_avg = calc_avg() +next(my_avg) +print(my_avg.send(4)) +print(my_avg.send(5)) +print(my_avg.send(6)) +""" +def total(my_avg, value): + avg = my_avg.send(value) + print(f"avg value: {avg}") + +if __name__ == "__main__": + my_avg = calc_avg() + my_avg.send(None) + while True: + read = input("input: ") + read = int(read) + if read == 0: + break total(my_avg, read) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/coro.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/coro.py" index 137f18eebb023d15683f053fb947e27730381c92..fb1288da841b87f610e41ad0e02a873c589cb3d9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/coro.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/coro.py" @@ -1,14 +1,14 @@ -import asyncio - -async def hello(): - print("Hello world!") - # 异步调用asyncio.sleep(1): - r = await asyncio.sleep(1) - print("Hello again!") - -# 获取EventLoop: -loop = asyncio.get_event_loop() -# 执行coroutine -tasks = [hello(), hello()] -loop.run_until_complete(asyncio.wait(tasks)) +import asyncio + +async def hello(): + print("Hello world!") + # 异步调用asyncio.sleep(1): + r = await asyncio.sleep(1) + print("Hello again!") + +# 获取EventLoop: +loop = asyncio.get_event_loop() +# 执行coroutine +tasks = [hello(), hello()] +loop.run_until_complete(asyncio.wait(tasks)) loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/lock.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/lock.py" index 80084b0fc15bfee5cfe5ebb3e3f427a656781d13..e640d578332bb690ce158ec3132efe60fa188c23 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/lock.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/lock.py" @@ -1,35 +1,35 @@ -from multiprocessing import Process, Lock -from threading import Thread, Lock - -#进程锁 -pro_lock = Lock() -def pro_foo(index): - with pro_lock: - with open("test.txt", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") -#线程锁 -thr_lock = Lock() -index = 0 -def thr_foo(): - global index - for i in range(10**5): - with thr_lock: - index += 1 - index -= 1 - -if __name__ == "__main__": - pro_array = [] - thr_array = [] - for i in range(10): - #p = Process(target=pro_foo, args=(i, )) - t = Thread(target=thr_foo) - #pro_array.append(p) - thr_array.append(t) - #p.start() - t.start() - #for p in pro_array: - #p.join() - for t in thr_array: - t.join() - print(index) +from multiprocessing import Process, Lock +from threading import Thread, Lock + +#进程锁 +pro_lock = Lock() +def pro_foo(index): + with pro_lock: + with open("test.txt", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") +#线程锁 +thr_lock = Lock() +index = 0 +def thr_foo(): + global index + for i in range(10**5): + with thr_lock: + index += 1 + index -= 1 + +if __name__ == "__main__": + pro_array = [] + thr_array = [] + for i in range(10): + #p = Process(target=pro_foo, args=(i, )) + t = Thread(target=thr_foo) + #pro_array.append(p) + thr_array.append(t) + #p.start() + t.start() + #for p in pro_array: + #p.join() + for t in thr_array: + t.join() + print(index) print("done!!!") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/queue.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/queue.py" index 666b565323592a08b365cb077cec562ec5f6749b..44928b893e25518c892803ffa4ddd95d97a04ef0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/queue.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/queue.py" @@ -1,13 +1,13 @@ -from multiprocessing import Process, Lock -from multiprocessing import Queue, Array, Value - -def test_queue(index, my_queue): - my_queue.put(index) - -if __name__ == "__main__": - my_queue = Queue() - for i in range(10): - p = Process(target=test_queue, args=(i, my_queue)) - p.start() - while True: +from multiprocessing import Process, Lock +from multiprocessing import Queue, Array, Value + +def test_queue(index, my_queue): + my_queue.put(index) + +if __name__ == "__main__": + my_queue = Queue() + for i in range(10): + p = Process(target=test_queue, args=(i, my_queue)) + p.start() + while True: print(my_queue.get()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\200\350\212\202" index 468d0341a2f0ccdcfd98f213cccc7b7af2194751..f7474573f7c7c4e9b91ed0da348fd62cb407d5b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\253\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,6 +1,6 @@ -非空约束:如性别 -唯一约束:唯一标识符如产品序列号 -default约束:时间戳 - -分组查询 +非空约束:如性别 +唯一约束:唯一标识符如产品序列号 +default约束:时间戳 + +分组查询 select class, count(*) as 人数, avg(score) as 平均分 from std_score group by class; \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202" index 4fd8befc068ec2e2e43054fa980c0e134c489c29..2014a10f5bffa3dbc98358062f3ae81a23f38264 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,7 +1,7 @@ -物理层 >> 电器标准规范,如使用规定的线缆使其计算器互通,使用什么频率电磁波发送无线信号 -数据链路层 >> 二层数据包的标准,使其能够将数据包传输给正确的对端;相当于在配送包裹的一个个配送站 -网络层 >> 具有逻辑IP地址,相当于包裹中的邮寄地址。不用关系包裹经过了那些城市只关心最终目的地 -传输层 >> 具有逻辑端口,包裹已在小哥手里需要精准配送到你的手中,而你相当于端口。TCP为面对面交到你手里确认签收,UDP为将快递放到蜂巢如果忙不开忘记了就容易丢失 -会话层 >> 维持传输层的会话,什么时候断开连接什么时候一直保持连接 -表示层 >> 对数据进行处理,如加密/压缩。如你买的东西有特殊需求会被商家按照你的要求打包 +物理层 >> 电器标准规范,如使用规定的线缆使其计算器互通,使用什么频率电磁波发送无线信号 +数据链路层 >> 二层数据包的标准,使其能够将数据包传输给正确的对端;相当于在配送包裹的一个个配送站 +网络层 >> 具有逻辑IP地址,相当于包裹中的邮寄地址。不用关系包裹经过了那些城市只关心最终目的地 +传输层 >> 具有逻辑端口,包裹已在小哥手里需要精准配送到你的手中,而你相当于端口。TCP为面对面交到你手里确认签收,UDP为将快递放到蜂巢如果忙不开忘记了就容易丢失 +会话层 >> 维持传输层的会话,什么时候断开连接什么时候一直保持连接 +表示层 >> 对数据进行处理,如加密/压缩。如你买的东西有特殊需求会被商家按照你的要求打包 应用层 >> 相当于你可以使用你买到的产品了,并可以作出反馈去评价产品 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202" index 32d5d0fa7c4c6e964bc859d2d9062a0e4d3fdc9a..f3ad8aa270d40706960ea42edffbe633fd63708b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\205\255\345\221\250_\347\254\254\344\272\214\350\212\202" @@ -1,25 +1,25 @@ -TCP三次握手 -假设 A主动 ----> 访问B -1、A发送syn报文到B端,A进入send_syn状态机,B查看报文决定是否提供服务 -2、B可以提供服务发送syn+ack报文给A,B进入receive_syn状态机 -3、A接收到syn+ack,发送带有数据的报文同时ack在初始化seq+1 -4、至此握手建立成功,establish状态 - -TCP四次分手 -假设 A不在需要 ----> B提供服务 -1、A主动发送FIN报文到B,A进入fin_wait_1状态机 -2、B接收到FIN报文,B回复ACK报文进入close_wait状态机 -3、A接收到B的ACK报文进入fin_wait_2状态机 -4、B发送FIN报文给A,B进入last_ack状态机 -5、A接收到B的FIN报文并发送ACK报文给B,进入time_wait状态机 -6、B接收到ACK报文进入closed -7、A默认等待2MSL进入closed - -HTTPS加密过程 -假设A ----> 访问https的网站B -1、A发送client hello报文给B,包括支持版本、加密套件等信息 -2、B接收到A的报文,根据信息返回一个协商好的版本信息server hello,并发送带有服务器的证书报文 -3、A拿到server hello和证书后,校验是否受信。如果不信任断开连接,否则进入下一步 -4、A发送change cipe spack报文是经过证书公钥加密的数据包 -5、B也会发送change cipe spack报文,用于预验证是否可以正常解密 +TCP三次握手 +假设 A主动 ----> 访问B +1、A发送syn报文到B端,A进入send_syn状态机,B查看报文决定是否提供服务 +2、B可以提供服务发送syn+ack报文给A,B进入receive_syn状态机 +3、A接收到syn+ack,发送带有数据的报文同时ack在初始化seq+1 +4、至此握手建立成功,establish状态 + +TCP四次分手 +假设 A不在需要 ----> B提供服务 +1、A主动发送FIN报文到B,A进入fin_wait_1状态机 +2、B接收到FIN报文,B回复ACK报文进入close_wait状态机 +3、A接收到B的ACK报文进入fin_wait_2状态机 +4、B发送FIN报文给A,B进入last_ack状态机 +5、A接收到B的FIN报文并发送ACK报文给B,进入time_wait状态机 +6、B接收到ACK报文进入closed +7、A默认等待2MSL进入closed + +HTTPS加密过程 +假设A ----> 访问https的网站B +1、A发送client hello报文给B,包括支持版本、加密套件等信息 +2、B接收到A的报文,根据信息返回一个协商好的版本信息server hello,并发送带有服务器的证书报文 +3、A拿到server hello和证书后,校验是否受信。如果不信任断开连接,否则进入下一步 +4、A发送change cipe spack报文是经过证书公钥加密的数据包 +5、B也会发送change cipe spack报文,用于预验证是否可以正常解密 6、如果可以正常解密,发送shakehands报文,后续根据协商的密钥进行加密传输 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202" index 3b755f294ee74c6aefde7a94b50bd3dd32fd1319..740dde92aa1f708e7a51fe40f5b1bfda31d2daa3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202" @@ -1,26 +1,26 @@ -from datetime import datetime -from datetime import timedelta -#作业1 -datetime.now(tz=None) #获取本地时间,datetime对象 -datetime.now(tz=None).strftime('%Y-%m-%d') #转化为字符串 - -#字符串转化为datetime对象 -s = datetime.now(tz=None).strftime('%Y-%m-%d') -datetime.strptime(s, '%Y-%m-%d') - -datetime.now(tz=None).timestamp() #转化为时间戳 - -#时间戳转化为datetime对象 -t = datetime.now(tz=None).timestamp() -datetime.fromtimestamp(t, tz=None) - -#作业2,封装一个get_date函数 -def get_date(day_delta): - if day_delta == -1: - now = datetime.now(tz=None) - return now + timedelta(days=day_delta) - return datetime.now(tz=None) - -if __name__ == '__main__': - date = get_date(-1) +from datetime import datetime +from datetime import timedelta +#作业1 +datetime.now(tz=None) #获取本地时间,datetime对象 +datetime.now(tz=None).strftime('%Y-%m-%d') #转化为字符串 + +#字符串转化为datetime对象 +s = datetime.now(tz=None).strftime('%Y-%m-%d') +datetime.strptime(s, '%Y-%m-%d') + +datetime.now(tz=None).timestamp() #转化为时间戳 + +#时间戳转化为datetime对象 +t = datetime.now(tz=None).timestamp() +datetime.fromtimestamp(t, tz=None) + +#作业2,封装一个get_date函数 +def get_date(day_delta): + if day_delta == -1: + now = datetime.now(tz=None) + return now + timedelta(days=day_delta) + return datetime.now(tz=None) + +if __name__ == '__main__': + date = get_date(-1) print(date.strftime('%Y-%m-%d %H:%M:%S')) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/re_math_staticmethod.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/re_math_staticmethod.py" index 90247246176d33ba85ec4c81acd84425ef2af839..77a2a43ff5e352e84321bb7f678ca4d31c32f14d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/re_math_staticmethod.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/re_math_staticmethod.py" @@ -1,24 +1,24 @@ -#封装一个MyMath类,实现加/减/乘/除 -class MyMath(object): - @staticmethod - def add(a, b): - return a + b - - @staticmethod - def less(a, b): - return a - b - - @staticmethod - def mult(a, b): - return a * b - - @staticmethod - def exce(a, b): - return a / b - -if __name__ == '__main__': - a, b = input("please input a,b: ").split(',') - print(f"a + b: {MyMath.add(int(a), int(b))}") - print(f"a - b: {MyMath.less(int(a), int(b))}") - print(f"a * b: {MyMath.mult(int(a), int(b))}") +#封装一个MyMath类,实现加/减/乘/除 +class MyMath(object): + @staticmethod + def add(a, b): + return a + b + + @staticmethod + def less(a, b): + return a - b + + @staticmethod + def mult(a, b): + return a * b + + @staticmethod + def exce(a, b): + return a / b + +if __name__ == '__main__': + a, b = input("please input a,b: ").split(',') + print(f"a + b: {MyMath.add(int(a), int(b))}") + print(f"a - b: {MyMath.less(int(a), int(b))}") + print(f"a * b: {MyMath.mult(int(a), int(b))}") print(f"a / b: {MyMath.exce(int(a), int(b))}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/\347\261\273\345\261\236\346\200\247\347\273\203\344\271\240" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/\347\261\273\345\261\236\346\200\247\347\273\203\344\271\240" index c63add9d7c996f8b33fe88f87482f6350c2673b3..1f49bfdf3c1a9f245e35757dedaf19c403b3d87d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/\347\261\273\345\261\236\346\200\247\347\273\203\344\271\240" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202/\347\261\273\345\261\236\346\200\247\347\273\203\344\271\240" @@ -1,17 +1,17 @@ -#创建类,实例化 -class Student(object): - area = 'CN' - __gender = ["male", "female"] - def __init__(self, name, score): - self.name = name - self.__score = score - - def get_score(self): - return self.__score - - def __str__(self): - return f"My score {self.get_score()}" - -ZhangSan = Student('ZS', '80') -LiSi = Student('LS', '57') +#创建类,实例化 +class Student(object): + area = 'CN' + __gender = ["male", "female"] + def __init__(self, name, score): + self.name = name + self.__score = score + + def get_score(self): + return self.__score + + def __str__(self): + return f"My score {self.get_score()}" + +ZhangSan = Student('ZS', '80') +LiSi = Student('LS', '57') print(ZhangSan) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" index fa5f3b5a278569a78a1eb3a844f8bb0aa1ed1087..b74a937c3567b573a51be9b3866742a11981703a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/MyMath.py" @@ -1,21 +1,21 @@ -#封装一个MyMath类,实现加/减/乘/除 -class MyMath(object): - def __init__(self, a, b): - self.a = a - self.b = b - def add(self): - return self.a + self.b - def less(self): - return self.a - self.b - def mult(self): - return self.a * self.b - def exce(self): - return self.a / self.b - -if __name__ == '__main__': - a, b = input("please input a,b: ").split(',') - calc = MyMath(int(a), int(b)) - print(f"a + b: {calc.add()}") - print(f"a - b: {calc.less()}") - print(f"a * b: {calc.mult()}") +#封装一个MyMath类,实现加/减/乘/除 +class MyMath(object): + def __init__(self, a, b): + self.a = a + self.b = b + def add(self): + return self.a + self.b + def less(self): + return self.a - self.b + def mult(self): + return self.a * self.b + def exce(self): + return self.a / self.b + +if __name__ == '__main__': + a, b = input("please input a,b: ").split(',') + calc = MyMath(int(a), int(b)) + print(f"a + b: {calc.add()}") + print(f"a - b: {calc.less()}") + print(f"a * b: {calc.mult()}") print(f"a / b: {calc.exce()}") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/class" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/class" index daa6fbe96a60aa943468588bec01c99682ce9fae..59960dbc2492e7d1e3499ea4e14f03fd940313c8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/class" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\256\211\351\200\270/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202/class" @@ -1,21 +1,21 @@ -#创建类,实例化 -class Student(object): - def __init__(self, name, score): - self.name = name - self,score = score - -ZhangSan = Student('ZS', '80') -LiSi = Student('LS', '57') - -#继承和多态 -class Animal(object): - def attributes(self): - print("Animal are cute!!!") - -class Dog(Animal): - def attributes(self): - print("Dog are cute") - -class Cat(Animal): - def attributes(self): +#创建类,实例化 +class Student(object): + def __init__(self, name, score): + self.name = name + self,score = score + +ZhangSan = Student('ZS', '80') +LiSi = Student('LS', '57') + +#继承和多态 +class Animal(object): + def attributes(self): + print("Animal are cute!!!") + +class Dog(Animal): + def attributes(self): + print("Dog are cute") + +class Cat(Animal): + def attributes(self): print("Cat are cute") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 2-2 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 2-2 homework.py" index 2a325a73e044e2c6a5012709dda8d6675c15f69a..366729d6784cc1414a51892b4b01bf422e03a53f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 2-2 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 2-2 homework.py" @@ -1,68 +1,68 @@ -# 字符串的编码和解码 -a = "德里克".encode('utf-8') -print(a) -b = a.decode('utf-8') -print(b) - -# 字符串的CRUD -# Creat -a = "Derek" -b = a + ' hello!' -print(b) -# Retrieve---检索 -a = ['Derek', [1, 2], (2, 3, 4)] -d = a[0] -b = a[1] -c = a[2] -print("{}, {}, {}".format(b, c, d)) -a = "Derek, Hello" -b = a.find('!') -c = a.find('e') -print("{},{}".format(b,c)) -b = a.index('e') -print(b) -# update -a = "Dorok,hello" -b = a.replace('o', 'e') -print(b) - -a = "Derek, Mary, Ivan" -b = a.split(',') -print(b) -c = '#'.join(b) -print(c) - -# Delete -a = " hello, Derek " -b = a.strip() -print(b) -b = a.lstrip() -print(b) -b = a.rstrip() -print(b) - -# 字符串输入输出 -# 保存文件 -file_1 = open('Derek.txt', 'w', encoding="utf-8") -content = 'Derek, hello' -file_1.write(content) -file_1.close() -# 读取文件 -file_2 = open('Derek.txt', 'r', encoding='utf-8') -content = file_2.read() -print(content) -file_2.close() -# 追加文件 -file_3 = open('Derek.txt', 'a', encoding="utf-8") -content = "\nyou are so handsome that I love you" -file_3.write(content) -file_3.close() - -# 字符串输入输出 -a = "so" -b = "handsome" -print(f"Derek, you are : {a}, {b}") - -# 小数格式化 -b = "{:.2f}".format(3.1415926) -print(b) +# 字符串的编码和解码 +a = "德里克".encode('utf-8') +print(a) +b = a.decode('utf-8') +print(b) + +# 字符串的CRUD +# Creat +a = "Derek" +b = a + ' hello!' +print(b) +# Retrieve---检索 +a = ['Derek', [1, 2], (2, 3, 4)] +d = a[0] +b = a[1] +c = a[2] +print("{}, {}, {}".format(b, c, d)) +a = "Derek, Hello" +b = a.find('!') +c = a.find('e') +print("{},{}".format(b,c)) +b = a.index('e') +print(b) +# update +a = "Dorok,hello" +b = a.replace('o', 'e') +print(b) + +a = "Derek, Mary, Ivan" +b = a.split(',') +print(b) +c = '#'.join(b) +print(c) + +# Delete +a = " hello, Derek " +b = a.strip() +print(b) +b = a.lstrip() +print(b) +b = a.rstrip() +print(b) + +# 字符串输入输出 +# 保存文件 +file_1 = open('Derek.txt', 'w', encoding="utf-8") +content = 'Derek, hello' +file_1.write(content) +file_1.close() +# 读取文件 +file_2 = open('Derek.txt', 'r', encoding='utf-8') +content = file_2.read() +print(content) +file_2.close() +# 追加文件 +file_3 = open('Derek.txt', 'a', encoding="utf-8") +content = "\nyou are so handsome that I love you" +file_3.write(content) +file_3.close() + +# 字符串输入输出 +a = "so" +b = "handsome" +print(f"Derek, you are : {a}, {b}") + +# 小数格式化 +b = "{:.2f}".format(3.1415926) +print(b) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 3-1 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 3-1 homework.py" index 8affae68e03b651ab6eda412eed067b2c2962e2f..1f08d2a386d6a9b42bce2f3e5d8a702ac10ea551 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 3-1 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson 3-1 homework.py" @@ -1,42 +1,42 @@ -# 计数功能 -''' -#while循环实现 -count = 0 -while count < 100: - print(f"process: {count}") - count += 1 - -for循环实现 -for count in range(100): - print(f"The process:{count}") - -''' -''' -fibs = [0, 1] -for i in range(10): #一共循环10次,这里的i只是起到了代表循环次数的作用 - fibs.append(fibs[-2] + fibs[-1]) -print(fibs) -''' - -'''----这个到了144,不太行 -fibs = [0, 1] -while True: - if fibs[-1] < 100: - fibs.append(fibs[-2] + fibs[-1]) - else: - break -print(fibs) -''' - -#while循环来实现 -''' -i = 0 -a = 0 -j = 1 -while i < 100: - print(i, end=' ') - a = i - i = j - j = a + i -# 或者直接这样:i, j =j, i+j # i,j是并列赋值,类似于C语言里面的交换变量的方法,这是python独特的优势所在 -''' +# 计数功能 +''' +#while循环实现 +count = 0 +while count < 100: + print(f"process: {count}") + count += 1 + +for循环实现 +for count in range(100): + print(f"The process:{count}") + +''' +''' +fibs = [0, 1] +for i in range(10): #一共循环10次,这里的i只是起到了代表循环次数的作用 + fibs.append(fibs[-2] + fibs[-1]) +print(fibs) +''' + +'''----这个到了144,不太行 +fibs = [0, 1] +while True: + if fibs[-1] < 100: + fibs.append(fibs[-2] + fibs[-1]) + else: + break +print(fibs) +''' + +#while循环来实现 +''' +i = 0 +a = 0 +j = 1 +while i < 100: + print(i, end=' ') + a = i + i = j + j = a + i +# 或者直接这样:i, j =j, i+j # i,j是并列赋值,类似于C语言里面的交换变量的方法,这是python独特的优势所在 +''' diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-2 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-2 homework.py" index 8e578cf1257a62632bd9436b3ae7af261409df64..c5266e35924f94ffaa02a123744e96254c3f3687 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-2 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-2 homework.py" @@ -1,54 +1,54 @@ - -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -classes.sort(key = lambda x: x["grade"]) -print(classes) - -# 注意:list.sort()完成后会自动更新列表的顺序,所以,不需要在l = list.sort()了,这是一个错误做法 -f = filter(lambda x: True if x["grade"] == 'A' else False, classes) -print(list(f)) - - -# 这个地方传入的是列表中的元素。注意,这个地方自己出现过问题 -def ages(ele): - ele["age"] += 1 - return ele - -m = map(ages, classes) -print(list(m)) -# 这里的map()映射的是,从列表classes中的元素来调用函数ages,从而得到年龄加一的功能 -# 举个简单例子: -''' -def power(a): - return a **2 -l = [1, 2, 3, 4] -m = map(power, l) - -最终结果是 l = [1,4,9,16] -小结:所以我们写函数,如果对象是列表,往往参数都是列表中的元素,不要因为列表中的元素不是数字,就不会写了 -''' - - -# 使用递归函数重构斐波那契函数 - -def fibs(n): - if n == 1: - return 0 - elif n == 2: - return 1 - return (fibs(n - 1) + fibs(n - 2)) - - -num = int(input("请输入你要输入的项数:")) -l = [] -for i in range(1, num + 1): -c = fibs(i) -l.append(c) -print("斐波那契数列是:", l) + +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +classes.sort(key = lambda x: x["grade"]) +print(classes) + +# 注意:list.sort()完成后会自动更新列表的顺序,所以,不需要在l = list.sort()了,这是一个错误做法 +f = filter(lambda x: True if x["grade"] == 'A' else False, classes) +print(list(f)) + + +# 这个地方传入的是列表中的元素。注意,这个地方自己出现过问题 +def ages(ele): + ele["age"] += 1 + return ele + +m = map(ages, classes) +print(list(m)) +# 这里的map()映射的是,从列表classes中的元素来调用函数ages,从而得到年龄加一的功能 +# 举个简单例子: +''' +def power(a): + return a **2 +l = [1, 2, 3, 4] +m = map(power, l) + +最终结果是 l = [1,4,9,16] +小结:所以我们写函数,如果对象是列表,往往参数都是列表中的元素,不要因为列表中的元素不是数字,就不会写了 +''' + + +# 使用递归函数重构斐波那契函数 + +def fibs(n): + if n == 1: + return 0 + elif n == 2: + return 1 + return (fibs(n - 1) + fibs(n - 2)) + + +num = int(input("请输入你要输入的项数:")) +l = [] +for i in range(1, num + 1): +c = fibs(i) +l.append(c) +print("斐波那契数列是:", l) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-3 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-3 homework.py" index 25319eefcb510dcce86b2d716ae363982840424b..608969b6b4bac8812c4dcd658f0367d4b40214ac 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-3 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson3-3 homework.py" @@ -1,69 +1,69 @@ -#问题一,练习作用域之间的转换 -total = 0 -def sum(a, b): - total = a + b - print("函数内是局部变量:", total) - return total -print(sum(5, 10)) -print("函数外是全局变量:", total) - -total1 = 1 -def func(): - global total1 - print(total1) - total1 = 2 - print(total1) -print(func()) -print(total1) - -def a(): - total = 1 - def b(): - nonlocal total - total = 3 - print(total) - return b - b() - print(total) -a() - -#问题二,实现一个装饰器,用来输出函数的执行时间 -import time -def clock_deco(func): - def wrap(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") - return result - return wrap - -@clock_deco -def cool(a, b): - num = 0 - while True: - if num >= a ** b: - break - num += 1 - -cool(5, 10) - -#问题三,使用装饰器来为斐波那契函数增加缓存 -a = {} -def cache_deco(func): - global a - def wrap(n): - if n not in a: - a[n] = func(n) - return a[n] - return wrap - -@ cache_deco -def fib(n): - if n < 2: - return n - else: - return fib(n - 2) + fib(n - 1) - -print(fib(10)) +#问题一,练习作用域之间的转换 +total = 0 +def sum(a, b): + total = a + b + print("函数内是局部变量:", total) + return total +print(sum(5, 10)) +print("函数外是全局变量:", total) + +total1 = 1 +def func(): + global total1 + print(total1) + total1 = 2 + print(total1) +print(func()) +print(total1) + +def a(): + total = 1 + def b(): + nonlocal total + total = 3 + print(total) + return b + b() + print(total) +a() + +#问题二,实现一个装饰器,用来输出函数的执行时间 +import time +def clock_deco(func): + def wrap(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") + return result + return wrap + +@clock_deco +def cool(a, b): + num = 0 + while True: + if num >= a ** b: + break + num += 1 + +cool(5, 10) + +#问题三,使用装饰器来为斐波那契函数增加缓存 +a = {} +def cache_deco(func): + global a + def wrap(n): + if n not in a: + a[n] = func(n) + return a[n] + return wrap + +@ cache_deco +def fib(n): + if n < 2: + return n + else: + return fib(n - 2) + fib(n - 1) + +print(fib(10)) print(a) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-1 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-1 homework.py" index 942f952e2a70641d7dfa96379b575b4a68a79a55..f7b2b99ae5bb9d29298eb7a861c9c879c371c4ff 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-1 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-1 homework.py" @@ -1,37 +1,37 @@ -# 时间戳 -import time -import datetime - -# datetime.datetime 转换成 str -t = datetime.datetime.today() -print(t) -print(t.strftime("%Y-%m-%d %H:%M:%S")) - -# str到datetime.datetime -# 第一个datetime是模块,第二个datetime是类,第三个strptime是第二个datetime里面的属性 -cday = datetime.datetime.strptime('2020-1-6 18:20:20', '%Y-%m-%d %H:%M:%S') -print(cday) - -t = datetime.datetime.now() # 获取的是datetime类型 -a = t.strftime("%Y-%m-%d %H:%M:%S") # 这一步是把datetime类型转换成str类型 -b = datetime.datetime.strptime(a, "%Y-%m-%d %H:%M:%S") #根据指定的格式把一个时间字符串解析为时间元组。 - - -# datetime.datetime 转换成 timestamp -t = datetime. datetime. now() -c = t. timestamp() -print(c) - - -# 封装一个函数get_date(day_delta), 获取当前时间,并计算经过多少天后,他的日期是几月几号 -def get_date(day_delta): - t = datetime.datetime.today() - delta = datetime.timedelta(days=day_delta) - result = t+delta - print("经过{}天后的日期是:{}".format(day_delta, result)) - -num = int(input("请输入你要查询多少天前(后)的天数:")) -get_date(num) - - - +# 时间戳 +import time +import datetime + +# datetime.datetime 转换成 str +t = datetime.datetime.today() +print(t) +print(t.strftime("%Y-%m-%d %H:%M:%S")) + +# str到datetime.datetime +# 第一个datetime是模块,第二个datetime是类,第三个strptime是第二个datetime里面的属性 +cday = datetime.datetime.strptime('2020-1-6 18:20:20', '%Y-%m-%d %H:%M:%S') +print(cday) + +t = datetime.datetime.now() # 获取的是datetime类型 +a = t.strftime("%Y-%m-%d %H:%M:%S") # 这一步是把datetime类型转换成str类型 +b = datetime.datetime.strptime(a, "%Y-%m-%d %H:%M:%S") #根据指定的格式把一个时间字符串解析为时间元组。 + + +# datetime.datetime 转换成 timestamp +t = datetime. datetime. now() +c = t. timestamp() +print(c) + + +# 封装一个函数get_date(day_delta), 获取当前时间,并计算经过多少天后,他的日期是几月几号 +def get_date(day_delta): + t = datetime.datetime.today() + delta = datetime.timedelta(days=day_delta) + result = t+delta + print("经过{}天后的日期是:{}".format(day_delta, result)) + +num = int(input("请输入你要查询多少天前(后)的天数:")) +get_date(num) + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-2 homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-2 homework.py" index b6ace9e31d6ccbdace0f9ebc9c1fba3a179fa99a..e045e14032764b6e3526a23d1e295a0506a7121d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-2 homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/lesson4-2 homework.py" @@ -1,46 +1,46 @@ -# 用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 -class MyMath(object): - def add_(self, a, b): - return a+b - def less(self, a, b): - return a - b - def pow_(self, a, b): - return a ** b - def exce(self, a, b): - return a / b -if __name__ == '__main__': - a = int(input("请输入第一个整数:")) - b = int(input("请输入第二个整数:")) - p = MyMath() - print(p.add_(a, b)) - print(p.less(a, b)) - print(p.pow_(a, b)) - print(p.exce(a, b)) - - -# 抽象出一个类 -class Animal(object): - def __init__(self, value): - self.name = value - self.age = 10 - -cat = Animal('Ivan') -dog = Animal("Mary") - -print(cat.age, cat.name, dog.age, dog.name) - - -# 创建多个继承作业2父类的子类 -class Dog(Animal): - print("the dog is running") - -class Cat(Animal): - print("the cat is watching you") - -d = Dog("狗") -print(d.name) -print(d.age) - -c = Cat("猫") -print(c.name) +# 用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 +class MyMath(object): + def add_(self, a, b): + return a+b + def less(self, a, b): + return a - b + def pow_(self, a, b): + return a ** b + def exce(self, a, b): + return a / b +if __name__ == '__main__': + a = int(input("请输入第一个整数:")) + b = int(input("请输入第二个整数:")) + p = MyMath() + print(p.add_(a, b)) + print(p.less(a, b)) + print(p.pow_(a, b)) + print(p.exce(a, b)) + + +# 抽象出一个类 +class Animal(object): + def __init__(self, value): + self.name = value + self.age = 10 + +cat = Animal('Ivan') +dog = Animal("Mary") + +print(cat.age, cat.name, dog.age, dog.name) + + +# 创建多个继承作业2父类的子类 +class Dog(Animal): + print("the dog is running") + +class Cat(Animal): + print("the cat is watching you") + +d = Dog("狗") +print(d.name) +print(d.age) + +c = Cat("猫") +print(c.name) print(c.age) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/main.py" index ed56a6acf7bc3ffb7c9c2b61d7bdc8b2275f7375..752cd3e6d690620764fe7075826b2c561dd93c66 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/main.py" @@ -1,23 +1,23 @@ -## 四大基本数据结构中哪些是可变的, 哪些是不可变的。有序或者无序? -# list()--列表 可变-可更改 有序 -# tuple()--元组 不可变-不可更改 有序 -# dict()--字典 可变的-可更改 无序 -# set()--集合 可变-可更改 无序 - - -def datatest(): - int_t = 1 - float_t = 0.1 - string_t = 'Derek' - bool_t = True - byte_t = bytes('23', encoding='utf-8') - none_t = None - - list_t = [int_t, float_t, string_t, bool_t, byte_t, none_t] - tuple_t = (int_t, float_t, string_t, bool_t, byte_t, none_t) - dict_t = {int_t, float_t, string_t, bool_t, byte_t, none_t} - set_t = (int_t, float_t, string_t, bool_t, byte_t, none_t) - - print(list_t, tuple_t, dict_t, set_t) - -print(datatest()) +## 四大基本数据结构中哪些是可变的, 哪些是不可变的。有序或者无序? +# list()--列表 可变-可更改 有序 +# tuple()--元组 不可变-不可更改 有序 +# dict()--字典 可变的-可更改 无序 +# set()--集合 可变-可更改 无序 + + +def datatest(): + int_t = 1 + float_t = 0.1 + string_t = 'Derek' + bool_t = True + byte_t = bytes('23', encoding='utf-8') + none_t = None + + list_t = [int_t, float_t, string_t, bool_t, byte_t, none_t] + tuple_t = (int_t, float_t, string_t, bool_t, byte_t, none_t) + dict_t = {int_t, float_t, string_t, bool_t, byte_t, none_t} + set_t = (int_t, float_t, string_t, bool_t, byte_t, none_t) + + print(list_t, tuple_t, dict_t, set_t) + +print(datatest()) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\357\274\210\350\256\241\347\256\227\345\231\250\357\274\211.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\357\274\210\350\256\241\347\256\227\345\231\250\357\274\211.py" index f80188886a2dc8e4ab26e2d3e75049070798f934..41331c6b50ffaa47f954be54b5cd97c29cb97523 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\357\274\210\350\256\241\347\256\227\345\231\250\357\274\211.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\357\274\210\350\256\241\347\256\227\345\231\250\357\274\211.py" @@ -1,31 +1,31 @@ -def add(a, b): - c = a + b - return c -def subtraction(a, b): - c = a - b - return c -def sqrt(a, b): #开方 - c = a**b - return c -def multiply(a, b): #乘法 - c = a * b - return c -def remainder(a, b): #取余 - c = a % b - return c -def aliquot(a, b): #整除 - c = a // b - return c -def divide(a, b): #除 - c = a / b - return c - -a = int(input("请输入一个数:")) -b = int(input("请输入一个数:")) -print(add(a,b)) -print(subtraction(a,b)) -print(sqrt(a,b)) -print(multiply(a, b)) -print(remainder(a, b)) -print(aliquot(a, b)) +def add(a, b): + c = a + b + return c +def subtraction(a, b): + c = a - b + return c +def sqrt(a, b): #开方 + c = a**b + return c +def multiply(a, b): #乘法 + c = a * b + return c +def remainder(a, b): #取余 + c = a % b + return c +def aliquot(a, b): #整除 + c = a // b + return c +def divide(a, b): #除 + c = a / b + return c + +a = int(input("请输入一个数:")) +b = int(input("请输入一个数:")) +print(add(a,b)) +print(subtraction(a,b)) +print(sqrt(a,b)) +print(multiply(a, b)) +print(remainder(a, b)) +print(aliquot(a, b)) print(divide(a, b)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276.py" index 2a325a73e044e2c6a5012709dda8d6675c15f69a..366729d6784cc1414a51892b4b01bf422e03a53f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\345\276\267\351\207\214\345\205\213/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276.py" @@ -1,68 +1,68 @@ -# 字符串的编码和解码 -a = "德里克".encode('utf-8') -print(a) -b = a.decode('utf-8') -print(b) - -# 字符串的CRUD -# Creat -a = "Derek" -b = a + ' hello!' -print(b) -# Retrieve---检索 -a = ['Derek', [1, 2], (2, 3, 4)] -d = a[0] -b = a[1] -c = a[2] -print("{}, {}, {}".format(b, c, d)) -a = "Derek, Hello" -b = a.find('!') -c = a.find('e') -print("{},{}".format(b,c)) -b = a.index('e') -print(b) -# update -a = "Dorok,hello" -b = a.replace('o', 'e') -print(b) - -a = "Derek, Mary, Ivan" -b = a.split(',') -print(b) -c = '#'.join(b) -print(c) - -# Delete -a = " hello, Derek " -b = a.strip() -print(b) -b = a.lstrip() -print(b) -b = a.rstrip() -print(b) - -# 字符串输入输出 -# 保存文件 -file_1 = open('Derek.txt', 'w', encoding="utf-8") -content = 'Derek, hello' -file_1.write(content) -file_1.close() -# 读取文件 -file_2 = open('Derek.txt', 'r', encoding='utf-8') -content = file_2.read() -print(content) -file_2.close() -# 追加文件 -file_3 = open('Derek.txt', 'a', encoding="utf-8") -content = "\nyou are so handsome that I love you" -file_3.write(content) -file_3.close() - -# 字符串输入输出 -a = "so" -b = "handsome" -print(f"Derek, you are : {a}, {b}") - -# 小数格式化 -b = "{:.2f}".format(3.1415926) -print(b) +# 字符串的编码和解码 +a = "德里克".encode('utf-8') +print(a) +b = a.decode('utf-8') +print(b) + +# 字符串的CRUD +# Creat +a = "Derek" +b = a + ' hello!' +print(b) +# Retrieve---检索 +a = ['Derek', [1, 2], (2, 3, 4)] +d = a[0] +b = a[1] +c = a[2] +print("{}, {}, {}".format(b, c, d)) +a = "Derek, Hello" +b = a.find('!') +c = a.find('e') +print("{},{}".format(b,c)) +b = a.index('e') +print(b) +# update +a = "Dorok,hello" +b = a.replace('o', 'e') +print(b) + +a = "Derek, Mary, Ivan" +b = a.split(',') +print(b) +c = '#'.join(b) +print(c) + +# Delete +a = " hello, Derek " +b = a.strip() +print(b) +b = a.lstrip() +print(b) +b = a.rstrip() +print(b) + +# 字符串输入输出 +# 保存文件 +file_1 = open('Derek.txt', 'w', encoding="utf-8") +content = 'Derek, hello' +file_1.write(content) +file_1.close() +# 读取文件 +file_2 = open('Derek.txt', 'r', encoding='utf-8') +content = file_2.read() +print(content) +file_2.close() +# 追加文件 +file_3 = open('Derek.txt', 'a', encoding="utf-8") +content = "\nyou are so handsome that I love you" +file_3.write(content) +file_3.close() + +# 字符串输入输出 +a = "so" +b = "handsome" +print(f"Derek, you are : {a}, {b}") + +# 小数格式化 +b = "{:.2f}".format(3.1415926) +print(b) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-test.py" index 9fead1bdbb2971e5668d6e0ce70bfbef61237dd8..0ebca7acacbe0dfb343b0ad748cb7b3e1b20f381 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-test.py" @@ -1,21 +1,21 @@ -''' -六大基本数据类型:int,float,str,bytes,boolean,None -四大基本数据结构:list,tuple,dict,set -''' -a=int(1) -b=float(2.0) -c=str('3') -d=bytes('4'.encode('utf-8')) -e=bool(5) -f=None - -#print(a,'\n',b,'\n',c,'\n',d,'\n',e,'\n',f,type(f)) -aa=[a,b,c,d,e,f] -bb=(a,b,c,d,e,f) -cc={"a1": a,"b1":b,"c1":c,"d1":d,"e1":e,"f1":f} -dd=set([a,b,c,d,e,f]) - -print('列表aa:',aa) -print('元组bb:',bb) -print('字典cc:',cc) +''' +六大基本数据类型:int,float,str,bytes,boolean,None +四大基本数据结构:list,tuple,dict,set +''' +a=int(1) +b=float(2.0) +c=str('3') +d=bytes('4'.encode('utf-8')) +e=bool(5) +f=None + +#print(a,'\n',b,'\n',c,'\n',d,'\n',e,'\n',f,type(f)) +aa=[a,b,c,d,e,f] +bb=(a,b,c,d,e,f) +cc={"a1": a,"b1":b,"c1":c,"d1":d,"e1":e,"f1":f} +dd=set([a,b,c,d,e,f]) + +print('列表aa:',aa) +print('元组bb:',bb) +print('字典cc:',cc) print('集合dd:',dd) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\345\267\256\345\274\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\345\267\256\345\274\202.md" index e207540b00a85315e7cb3c12f995cc0a8c290546..8b08dfbd2d2bbec24b26c74b9d78d42416ecfbce 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\345\267\256\345\274\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\345\267\256\345\274\202.md" @@ -1,13 +1,13 @@ -1:四大基本数据结构中哪些是可变的, 哪些是不可变的? - -​ 可变的:列表list,字典dict,集合set - -​ 不可以变的:元组tuple - -2:四大基本数据结构中哪些是有序的, 哪些是无序的? - -​ 有序的:列表list,元组tuple - -​ 无序的:字典dict,集合set - +1:四大基本数据结构中哪些是可变的, 哪些是不可变的? + +​ 可变的:列表list,字典dict,集合set + +​ 不可以变的:元组tuple + +2:四大基本数据结构中哪些是有序的, 哪些是无序的? + +​ 有序的:列表list,元组tuple + +​ 无序的:字典dict,集合set + 3:set无法包括全部数据类型(bool值为true时) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202.md" index fb7c46bcf967c83b15a6e574ef7acae6d7c27914..ba5deda92bb99bea5a18a4c9efb7553c497927ba 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202.md" @@ -1,83 +1,83 @@ -1:什么是关系型数据表,什么是非关系型数据表,有什么区别,各有什么应用场景 - -``` -关系型数据库: -创建在**关系模型**基础上的数据库,用来存储和管理结构化的数据 -``` - -``` -非关系型数据库not only sql: -创建在nosql系统存储(键值对)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 -``` - -``` -区别: -关系型数据库通过索引查找数据,速度较慢。由于事务,所以比较可靠 - -非关系型数据库通过键值对查找数据,速度较快 -``` - -``` -应用场景: -关系型数据库应用在对可靠性有需求的情况。例如银行系统 -非关系型数据库应用在对速度有需求的情况。例如一些实时互动 -``` - -2:什么是事务, 事务的特点: - -``` -什么是事务: -数据库操作的最小工作单元,是作为单个逻辑工作单元的一系列操作,这些操作作为一个整体一起向系统提交,要么都执行,要么都不执行,事务是一组不可以再分割的操作集合(工作逻辑单元) -``` - -``` -关系型数据库/事务的特点(ACID): - -atomic(原子性):不可分割(根据原子是组成物质的最小单位),即对事务的操作是不可分割的,要么是,要么不是,不存在其他状态。 - -举例说明:A向B转账,转账结果只有转账完成和转账未完成,如果有其他状态,银行系统将会崩溃。 - -consistence(一致性):事务之间同时运行,无论谁先结束,数据库都会到达一致。 - -举例说明:AB相约在某饭店吃饭,不管谁等谁,等了多久,只要两者到达饭店就ok。 - -isolation(隔离性):解决多个事务同时对数据进行读取和修改能力。 - -duration(持久性):某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够被持久性地保存下来。事务的所有操作都是有记录的,即使数据库中途崩溃,仍然可以通过记录恢复。 -``` - -3:完成Mysql服务端和Navicat的安装: - -![MySQL](C:\Users\孤傲冷青双\Desktop\MySQL.png) - -![image-20210127230545590](C:\Users\孤傲冷青双\Desktop\image-20210127230545590.png) - -4:完成数据库和数据表的基础操作. - -``` -对数据库的增删改查: -CREATE 增:CREATE DATABASE test_2; -DROP 删:DROP DATABASE test_2; -update 改:ALTER database test DEFAULT CHARACTER SET 'utf8mb4' -retrieve查:show databases; -``` - -``` -对数据表的增删改查: -create 增: -use test; -CREATE TABLE grade( - chinese float(3), - mathematics float(3), - english float(3) -); -drop 删: -drop table grade; -update 改: -use test; -ALTER table grade DEFAULT CHARACTER set 'utf8mb4',RENAME gradess; -retrieve查: -use test; -show tables; -``` - +1:什么是关系型数据表,什么是非关系型数据表,有什么区别,各有什么应用场景 + +``` +关系型数据库: +创建在**关系模型**基础上的数据库,用来存储和管理结构化的数据 +``` + +``` +非关系型数据库not only sql: +创建在nosql系统存储(键值对)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 +``` + +``` +区别: +关系型数据库通过索引查找数据,速度较慢。由于事务,所以比较可靠 + +非关系型数据库通过键值对查找数据,速度较快 +``` + +``` +应用场景: +关系型数据库应用在对可靠性有需求的情况。例如银行系统 +非关系型数据库应用在对速度有需求的情况。例如一些实时互动 +``` + +2:什么是事务, 事务的特点: + +``` +什么是事务: +数据库操作的最小工作单元,是作为单个逻辑工作单元的一系列操作,这些操作作为一个整体一起向系统提交,要么都执行,要么都不执行,事务是一组不可以再分割的操作集合(工作逻辑单元) +``` + +``` +关系型数据库/事务的特点(ACID): + +atomic(原子性):不可分割(根据原子是组成物质的最小单位),即对事务的操作是不可分割的,要么是,要么不是,不存在其他状态。 + +举例说明:A向B转账,转账结果只有转账完成和转账未完成,如果有其他状态,银行系统将会崩溃。 + +consistence(一致性):事务之间同时运行,无论谁先结束,数据库都会到达一致。 + +举例说明:AB相约在某饭店吃饭,不管谁等谁,等了多久,只要两者到达饭店就ok。 + +isolation(隔离性):解决多个事务同时对数据进行读取和修改能力。 + +duration(持久性):某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够被持久性地保存下来。事务的所有操作都是有记录的,即使数据库中途崩溃,仍然可以通过记录恢复。 +``` + +3:完成Mysql服务端和Navicat的安装: + +![MySQL](C:\Users\孤傲冷青双\Desktop\MySQL.png) + +![image-20210127230545590](C:\Users\孤傲冷青双\Desktop\image-20210127230545590.png) + +4:完成数据库和数据表的基础操作. + +``` +对数据库的增删改查: +CREATE 增:CREATE DATABASE test_2; +DROP 删:DROP DATABASE test_2; +update 改:ALTER database test DEFAULT CHARACTER SET 'utf8mb4' +retrieve查:show databases; +``` + +``` +对数据表的增删改查: +create 增: +use test; +CREATE TABLE grade( + chinese float(3), + mathematics float(3), + english float(3) +); +drop 删: +drop table grade; +update 改: +use test; +ALTER table grade DEFAULT CHARACTER set 'utf8mb4',RENAME gradess; +retrieve查: +use test; +show tables; +``` + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\346\225\260\346\215\256\345\272\223\344\270\255\347\232\204curd\345\222\214\351\233\206\345\220\210\346\223\215\344\275\234.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\346\225\260\346\215\256\345\272\223\344\270\255\347\232\204curd\345\222\214\351\233\206\345\220\210\346\223\215\344\275\234.md" index 66524e84b70d5c344dab0d2a48416977288688e3..a40d03e3de0b972765f8342b4af6345f22b16052 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\346\225\260\346\215\256\345\272\223\344\270\255\347\232\204curd\345\222\214\351\233\206\345\220\210\346\223\215\344\275\234.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202-\346\225\260\346\215\256\345\272\223\344\270\255\347\232\204curd\345\222\214\351\233\206\345\220\210\346\223\215\344\275\234.md" @@ -1,106 +1,106 @@ -**curd操作** - -1:增 - -``` -1:单条插入: -insert into class_1 values ('杨',20,1); -2:多条插入: -insert into class_2 (name,age,gender) values ('孙',20,1),('郑',19,0); -``` - -2:查 - -``` -1:查询所有 -select * from class_1; -2:查询指定字段名 -select age from class_1; -3:条件查询 -select * from class_1 where age = 18; -select age,name from class_1 where age = 18; -4:模糊查询 -select * from class_1 where name like '赵%'; -5:限制返回条数 -select * from class_1 where age = 18 limit 3; -6:过滤重复值 -select distinct age,gender from class_1 where gender = 0; -7:对查询结果进行升序排序 -select * from class_1 order by age ASC; -8:对查询结果进行降序排序 -select * from class_1 order by age DESC; -9:获取返回结果的总条数 -select count(*) from class_1; -``` - -3:改 - -``` -update class_1 set name = '皇' where name='赵'; -``` - -4:删 - -``` -delete from class_1 where name = '皇'; -``` - -**集合操作** - -1:并集 - -``` -select name,age,gender from class_1 where name is not null -union -select name,age,gender from class_2 where name is not null -``` - -2:交集 - -``` -select c1.name,c1.age,c1.gender from -(select name,age,gender from class_1 where name is not null) as c1 -join -(select name,age,gender from class_2 where name is not null) as c2 -where c1.name = c2.name -``` - -3:差集 - -``` -A对B差集 -select c1.name from -(select name from class_1 where name is not null) as c1 -left join -(select name from class_2 where name is not null) as c2 -on c1.name = c2.name -where c2.name is NULL -B对A差集 -select * from -(select name from class_1 where name is not null) as c1 -right join -(select name from class_2 where name is not null) as c2 -on c1.name = c2.name -where c1.name is NULL -``` - -4:补集 - -``` -A和B的补集 = A和B的并集 - A和B的交集 -或 A和B的补集 = A对B的差集 + B对A的差集 -select c1.name from -(select name from class_1 where name is not null) as c1 -left join -(select name from class_2 where name is not null) as c2 -on c1.name = c2.name -where c2.name is NULL -union -select c2.name from -(select name from class_1 where name is not null) as c1 -right join -(select name from class_2 where name is not null) as c2 -on c1.name = c2.name -where c1.name is NULL -``` - +**curd操作** + +1:增 + +``` +1:单条插入: +insert into class_1 values ('杨',20,1); +2:多条插入: +insert into class_2 (name,age,gender) values ('孙',20,1),('郑',19,0); +``` + +2:查 + +``` +1:查询所有 +select * from class_1; +2:查询指定字段名 +select age from class_1; +3:条件查询 +select * from class_1 where age = 18; +select age,name from class_1 where age = 18; +4:模糊查询 +select * from class_1 where name like '赵%'; +5:限制返回条数 +select * from class_1 where age = 18 limit 3; +6:过滤重复值 +select distinct age,gender from class_1 where gender = 0; +7:对查询结果进行升序排序 +select * from class_1 order by age ASC; +8:对查询结果进行降序排序 +select * from class_1 order by age DESC; +9:获取返回结果的总条数 +select count(*) from class_1; +``` + +3:改 + +``` +update class_1 set name = '皇' where name='赵'; +``` + +4:删 + +``` +delete from class_1 where name = '皇'; +``` + +**集合操作** + +1:并集 + +``` +select name,age,gender from class_1 where name is not null +union +select name,age,gender from class_2 where name is not null +``` + +2:交集 + +``` +select c1.name,c1.age,c1.gender from +(select name,age,gender from class_1 where name is not null) as c1 +join +(select name,age,gender from class_2 where name is not null) as c2 +where c1.name = c2.name +``` + +3:差集 + +``` +A对B差集 +select c1.name from +(select name from class_1 where name is not null) as c1 +left join +(select name from class_2 where name is not null) as c2 +on c1.name = c2.name +where c2.name is NULL +B对A差集 +select * from +(select name from class_1 where name is not null) as c1 +right join +(select name from class_2 where name is not null) as c2 +on c1.name = c2.name +where c1.name is NULL +``` + +4:补集 + +``` +A和B的补集 = A和B的并集 - A和B的交集 +或 A和B的补集 = A对B的差集 + B对A的差集 +select c1.name from +(select name from class_1 where name is not null) as c1 +left join +(select name from class_2 where name is not null) as c2 +on c1.name = c2.name +where c2.name is NULL +union +select c2.name from +(select name from class_1 where name is not null) as c1 +right join +(select name from class_2 where name is not null) as c2 +on c1.name = c2.name +where c1.name is NULL +``` + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202.md" index 8efdb9c8fa32050468b5039fefed61060f56a19d..6b302e29b535e38bdb63c69d5877c2a57cdea616 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\203\345\221\250/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202.md" @@ -1,73 +1,73 @@ -1:通过navicat建表, 包含当前常用的数据类型. - -``` -use test; -create table test_table_2( - test_int int(10), - test_bigint bigint(19), - test_float float(7,2), - test_double double(15,2), - test_decimal decimal(65,2), - test_char char(255), - test_varchar varchar(6553), - test_text LONGTEXT, - test_datetime TIMESTAMP - ) DEFAULT CHARACTER SET 'utf8mb4' -``` - -``` -use test; -insert into test_table_2 (test_int,test_float) values (5,10.55); -``` - -2:练习常用的运算符 - -``` -算术运算符: - 加减乘除: select 4(+-*/)5 - 取商: select 4 div 5 - 取余: select 4 mod 5 - -比较运算符:(返回值1为true,0为false) - 大于,小于,大于等于,小于等于,等于: select 4 (>,<,>=,<=,=) 5 - 在某个区间(两边闭区间):select 4 BETWEEN 3 and 4,select 4 BETWEEN 4 and 5 返回值为1 - 不在某个区间:select 4 not BETWEEN 4 and 5,select 4 not BETWEEN 3 and 4 返回值为0 - 判断有没有记录:select 4 is not null 返回值为1 - select 4 is null 返回值为0 - -逻辑运算符: - not(非):select not 1=0 返回值为1(当表达式为true时,通过not取反,得到false) - and(与运算):select 1=1 and 0=0 返回值为1(两个条件都要true) - or(或运算):select 1=1 or 2=0 返回值为1(只要有一个true) - xor:select 1=1 xor 1=0 返回值为1(一个true一个false) -``` - -3:练习常用的函数 - -``` - sum(求和): - use test; - select sum(test_int) from test_table_2; - avg(求平均值): - use test; - select avg(test_int) from test_table_2; - count(记录数量): - use test; - select count(test_int) from test_table_2; - max(取最大值): - use test; - select max(test_int) from test_table_2; - min(取最小值): - use test; - select min(test_int) from test_table_2; - char_length(计算字符串长度): - select char_length('123456'); 结果:6 - format(格式化输出): - select format('123456',2) 结果:123456.00 - left和right(取左边或右边N位字符): - select left('123456',2) 结果:12 - select right('123456',2) 结果:56 - trim(清空左右两边空格): - select trim(' 12 34 56 ') 结果:12 34 56 -``` - +1:通过navicat建表, 包含当前常用的数据类型. + +``` +use test; +create table test_table_2( + test_int int(10), + test_bigint bigint(19), + test_float float(7,2), + test_double double(15,2), + test_decimal decimal(65,2), + test_char char(255), + test_varchar varchar(6553), + test_text LONGTEXT, + test_datetime TIMESTAMP + ) DEFAULT CHARACTER SET 'utf8mb4' +``` + +``` +use test; +insert into test_table_2 (test_int,test_float) values (5,10.55); +``` + +2:练习常用的运算符 + +``` +算术运算符: + 加减乘除: select 4(+-*/)5 + 取商: select 4 div 5 + 取余: select 4 mod 5 + +比较运算符:(返回值1为true,0为false) + 大于,小于,大于等于,小于等于,等于: select 4 (>,<,>=,<=,=) 5 + 在某个区间(两边闭区间):select 4 BETWEEN 3 and 4,select 4 BETWEEN 4 and 5 返回值为1 + 不在某个区间:select 4 not BETWEEN 4 and 5,select 4 not BETWEEN 3 and 4 返回值为0 + 判断有没有记录:select 4 is not null 返回值为1 + select 4 is null 返回值为0 + +逻辑运算符: + not(非):select not 1=0 返回值为1(当表达式为true时,通过not取反,得到false) + and(与运算):select 1=1 and 0=0 返回值为1(两个条件都要true) + or(或运算):select 1=1 or 2=0 返回值为1(只要有一个true) + xor:select 1=1 xor 1=0 返回值为1(一个true一个false) +``` + +3:练习常用的函数 + +``` + sum(求和): + use test; + select sum(test_int) from test_table_2; + avg(求平均值): + use test; + select avg(test_int) from test_table_2; + count(记录数量): + use test; + select count(test_int) from test_table_2; + max(取最大值): + use test; + select max(test_int) from test_table_2; + min(取最小值): + use test; + select min(test_int) from test_table_2; + char_length(计算字符串长度): + select char_length('123456'); 结果:6 + format(格式化输出): + select format('123456',2) 结果:123456.00 + left和right(取左边或右边N位字符): + select left('123456',2) 结果:12 + select right('123456',2) 结果:56 + trim(清空左右两边空格): + select trim(' 12 34 56 ') 结果:12 34 56 +``` + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202.py" index daf3fd747be1ed06fc2c572b1aafd4fe56b9735f..6fb639194adce993a6a37f586c1af88e44cbf5e6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202.py" @@ -1,48 +1,48 @@ -#给定一个列表classes,对classes进行操作 -import math -def classes(): - classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, - ] - return classes - -#将classes按grade从A到D进行排序 -res_1=classes() -res_1.sort(key=lambda x:x["grade"]) -print(res_1) - -#过滤器filter筛选出grade为A的同学 -res_2=classes() -filter_1=filter(lambda x:x["grade"]=="A",res_2) -print(list(filter_1)) - -#通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) -res_3=classes() -def add_1(i): - i['age']+=1 - #print(i['name'],i['age'],i['grade']) - return i -map_1=map(add_1,res_3) -print(list(map_1)) - -#使用递归函数重构斐波那契函数,,f(n) = f(n-1) + f(n-2),,[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] -def a(n): - if n==0: - return 0 - if n==1: - return 1 - if n>1: - res=a(n-1)+a(n-2) - return res -arr=[] -for i in range(0,10010): - if a(i)>100: - break - arr.append(a(i)) +#给定一个列表classes,对classes进行操作 +import math +def classes(): + classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, + ] + return classes + +#将classes按grade从A到D进行排序 +res_1=classes() +res_1.sort(key=lambda x:x["grade"]) +print(res_1) + +#过滤器filter筛选出grade为A的同学 +res_2=classes() +filter_1=filter(lambda x:x["grade"]=="A",res_2) +print(list(filter_1)) + +#通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) +res_3=classes() +def add_1(i): + i['age']+=1 + #print(i['name'],i['age'],i['grade']) + return i +map_1=map(add_1,res_3) +print(list(map_1)) + +#使用递归函数重构斐波那契函数,,f(n) = f(n-1) + f(n-2),,[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] +def a(n): + if n==0: + return 0 + if n==1: + return 1 + if n>1: + res=a(n-1)+a(n-2) + return res +arr=[] +for i in range(0,10010): + if a(i)>100: + break + arr.append(a(i)) print(arr) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-for\357\274\214while\345\276\252\347\216\257\345\222\214\345\274\202\345\270\270\345\244\204\347\220\206.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-for\357\274\214while\345\276\252\347\216\257\345\222\214\345\274\202\345\270\270\345\244\204\347\220\206.py" index 667c06bd0e10d849e099755eb15a69efe3d37d0c..3bdfd45016202aa751f581c7c64c4a5931c89666 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-for\357\274\214while\345\276\252\347\216\257\345\222\214\345\274\202\345\270\270\345\244\204\347\220\206.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\270\211\345\221\250/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-for\357\274\214while\345\276\252\347\216\257\345\222\214\345\274\202\345\270\270\345\244\204\347\220\206.py" @@ -1,83 +1,83 @@ -#用for循环进行计数 -def for_sum(): - sum=0 - a=[0,5,8,3,4,False,None] - for i in a: - if type(i) == int: - sum += i - return f"当前for循环sum值为:{sum}" - -#while循环进行计数,while循环一定要有退出机制 -def while_sum(): - sum=50 - while sum<=500: - if sum>500: - break - sum+=100 - return f"当前while循环sum值为:{sum}" - -#用for和while循环实现裴波那契函数f(n)=f(n-1)+f(n-2) [0,1,1,2,3,5,8,13...] -def pbnq(): - n1=0 - n2=1 - n3=0 - arr=[0,1] - while n3<100: - n3=n1+n2 - if n3>=100: - break - n1=n2 - n2=n3 - arr.append(n3) - return f"裴波那契函数(100以内):{arr}" - -#简约计算器 -def calculator(a,b): - res = 0 - a = int(a) - b = int(b) - if c == "+": - res = a+b - if c == "-": - res = a-b - if c == "*": - res = a*b - if c == "/": - try: - res = a/b - except: - return "运算出错,分母不能为0" - if c == "%": - try: - res = a%b - except: - return "运算出错,分母不能为0" - if c == "//": - try: - res = a//b - except: - return "运算出错,分母不能为0" - if c == "**": - res = a ** b - return f"{a}{c}{b}运算结果是:{res}" - -a=input("输入第一个:") -b=input("输入第二个:") -c=input("输入运算符:") -if a.isdigit() == True and b.isdigit() == True: - pass -else: - print("请输入数字进行计算!") - -if __name__ == '__main__': - res_for_sum=for_sum() - print(res_for_sum) - - res_while_sum=while_sum() - print(res_while_sum) - - res_pbnq=pbnq() - print(res_pbnq) - - res_calculator = calculator(a,b) +#用for循环进行计数 +def for_sum(): + sum=0 + a=[0,5,8,3,4,False,None] + for i in a: + if type(i) == int: + sum += i + return f"当前for循环sum值为:{sum}" + +#while循环进行计数,while循环一定要有退出机制 +def while_sum(): + sum=50 + while sum<=500: + if sum>500: + break + sum+=100 + return f"当前while循环sum值为:{sum}" + +#用for和while循环实现裴波那契函数f(n)=f(n-1)+f(n-2) [0,1,1,2,3,5,8,13...] +def pbnq(): + n1=0 + n2=1 + n3=0 + arr=[0,1] + while n3<100: + n3=n1+n2 + if n3>=100: + break + n1=n2 + n2=n3 + arr.append(n3) + return f"裴波那契函数(100以内):{arr}" + +#简约计算器 +def calculator(a,b): + res = 0 + a = int(a) + b = int(b) + if c == "+": + res = a+b + if c == "-": + res = a-b + if c == "*": + res = a*b + if c == "/": + try: + res = a/b + except: + return "运算出错,分母不能为0" + if c == "%": + try: + res = a%b + except: + return "运算出错,分母不能为0" + if c == "//": + try: + res = a//b + except: + return "运算出错,分母不能为0" + if c == "**": + res = a ** b + return f"{a}{c}{b}运算结果是:{res}" + +a=input("输入第一个:") +b=input("输入第二个:") +c=input("输入运算符:") +if a.isdigit() == True and b.isdigit() == True: + pass +else: + print("请输入数字进行计算!") + +if __name__ == '__main__': + res_for_sum=for_sum() + print(res_for_sum) + + res_while_sum=while_sum() + print(res_while_sum) + + res_pbnq=pbnq() + print(res_pbnq) + + res_calculator = calculator(a,b) print(res_calculator) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202-\350\257\267\346\261\202\347\232\204\347\273\204\346\210\220.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202-\350\257\267\346\261\202\347\232\204\347\273\204\346\210\220.py" index a82ebf3ffdecd9c20e0e765d9be3dc72369a53a3..42f65cea08fadac36779665ceefe197a3200a492 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202-\350\257\267\346\261\202\347\232\204\347\273\204\346\210\220.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202-\350\257\267\346\261\202\347\232\204\347\273\204\346\210\220.py" @@ -1,60 +1,60 @@ -import requests -import json - -urls={ - "search_url":"https://search.jd.com/Search", - "item_url":"https://item.jd.com/" -} -def request_jd(url,keyword): - get_url = urls.get(url) - - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" - } - - params = { - "keyword": keyword - } - - result = requests.get(url = get_url,params=params,headers = headers) - str_result = result.text - print(type(result.text),type(result)) - - if url == 'search_url': - file_name = "search_"+keyword+".html" - - if url == 'item_url': - file_name = "item_" + keyword + ".html" - - save_as_file = open(file_name,'w',encoding="utf-8") - save_as_file.write(str_result) - save_as_file.close() - - #print(result.text) - - -#json格式练习 -#json数据是 str -def json_test(): - test = { - "int" : 1, - "str" : "1", - "dict" : {"a": "1", "b": "2"}, - "list" : [1, "2", None] - } - - #将dict转换为json - json_data = json.dumps(test) - print(type(json_data),json_data) - - #将json转换为dict - dict_data = json.loads(json_data) - print(type(dict_data), dict_data) - - -if __name__ == "__main__": - #搜索页用 search_url - #request_jd("search_url","gtx1050") - #详情页用 item_url - #request_jd("item_url","68451273596") +import requests +import json + +urls={ + "search_url":"https://search.jd.com/Search", + "item_url":"https://item.jd.com/" +} +def request_jd(url,keyword): + get_url = urls.get(url) + + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" + } + + params = { + "keyword": keyword + } + + result = requests.get(url = get_url,params=params,headers = headers) + str_result = result.text + print(type(result.text),type(result)) + + if url == 'search_url': + file_name = "search_"+keyword+".html" + + if url == 'item_url': + file_name = "item_" + keyword + ".html" + + save_as_file = open(file_name,'w',encoding="utf-8") + save_as_file.write(str_result) + save_as_file.close() + + #print(result.text) + + +#json格式练习 +#json数据是 str +def json_test(): + test = { + "int" : 1, + "str" : "1", + "dict" : {"a": "1", "b": "2"}, + "list" : [1, "2", None] + } + + #将dict转换为json + json_data = json.dumps(test) + print(type(json_data),json_data) + + #将json转换为dict + dict_data = json.loads(json_data) + print(type(dict_data), dict_data) + + +if __name__ == "__main__": + #搜索页用 search_url + #request_jd("search_url","gtx1050") + #详情页用 item_url + #request_jd("item_url","68451273596") json_test() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.md" index 873a1ad9cb3e6fa9e393f869425ac08d375ccbca..b9ec63693d97992a5e2d793749b18a87f66580f8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.md" @@ -1,205 +1,205 @@ -css-selector - - - -**定位到的结果是一个列表** - - - -本次参考链接https://search.jd.com/Search?keyword=gtx1080 - -- 直接定位元素 - - 通过id定位元素(通常id是唯一的) - - ``` - $("#J_goodsList") - ``` - - - 通过class定位元素(不适用于同个标签有多个class值如
                                                                                    ) - - ``` - $(".gl-item") - $(".gl-warp clearfix") 就没有定位结果 - ``` - - - 通过属性名定位元素 - - ``` - $("ul[class='gl-warp clearfix']")[0] - ``` - -- 获取兄弟节点 - - - 获取当前节点的下一个节点 - - - 通过dom提供的接口获取,不属于css选择器的语法 - - ``` - $("li[data-sku='62357495472']")[0].nextElementSibling - ``` - - - 通过css选择器语法(相对复杂,不建议用) - - ``` - $("ul[class='gl-warp clearfix'] li:first-child + li") - ``` - - - 获取当前节点的上一个节点 - - - 通过dom提供的接口获取,不属于css选择器的语法 - - ``` - $("li[data-sku='68451273583']")[0].previousElementSibling - ``` - -- 获取父子节点 - - - 获取父节点 - - ``` - $("li[data-sku='68451273583']")[0].parentElement - ``` - - - 获取子节点 - - - 获取所有子节点 - - - 遍历所有的符合条件的元素 - - ``` - 所有标签是div的节点都会获取到 - $("ul[class='gl-warp clearfix'] div") - - 通过属性名定位可以筛选出符合条件的div - $("ul[class='gl-warp clearfix'] div[class='gl-i-wrap']") - ``` - - - 通过dom提供的接口获取,不属于css选择器的语法 - - ``` - $("ul[class='gl-warp clearfix']")[0].children - ``` - - - 获取第一个子节点 - - ``` - $("ul[class='gl-warp clearfix'] li:first-child") - ``` - - - 获取最后一个子节点 - - ``` - $("ul[class='gl-warp clearfix'] li:last-child") - ``` - - - 获取第n个子节点(从1数起,不是从0,n就是第n个) - - ``` - $("ul[class='gl-warp clearfix'] li:nth-child(1)")[0] - ``` - -- 模糊匹配 - - - 匹配开头 ( ^ ) - - ``` - $("li[data-sku^='4']") - ``` - - - 匹配结尾 ( $ ) - - ``` - $("li[data-sku$='4']") - ``` - - - 匹配子集 ( * )(即匹配所有含有x的) - - ``` - $("li[data-sku*='4']") - ``` - -- 获取文本值 - - ``` - 获取指定li标签下的所有文本值 - $("li[data-sku*='4']")[0].innerText - - 获取指定li标签下class为p-price的div的所有文本值 - $("li[data-sku*='4'] div[class='p-price']")[0].innerText - ``` - -- 获取属性值 - - ``` - 获取ul下第二个li标签的属性名为data-sku的值 - $("ul[class='gl-warp clearfix'] li:nth-child(2)")[0].getAttribute("data-sku") - ``` - - - -beautifulsoup - -- 使用BeautifulSoup - - ``` - from bs4 import BeautifulSoup - - - def jd_search_parse(html): - soup = BeautifulSoup(html, "lxml") - item = soup.select("li[data-sku='6039832']")[0] - ``` - -- 直接定位元素 - - 略 - -- 去除空白字符 - - ``` - html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") - ``` - -- 获取兄弟节点 - - - 获取上一个节点 - - ``` - tmp_ele.previous_sibling - ``` - - - 获取下一个节点 - - ``` - tmp_ele.next_sibling - ``` - -- 获取父子节点 - - - 获取父节点 - - ``` - tmp_ele.parent - ``` - - - 获取子节点 - - ``` - tmp_ele.children - ``` - -- 模糊匹配 - - 略 - -- 获取文本值 - - ``` - content = tmp_ele.text.strip() - ``` - -- 获取属性值 - - ``` - value = tmp_ele.attrs["data-sku"] +css-selector + + + +**定位到的结果是一个列表** + + + +本次参考链接https://search.jd.com/Search?keyword=gtx1080 + +- 直接定位元素 + - 通过id定位元素(通常id是唯一的) + + ``` + $("#J_goodsList") + ``` + + - 通过class定位元素(不适用于同个标签有多个class值如
                                                                                      ) + + ``` + $(".gl-item") + $(".gl-warp clearfix") 就没有定位结果 + ``` + + - 通过属性名定位元素 + + ``` + $("ul[class='gl-warp clearfix']")[0] + ``` + +- 获取兄弟节点 + + - 获取当前节点的下一个节点 + + - 通过dom提供的接口获取,不属于css选择器的语法 + + ``` + $("li[data-sku='62357495472']")[0].nextElementSibling + ``` + + - 通过css选择器语法(相对复杂,不建议用) + + ``` + $("ul[class='gl-warp clearfix'] li:first-child + li") + ``` + + - 获取当前节点的上一个节点 + + - 通过dom提供的接口获取,不属于css选择器的语法 + + ``` + $("li[data-sku='68451273583']")[0].previousElementSibling + ``` + +- 获取父子节点 + + - 获取父节点 + + ``` + $("li[data-sku='68451273583']")[0].parentElement + ``` + + - 获取子节点 + + - 获取所有子节点 + + - 遍历所有的符合条件的元素 + + ``` + 所有标签是div的节点都会获取到 + $("ul[class='gl-warp clearfix'] div") + + 通过属性名定位可以筛选出符合条件的div + $("ul[class='gl-warp clearfix'] div[class='gl-i-wrap']") + ``` + + - 通过dom提供的接口获取,不属于css选择器的语法 + + ``` + $("ul[class='gl-warp clearfix']")[0].children + ``` + + - 获取第一个子节点 + + ``` + $("ul[class='gl-warp clearfix'] li:first-child") + ``` + + - 获取最后一个子节点 + + ``` + $("ul[class='gl-warp clearfix'] li:last-child") + ``` + + - 获取第n个子节点(从1数起,不是从0,n就是第n个) + + ``` + $("ul[class='gl-warp clearfix'] li:nth-child(1)")[0] + ``` + +- 模糊匹配 + + - 匹配开头 ( ^ ) + + ``` + $("li[data-sku^='4']") + ``` + + - 匹配结尾 ( $ ) + + ``` + $("li[data-sku$='4']") + ``` + + - 匹配子集 ( * )(即匹配所有含有x的) + + ``` + $("li[data-sku*='4']") + ``` + +- 获取文本值 + + ``` + 获取指定li标签下的所有文本值 + $("li[data-sku*='4']")[0].innerText + + 获取指定li标签下class为p-price的div的所有文本值 + $("li[data-sku*='4'] div[class='p-price']")[0].innerText + ``` + +- 获取属性值 + + ``` + 获取ul下第二个li标签的属性名为data-sku的值 + $("ul[class='gl-warp clearfix'] li:nth-child(2)")[0].getAttribute("data-sku") + ``` + + + +beautifulsoup + +- 使用BeautifulSoup + + ``` + from bs4 import BeautifulSoup + + + def jd_search_parse(html): + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='6039832']")[0] + ``` + +- 直接定位元素 + + 略 + +- 去除空白字符 + + ``` + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") + ``` + +- 获取兄弟节点 + + - 获取上一个节点 + + ``` + tmp_ele.previous_sibling + ``` + + - 获取下一个节点 + + ``` + tmp_ele.next_sibling + ``` + +- 获取父子节点 + + - 获取父节点 + + ``` + tmp_ele.parent + ``` + + - 获取子节点 + + ``` + tmp_ele.children + ``` + +- 模糊匹配 + + 略 + +- 获取文本值 + + ``` + content = tmp_ele.text.strip() + ``` + +- 获取属性值 + + ``` + value = tmp_ele.attrs["data-sku"] ``` \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.py" index e9173094fb0e3105076d79313017b41e4ec17045..1eccb7c463d82dbdd841b6154f7d93b24af1b7ae 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\271\235\345\221\250/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202-css\351\200\211\346\213\251\345\231\250\345\222\214beautifulsoup.py" @@ -1,14 +1,14 @@ -from bs4 import BeautifulSoup - -def jd_search(html): - soup = BeautifulSoup(html,"lxml") - result = soup.select("ul[class='gl-warp clearfix'] li div[class='gl-i-wrap']") - - for i in range(len(result)): - print(result[i].text,'\n') - -if __name__ == "__main__": - with open("search_gtx1080.html","r",encoding="utf-8") as f: - html = f.read() - html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") +from bs4 import BeautifulSoup + +def jd_search(html): + soup = BeautifulSoup(html,"lxml") + result = soup.select("ul[class='gl-warp clearfix'] li div[class='gl-i-wrap']") + + for i in range(len(result)): + print(result[i].text,'\n') + +if __name__ == "__main__": + with open("search_gtx1080.html","r",encoding="utf-8") as f: + html = f.read() + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") jd_search(html) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/my_calculator.py" index 137477b9d256c8906aaf6c28b58c5ccfc45e3a2e..784ef6b09b4e7e2e6003033f720bbdd4f28e1c53 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/my_calculator.py" @@ -1,41 +1,41 @@ -def add(a,b): - return int(a)+int(b) -def subtract(a,b): - return int(a)-int(b) -def multiply(a,b): - return int(a)*int(b) -def divide(a,b): - return int(a)/int(b) -def zhengchu(a,b): - return int(a)//int(b) -def quyu(a,b): - return int(a)%int(b) -def sqrt(a,b): - return int(a)**(1/int(b)) - -a=input("请输入第一个数字:") -b=input("请输入运算符(根号用空格表示):") -c=input("请输入第二个数字:") - -if b=='+': - result=add(a,c) - print("运算结果为:",result) -if b=='-': - result=subtract(a,c) - print("运算结果为:",result) -if b=='*': - result=multiply(a,c) - print("运算结果为:",result) -if b=='/': - result=divide(a,c) - print("运算结果为:",result) -if b=='//': - result=zhengchu(a,c) - print("运算结果为:",result) -if b=='%': - result=quyu(a,c) - print("运算结果为:",result) -if b==' ': - #'根号打不出来用空格表示' - result=sqrt(a,c) +def add(a,b): + return int(a)+int(b) +def subtract(a,b): + return int(a)-int(b) +def multiply(a,b): + return int(a)*int(b) +def divide(a,b): + return int(a)/int(b) +def zhengchu(a,b): + return int(a)//int(b) +def quyu(a,b): + return int(a)%int(b) +def sqrt(a,b): + return int(a)**(1/int(b)) + +a=input("请输入第一个数字:") +b=input("请输入运算符(根号用空格表示):") +c=input("请输入第二个数字:") + +if b=='+': + result=add(a,c) + print("运算结果为:",result) +if b=='-': + result=subtract(a,c) + print("运算结果为:",result) +if b=='*': + result=multiply(a,c) + print("运算结果为:",result) +if b=='/': + result=divide(a,c) + print("运算结果为:",result) +if b=='//': + result=zhengchu(a,c) + print("运算结果为:",result) +if b=='%': + result=quyu(a,c) + print("运算结果为:",result) +if b==' ': + #'根号打不出来用空格表示' + result=sqrt(a,c) print("运算结果为:",result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245.py" index d0463c2aebe524cfdcae19642fae96dbc2258cfb..307befc4b81559561a973cd389f297bad401654c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\345\233\233\345\244\247\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245.py" @@ -1,192 +1,192 @@ -# 1:list的crud -# list中储存的元素是引用 -def lists(): - list_1 = ['1',2,3.0,4>5,6<7,None,bytes("8",encoding="utf-8")] - list_2 = ['9','10'] - list_3 = [0,True,False,4,1] - return list_1,list_2,list_3 - -''' 1.1: create(增) -your_list.append()(在list末尾新增) -+(通过+号拼接两个list,并返回新的list) -+=(list内存地址不变) -*(通过*n,引用n个list里的所有元素,再赋值给list) -*=(。。。) -your_list.insert()(在下标为XX的位置,插入"XX";当下标大于当前列表长度时,则插入到末尾位置) -''' -list_1=lists()[0] -list_2=lists()[1] -print("list_1:",list_1,"->内存地址:",id(list_1)) -list_1.append("我是append进来的") -print("list_1.append():",list_1,"->内存地址:",id(list_1)) -list_1 = list_1 + list_2 -print("list_1+list_2:",list_1,"->内存地址:",id(list_1)) -list_1 += list_2 -print("list_1+=list_2:",list_1,"->内存地址:",id(list_1)) -list_1 = list_1*2 -print("list_1*2:",list_1,"-内存地址:",id(list_1)) -list_1.insert(0,'我是insert进来的') -print("list_1.insert():",list_1,"-内存地址:",id(list_1)) - -''' 1.2: retrieve(查) -your_list[x](通过索引取值) -your_list[start:end:step](切片,从下标start开始,到下标end结束,但不包括下标为end的元素,每隔step个元素取一次值) -your_list.index()(通过值获得下标) -''' -list_3 = lists()[0] -print("\nlist_3:",list_3) -print("your_list[x]:",list_3[len(list_3)-1]) -print("your_list[start:end:step]:",list_3[0:6:2]) -print("index:",list_3.index(2)) - -''' 1.3:update(改) -your_list[x]=xx(把下标为X的元素值改为xx) - -your_list[start:end]='xxx'(切片赋值,xxx必须是可迭代的)( ->>> a=[0,2,4,5,1] ->>> a[0:2]=['111','222','333','444'] ->>> a -['111', '222', '333', '444', 4, 5, 1] -''' -list_4 = lists()[0] -print("\nlist_4:",list_4) -list_4[0]=0 -print("your_list[x]=xx:",list_4) -list_4[0:1]='我是切片赋值' -print("your_list[start:end]:",list_4) - -''' 1.4:delete(删) -your_list.pop()(删除list中最后一个元素,并将它返回) -your_list.clear()(清空list,内存地址不会改变) -''' -list_5=lists()[0] -print("\nlist_5:",list_5) -list_5.pop() -print("your_list.pop():",list_5) -list_5.clear() -print("your_list.clear():",list_5) - -''' 1.5:sort(排序) -your_list.__reversed__()和list(reversed(your_list))(将原list倒序排序后,返回一个新的list,原list不变) -your_list.sort()(从小到大排序,必须是同种数据类型才可以进行排序) -your_list.reverse()(从大到小排序) -''' -list_6=lists()[2] -print("\nlist_6:",list_6) -print("list(reversed(your_list)):",list(reversed(list_6))) -list_7=list_6.__reversed__() -print("your_list.__reversed__():",list(list_7),"原list_6:",list_6) -list_6.sort() -print("your_list.sort():",list_6) -list_6.reverse() -print("your_list.reverse():",list_6) - -# 2:tuple的crud -#tuple不可改变 -# 2.1:create 无 - -''' 2.2:retrieve -your_tuple[x](索引取值,查询下标为X的元素的值) -your_tuple.index(value)(查询值为value的元素的下标) -your_tuple[start:end:step](切片) -''' -tuple_1=('1',2,3.0,None,False,True,bytes('4',encoding="utf-8")) -print("\ntuple_1:",tuple_1) -print("your_tuple[]:",tuple_1[0]) -print("your_tuple.index(value):",tuple_1.index(False)) -print(tuple_1[0:3:2]) - -# 2.3:update 无 - -# 2.4:delete 无 -# 实践发现没有key为True的键值对 -# 3:dict的crud -def dicts(): - dict_1={1:-1,'2':'2',3.0:3.0,None:None,True:True,False:False,bytes(4):bytes(4)} - dict_2={"test_1":"test_1"} - return dict_1,dict_2 - -''' 3.1:create -your_dict['xx']='xxx'(键值对赋值,如果已有key(xx),则将值xxx赋值给xx,如果没有就新建'xx':xxx的键值对) -your_dict_1.update(your_dict_2)(把your_dict_2合并到your_dict_1) -your_dict.setdefault(key,value)(如果当前dict没有key,则设置默认值value) -''' -dict_1=dicts()[0] -dict_2=dicts()[1] -print("\ndict_1:",dict_1) -dict_1['我是键值对赋值加进来的key']='我是键值对赋值加进来的value' -print("your_dict['xx']='xx':",dict_1) -dict_1.update(dict_2) -print("your_dict_1.update(your_dict_2):",dict_1) -dict_1.setdefault('我是your_dict.setdefault(key,value)加进来的key','我是your_dict.setdefault(key,value)加进来的value') -print("your_dict.setdefault(key,value):",dict_1) - -''' 3.2:retrieve -your_dict[key](键值对访问,通过key获取value) -your_dict.get(key,xx)(通过key获取value,若key不存在则返回xx) -your_dict.keys()(获取所有的key) -your_dict.values()(获取所有的value) -your_dict.items()(获取所有的item) -''' -dict_3=dicts()[0] -print("\nyour_dict[key]:",dict_3[1]) -print("your_dict.get(key):",dict_3.get(1)) -print("your_dict.keys():",dict_3.keys()) -print("your_dict.values():",dict_3.values()) -print("your_dict.items():",dict_3.items()) - -''' 3.3:update -your_dict[key]=new_value(通过键值对赋值改变value) -''' -dict_4=dicts()[0] -dict_4['2']='通过键值对赋值改变value' -print("\nyour_dict[key]=new_value:",dict_4) - -''' 3.4:delete -your_dict.pop(key)(删除当前元素并返回value) -your_dict.popitem()(对人类来说,相当于随机删除并返回一个item) -dict_5.clear()(清空所有元素) -''' -dict_5=dicts()[0] -dict_test_1=dict_5.pop(1) -print("\nyour_dict.pop(key):",dict_test_1,dict_5) -dict_test_2=dict_5.popitem() -print("your_dict.popitem():",dict_test_2,dict_5) -dict_5.clear() -print("your_dict.clear():",dict_5) - -# 4:set的crud -# set不存在元素True -set_1={1,2.0,'3',None,True,False,bytes(4)} -set_2={'test_1','test_2'} -'''4.1:create -your_set.add(xx)(通过add添加元素xx到集合set) -set_3=set_1.union(set_2)(将set_1和set_2合并成新的集合set_3,原1和2不变) -''' -set_1.add('我是add进来的') -print("\nyour_set.add(xx):",set_1) -set_3=set_1.union(set_2) -print("set_3=set_1.union(set_2):",set_3) - -''' 4.2:retrieve -a in your_set() -''' -set_4={1,2.0,'3',None,True,False,bytes(4)} -print("\na in set:",""'2' in set_4) - -''' 4.3:update -跟create中union同理 -''' - -''' 4.4:delete -your_set.remove(x)(删除值为X的元素,当x不存在时会报错) -your_set.discard(x)(删除值为X的元素,当x不存在时不会报错) -your_set.pop()(当成无序删除一个元素并返回此元素的值) -''' -set_5={1,2.0,'3',None,True,False,bytes(4)} -set_5.remove(1) -print("\nyour_set.remove(x):",set_5) -set_5.discard(1000) -print("your_set.discard(x):",set_5) -set_test=set_5.pop() +# 1:list的crud +# list中储存的元素是引用 +def lists(): + list_1 = ['1',2,3.0,4>5,6<7,None,bytes("8",encoding="utf-8")] + list_2 = ['9','10'] + list_3 = [0,True,False,4,1] + return list_1,list_2,list_3 + +''' 1.1: create(增) +your_list.append()(在list末尾新增) ++(通过+号拼接两个list,并返回新的list) ++=(list内存地址不变) +*(通过*n,引用n个list里的所有元素,再赋值给list) +*=(。。。) +your_list.insert()(在下标为XX的位置,插入"XX";当下标大于当前列表长度时,则插入到末尾位置) +''' +list_1=lists()[0] +list_2=lists()[1] +print("list_1:",list_1,"->内存地址:",id(list_1)) +list_1.append("我是append进来的") +print("list_1.append():",list_1,"->内存地址:",id(list_1)) +list_1 = list_1 + list_2 +print("list_1+list_2:",list_1,"->内存地址:",id(list_1)) +list_1 += list_2 +print("list_1+=list_2:",list_1,"->内存地址:",id(list_1)) +list_1 = list_1*2 +print("list_1*2:",list_1,"-内存地址:",id(list_1)) +list_1.insert(0,'我是insert进来的') +print("list_1.insert():",list_1,"-内存地址:",id(list_1)) + +''' 1.2: retrieve(查) +your_list[x](通过索引取值) +your_list[start:end:step](切片,从下标start开始,到下标end结束,但不包括下标为end的元素,每隔step个元素取一次值) +your_list.index()(通过值获得下标) +''' +list_3 = lists()[0] +print("\nlist_3:",list_3) +print("your_list[x]:",list_3[len(list_3)-1]) +print("your_list[start:end:step]:",list_3[0:6:2]) +print("index:",list_3.index(2)) + +''' 1.3:update(改) +your_list[x]=xx(把下标为X的元素值改为xx) + +your_list[start:end]='xxx'(切片赋值,xxx必须是可迭代的)( +>>> a=[0,2,4,5,1] +>>> a[0:2]=['111','222','333','444'] +>>> a +['111', '222', '333', '444', 4, 5, 1] +''' +list_4 = lists()[0] +print("\nlist_4:",list_4) +list_4[0]=0 +print("your_list[x]=xx:",list_4) +list_4[0:1]='我是切片赋值' +print("your_list[start:end]:",list_4) + +''' 1.4:delete(删) +your_list.pop()(删除list中最后一个元素,并将它返回) +your_list.clear()(清空list,内存地址不会改变) +''' +list_5=lists()[0] +print("\nlist_5:",list_5) +list_5.pop() +print("your_list.pop():",list_5) +list_5.clear() +print("your_list.clear():",list_5) + +''' 1.5:sort(排序) +your_list.__reversed__()和list(reversed(your_list))(将原list倒序排序后,返回一个新的list,原list不变) +your_list.sort()(从小到大排序,必须是同种数据类型才可以进行排序) +your_list.reverse()(从大到小排序) +''' +list_6=lists()[2] +print("\nlist_6:",list_6) +print("list(reversed(your_list)):",list(reversed(list_6))) +list_7=list_6.__reversed__() +print("your_list.__reversed__():",list(list_7),"原list_6:",list_6) +list_6.sort() +print("your_list.sort():",list_6) +list_6.reverse() +print("your_list.reverse():",list_6) + +# 2:tuple的crud +#tuple不可改变 +# 2.1:create 无 + +''' 2.2:retrieve +your_tuple[x](索引取值,查询下标为X的元素的值) +your_tuple.index(value)(查询值为value的元素的下标) +your_tuple[start:end:step](切片) +''' +tuple_1=('1',2,3.0,None,False,True,bytes('4',encoding="utf-8")) +print("\ntuple_1:",tuple_1) +print("your_tuple[]:",tuple_1[0]) +print("your_tuple.index(value):",tuple_1.index(False)) +print(tuple_1[0:3:2]) + +# 2.3:update 无 + +# 2.4:delete 无 +# 实践发现没有key为True的键值对 +# 3:dict的crud +def dicts(): + dict_1={1:-1,'2':'2',3.0:3.0,None:None,True:True,False:False,bytes(4):bytes(4)} + dict_2={"test_1":"test_1"} + return dict_1,dict_2 + +''' 3.1:create +your_dict['xx']='xxx'(键值对赋值,如果已有key(xx),则将值xxx赋值给xx,如果没有就新建'xx':xxx的键值对) +your_dict_1.update(your_dict_2)(把your_dict_2合并到your_dict_1) +your_dict.setdefault(key,value)(如果当前dict没有key,则设置默认值value) +''' +dict_1=dicts()[0] +dict_2=dicts()[1] +print("\ndict_1:",dict_1) +dict_1['我是键值对赋值加进来的key']='我是键值对赋值加进来的value' +print("your_dict['xx']='xx':",dict_1) +dict_1.update(dict_2) +print("your_dict_1.update(your_dict_2):",dict_1) +dict_1.setdefault('我是your_dict.setdefault(key,value)加进来的key','我是your_dict.setdefault(key,value)加进来的value') +print("your_dict.setdefault(key,value):",dict_1) + +''' 3.2:retrieve +your_dict[key](键值对访问,通过key获取value) +your_dict.get(key,xx)(通过key获取value,若key不存在则返回xx) +your_dict.keys()(获取所有的key) +your_dict.values()(获取所有的value) +your_dict.items()(获取所有的item) +''' +dict_3=dicts()[0] +print("\nyour_dict[key]:",dict_3[1]) +print("your_dict.get(key):",dict_3.get(1)) +print("your_dict.keys():",dict_3.keys()) +print("your_dict.values():",dict_3.values()) +print("your_dict.items():",dict_3.items()) + +''' 3.3:update +your_dict[key]=new_value(通过键值对赋值改变value) +''' +dict_4=dicts()[0] +dict_4['2']='通过键值对赋值改变value' +print("\nyour_dict[key]=new_value:",dict_4) + +''' 3.4:delete +your_dict.pop(key)(删除当前元素并返回value) +your_dict.popitem()(对人类来说,相当于随机删除并返回一个item) +dict_5.clear()(清空所有元素) +''' +dict_5=dicts()[0] +dict_test_1=dict_5.pop(1) +print("\nyour_dict.pop(key):",dict_test_1,dict_5) +dict_test_2=dict_5.popitem() +print("your_dict.popitem():",dict_test_2,dict_5) +dict_5.clear() +print("your_dict.clear():",dict_5) + +# 4:set的crud +# set不存在元素True +set_1={1,2.0,'3',None,True,False,bytes(4)} +set_2={'test_1','test_2'} +'''4.1:create +your_set.add(xx)(通过add添加元素xx到集合set) +set_3=set_1.union(set_2)(将set_1和set_2合并成新的集合set_3,原1和2不变) +''' +set_1.add('我是add进来的') +print("\nyour_set.add(xx):",set_1) +set_3=set_1.union(set_2) +print("set_3=set_1.union(set_2):",set_3) + +''' 4.2:retrieve +a in your_set() +''' +set_4={1,2.0,'3',None,True,False,bytes(4)} +print("\na in set:",""'2' in set_4) + +''' 4.3:update +跟create中union同理 +''' + +''' 4.4:delete +your_set.remove(x)(删除值为X的元素,当x不存在时会报错) +your_set.discard(x)(删除值为X的元素,当x不存在时不会报错) +your_set.pop()(当成无序删除一个元素并返回此元素的值) +''' +set_5={1,2.0,'3',None,True,False,bytes(4)} +set_5.remove(1) +print("\nyour_set.remove(x):",set_5) +set_5.discard(1000) +print("your_set.discard(x):",set_5) +set_test=set_5.pop() print("your_set.pop():",set_test,set_5) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\345\255\227\347\254\246\344\270\262\346\223\215\344\275\234\345\222\214\346\226\207\344\273\266\350\257\273\345\206\231.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\345\255\227\347\254\246\344\270\262\346\223\215\344\275\234\345\222\214\346\226\207\344\273\266\350\257\273\345\206\231.py" index 1bd7ca81e0b7161e5c2b240fdc737cac24fb484a..d3a14d9de247c34a863aac32f8dcfbc729db3556 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\345\255\227\347\254\246\344\270\262\346\223\215\344\275\234\345\222\214\346\226\207\344\273\266\350\257\273\345\206\231.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\214\345\221\250/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\345\255\227\347\254\246\344\270\262\346\223\215\344\275\234\345\222\214\346\226\207\344\273\266\350\257\273\345\206\231.py" @@ -1,136 +1,136 @@ -content = ''' - -1.字符串的编码与解码 - ->>> a = '你好'.encode("utf-8") + '你也好'.encode("gbk") ->>> a -b'\xe4\xbd\xa0\xe5\xa5\xbd\xc4\xe3\xd2\xb2\xba\xc3' ->>> a.decode("utf-8",errors='ignore') -'你好Ҳ' ->>> a.decode("utf-8",errors='replace') -'你好��Ҳ��' - -2.字符串的crud - -2.1:create(增) ->>> a='qwer去玩儿' ->>> a=a+'?' ->>> a -'qwer去玩儿?' ->>> a += a ->>> a -'qwer去玩儿?qwer去玩儿?' - -2.2:retrieve(查) ->>> a='12345' ->>> a.index('1') -0 ->>> a[2] -'3' ->>> a='122334456' ->>> a.index('1') -0 ->>> a[2] -'2' ->>> a.find('2') -1 ->>> a.startswith('12') -True ->>> a.endswith('56') -True - -2.3:update(改) ->>> a="2009,2010,2020" ->>> a.split(",") -['2009', '2010', '2020'] ->>> b=a.split(",") ->>> b -['2009', '2010', '2020'] ->>> c=",".join(b) ->>> c -'2009,2010,2020' ->>> a -'2009,2010,2020' ->>> a.replace(",","年,") -'2009年,2010年,2020' - -2.4:delete(删) ->>> a = ' 来 吧 。 ' ->>> a.strip() -'来 吧 。' ->>> a.lstrip() -'来 吧 。 ' ->>> a.rstrip() -' 来 吧 。' ->>> - -3.字符串的格式化输出 - ->>> a = '没bug,下早班' ->>> b = '有bug,要加班' - -3.1: 按传入参数默认顺序 ->>> "我:{},领导:{}".format(a,b) -'我:没bug,下早班,领导:有bug,要加班' - -3.2:按关键字参数 ->>> "我:{a},领导:{b}".format(a='不加班!',b='要加班!') -'我:不加班!,领导:要加班!' - -3.3:按指定参数的索引 ->>> "我:{1},领导:{0}".format(a,b) -'我:有bug,要加班,领导:没bug,下早班' - -3.4:按变量(注意f)(3.6以上版本才有) ->>> f"我:{a},领导:{b}" -'我:没bug,下早班,领导:有bug,要加班' - -3.5:老式格式化输出 ->>> "我:%s, 领导:%s" % ("没bug,下早班","有bug,要加班") -'我:没bug,下早班, 领导:有bug,要加班' - -3.6:小数的表示 n:小数点后n位,f:float {:.nf} ->>> "{:.2f}".format(3.000000000) -'3.00' - -4:文件的读写 - -4.1:write(写入文件)(覆盖写入,即文件原有内容会被现在写入的内容所替换) -文件路径,读写方式(写入),编码格式 -用content储存需要写入的内容 -正式写入文件 -关闭句柄(一定要关闭) ->>> output = open("test.md","w",encoding="utf-8") ->>> content = "把我写入文件中吧" ->>> output.write(content) -8 ->>> output.close() - -4.2:read(读取文件) -文件路径,读写方式(读取),编码格式 -用content储存从文件中读取到的内容 -关闭句柄 ->>> input=open("test.md","r",encoding="utf-8") ->>> print(input) -<_io.TextIOWrapper name='test.md' mode='r' encoding='utf-8'> ->>> content=input.read() ->>> print(content) -把我写入文件中吧 ->>> input.close() ->>> - -4.3:追加写入 -文件路径,读写方式(追加写入),编码格式 -用content储存需要追加写入的内容 -正式写入文件 -关闭句柄 ->>> output=open("test.md","a",encoding="utf-8") ->>> content="\n把我也写入吧" ->>> output.write(content) -7 ->>> output.close() - -''' -output = open("test.md","w",encoding="utf-8") -output.write(content) -output.close() +content = ''' + +1.字符串的编码与解码 + +>>> a = '你好'.encode("utf-8") + '你也好'.encode("gbk") +>>> a +b'\xe4\xbd\xa0\xe5\xa5\xbd\xc4\xe3\xd2\xb2\xba\xc3' +>>> a.decode("utf-8",errors='ignore') +'你好Ҳ' +>>> a.decode("utf-8",errors='replace') +'你好��Ҳ��' + +2.字符串的crud + +2.1:create(增) +>>> a='qwer去玩儿' +>>> a=a+'?' +>>> a +'qwer去玩儿?' +>>> a += a +>>> a +'qwer去玩儿?qwer去玩儿?' + +2.2:retrieve(查) +>>> a='12345' +>>> a.index('1') +0 +>>> a[2] +'3' +>>> a='122334456' +>>> a.index('1') +0 +>>> a[2] +'2' +>>> a.find('2') +1 +>>> a.startswith('12') +True +>>> a.endswith('56') +True + +2.3:update(改) +>>> a="2009,2010,2020" +>>> a.split(",") +['2009', '2010', '2020'] +>>> b=a.split(",") +>>> b +['2009', '2010', '2020'] +>>> c=",".join(b) +>>> c +'2009,2010,2020' +>>> a +'2009,2010,2020' +>>> a.replace(",","年,") +'2009年,2010年,2020' + +2.4:delete(删) +>>> a = ' 来 吧 。 ' +>>> a.strip() +'来 吧 。' +>>> a.lstrip() +'来 吧 。 ' +>>> a.rstrip() +' 来 吧 。' +>>> + +3.字符串的格式化输出 + +>>> a = '没bug,下早班' +>>> b = '有bug,要加班' + +3.1: 按传入参数默认顺序 +>>> "我:{},领导:{}".format(a,b) +'我:没bug,下早班,领导:有bug,要加班' + +3.2:按关键字参数 +>>> "我:{a},领导:{b}".format(a='不加班!',b='要加班!') +'我:不加班!,领导:要加班!' + +3.3:按指定参数的索引 +>>> "我:{1},领导:{0}".format(a,b) +'我:有bug,要加班,领导:没bug,下早班' + +3.4:按变量(注意f)(3.6以上版本才有) +>>> f"我:{a},领导:{b}" +'我:没bug,下早班,领导:有bug,要加班' + +3.5:老式格式化输出 +>>> "我:%s, 领导:%s" % ("没bug,下早班","有bug,要加班") +'我:没bug,下早班, 领导:有bug,要加班' + +3.6:小数的表示 n:小数点后n位,f:float {:.nf} +>>> "{:.2f}".format(3.000000000) +'3.00' + +4:文件的读写 + +4.1:write(写入文件)(覆盖写入,即文件原有内容会被现在写入的内容所替换) +文件路径,读写方式(写入),编码格式 +用content储存需要写入的内容 +正式写入文件 +关闭句柄(一定要关闭) +>>> output = open("test.md","w",encoding="utf-8") +>>> content = "把我写入文件中吧" +>>> output.write(content) +8 +>>> output.close() + +4.2:read(读取文件) +文件路径,读写方式(读取),编码格式 +用content储存从文件中读取到的内容 +关闭句柄 +>>> input=open("test.md","r",encoding="utf-8") +>>> print(input) +<_io.TextIOWrapper name='test.md' mode='r' encoding='utf-8'> +>>> content=input.read() +>>> print(content) +把我写入文件中吧 +>>> input.close() +>>> + +4.3:追加写入 +文件路径,读写方式(追加写入),编码格式 +用content储存需要追加写入的内容 +正式写入文件 +关闭句柄 +>>> output=open("test.md","a",encoding="utf-8") +>>> content="\n把我也写入吧" +>>> output.write(content) +7 +>>> output.close() + +''' +output = open("test.md","w",encoding="utf-8") +output.write(content) +output.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202.py" index 57d431c5d2c9596a67751a775bf579c3e75262e4..59c2d3da547e7a3f4a4b7fad9febdb48b9281300 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202.py" @@ -1,30 +1,30 @@ -import requests -from threading import Thread -from multiprocessing import Process - -def request_baidu(index): - url = 'https://www.baidu.com/' - headers = { - 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36' - } - result = requests.get(url=url,headers=headers) - print(result.status_code) - return result -if __name__ == "__main__": - thread_arr = [] - for i in range(10): - t = Thread(target=request_baidu, args=(i, )) - thread_arr.append(t) - t.start() - for i in thread_arr: - i.join() - print('--------------------多线程:ok!--------------------') - - process_arr = [] - for i in range(10): - p = Process(target=request_baidu, args=(i, )) - process_arr.append(p) - p.start() - for i in process_arr: - i.join() - print('--------------------多进程:ok!--------------------') +import requests +from threading import Thread +from multiprocessing import Process + +def request_baidu(index): + url = 'https://www.baidu.com/' + headers = { + 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36' + } + result = requests.get(url=url,headers=headers) + print(result.status_code) + return result +if __name__ == "__main__": + thread_arr = [] + for i in range(10): + t = Thread(target=request_baidu, args=(i, )) + thread_arr.append(t) + t.start() + for i in thread_arr: + i.join() + print('--------------------多线程:ok!--------------------') + + process_arr = [] + for i in range(10): + p = Process(target=request_baidu, args=(i, )) + process_arr.append(p) + p.start() + for i in process_arr: + i.join() + print('--------------------多进程:ok!--------------------') diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202.py" index 9e36d5bb8ec4abe95b9b37463d48dde72da47107..800bcbc576c2e483aa87a16120575eaa70ba4f6d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202.py" @@ -1,123 +1,123 @@ -import asyncio,time - -#yield翻译为让渡,可以简单理解为暂停,并返回值 -''' -列表:一次返回所有的元素,占用内存大 -list(range(10)) -什么是迭代器:一次可以只返回一个元素,占用很小的内存,读取大文件和数据集合时非常有用 -iter(range(1)) -迭代器可以用来表示数据流,提供惰性返回功能(即只有主动使用next方法调用一次迭代器,他才会返回一个数据) -当调用次数大于迭代器长度时,会报StopIteration错 -''' -l_1=list(range(10)) -# print(l_1) -i_1=iter(range(10)) -# print(next(i_1)) - -''' -什么是生成器:生成器是一种特殊的迭代器,但他在迭代器惰性返回数据的基础上,提供了额外的功能,比如可以计算 -yield 'sss',i -只要函数中有关键字yield,他就是生成器 -''' -def a(n): - for i in range(n): - print('i:',i) - yield 'sss',i -res = a(10) -# print('res:',next(res)) -# print('res:',next(res)) -# print('res:',next(res)) - -''' -迭代器和生成器的区别:迭代器侧重于对数据的惰性返回功能,生成器侧重于对指令的惰性返回功能 -生成器指令:yield 'sss',i -''' - -''' -协程的实现原理:跟生成器原理一样,但是在生成器的基础上增加了传递值的功能 -''' -def b(a): - print('a:',a) - # 按照一般理解,此处的b值应为a,即是b=2 - # 但是作为协程,此处的b值是语句aa.send(3)中传递过来的值3,即b=3 - b = yield a - print('b:',b) - c = yield b - print('c:',c) - d = yield c -aa = b(2) -# 想要调用send方法,必须先调用next方法预激活生成器,使它停留在第一个yield的位置 -# next(aa) -# aa.send(3) -# 实际上,print语句打印的是一个返回值,d -# print(aa.send(3)) - -''' -用协程实现一个计算平均数的函数 -''' -def average_1(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -average_2 = average_1() -# print(next(average_2)) -# print(average_2.send(5)) -# print(average_2.send(4)) - -''' -asyncio实现原理:自动维护一个事件队列,然后不断循环访问事件来完成异步的消息维护 -替换yield from实现协程异步io,更好地实现异步程序 -''' - -# (不使用anyscio)模拟网络请求百度,返回的状态码是404 -'''def statu_code(): - return 404 -def request_baidu(index): - print(f'模拟请求index:{index}') - res = statu_code() - print(f'状态码是:{res}') - # 模拟网络延迟1s,由于当前线程是单线程,time.sleep(1)会阻塞线程1s - time.sleep(1) -for i in range(10): - request_baidu(i) -''' - -# (使用anyscio)模拟网络请求百度,返回的状态码是404 -def statu_code(): - return 404 - -async def request_baidu(index): - res = statu_code() - print(f'模拟请求index:{index}') - # 模拟网络延迟1s,由于当前线程是单线程,time.sleep(1)会阻塞线程1s - # time.sleep(1) - print('-------------------------') - # 先全部执行完上面代码 - await asyncio.sleep(1) - # 1s后全部返回结果 - print('-------------------------') - print(f'请求{index}状态码是:{res}') - return res - -# 获取事件队列 -loop = asyncio.get_event_loop() - -# 将request_baidu包装成任务 -task_arr = [] - -# 往任务里添加事件 -for i in range(100): - task_arr.append(request_baidu(i)) - -# 循环访问任务 -loop.run_until_complete(asyncio.wait(task_arr)) - -# 关闭事件 +import asyncio,time + +#yield翻译为让渡,可以简单理解为暂停,并返回值 +''' +列表:一次返回所有的元素,占用内存大 +list(range(10)) +什么是迭代器:一次可以只返回一个元素,占用很小的内存,读取大文件和数据集合时非常有用 +iter(range(1)) +迭代器可以用来表示数据流,提供惰性返回功能(即只有主动使用next方法调用一次迭代器,他才会返回一个数据) +当调用次数大于迭代器长度时,会报StopIteration错 +''' +l_1=list(range(10)) +# print(l_1) +i_1=iter(range(10)) +# print(next(i_1)) + +''' +什么是生成器:生成器是一种特殊的迭代器,但他在迭代器惰性返回数据的基础上,提供了额外的功能,比如可以计算 +yield 'sss',i +只要函数中有关键字yield,他就是生成器 +''' +def a(n): + for i in range(n): + print('i:',i) + yield 'sss',i +res = a(10) +# print('res:',next(res)) +# print('res:',next(res)) +# print('res:',next(res)) + +''' +迭代器和生成器的区别:迭代器侧重于对数据的惰性返回功能,生成器侧重于对指令的惰性返回功能 +生成器指令:yield 'sss',i +''' + +''' +协程的实现原理:跟生成器原理一样,但是在生成器的基础上增加了传递值的功能 +''' +def b(a): + print('a:',a) + # 按照一般理解,此处的b值应为a,即是b=2 + # 但是作为协程,此处的b值是语句aa.send(3)中传递过来的值3,即b=3 + b = yield a + print('b:',b) + c = yield b + print('c:',c) + d = yield c +aa = b(2) +# 想要调用send方法,必须先调用next方法预激活生成器,使它停留在第一个yield的位置 +# next(aa) +# aa.send(3) +# 实际上,print语句打印的是一个返回值,d +# print(aa.send(3)) + +''' +用协程实现一个计算平均数的函数 +''' +def average_1(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +average_2 = average_1() +# print(next(average_2)) +# print(average_2.send(5)) +# print(average_2.send(4)) + +''' +asyncio实现原理:自动维护一个事件队列,然后不断循环访问事件来完成异步的消息维护 +替换yield from实现协程异步io,更好地实现异步程序 +''' + +# (不使用anyscio)模拟网络请求百度,返回的状态码是404 +'''def statu_code(): + return 404 +def request_baidu(index): + print(f'模拟请求index:{index}') + res = statu_code() + print(f'状态码是:{res}') + # 模拟网络延迟1s,由于当前线程是单线程,time.sleep(1)会阻塞线程1s + time.sleep(1) +for i in range(10): + request_baidu(i) +''' + +# (使用anyscio)模拟网络请求百度,返回的状态码是404 +def statu_code(): + return 404 + +async def request_baidu(index): + res = statu_code() + print(f'模拟请求index:{index}') + # 模拟网络延迟1s,由于当前线程是单线程,time.sleep(1)会阻塞线程1s + # time.sleep(1) + print('-------------------------') + # 先全部执行完上面代码 + await asyncio.sleep(1) + # 1s后全部返回结果 + print('-------------------------') + print(f'请求{index}状态码是:{res}') + return res + +# 获取事件队列 +loop = asyncio.get_event_loop() + +# 将request_baidu包装成任务 +task_arr = [] + +# 往任务里添加事件 +for i in range(100): + task_arr.append(request_baidu(i)) + +# 循环访问任务 +loop.run_until_complete(asyncio.wait(task_arr)) + +# 关闭事件 loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202.py" index 86cede5999e79152add6ecadb082a1eb01cd9f52..d28644a41665f4284a3e95fd5a0cbee82a6eb012 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\344\272\224\345\221\250/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202.py" @@ -1,68 +1,68 @@ -from multiprocessing import Process,Lock,Queue -from threading import Thread - -'''进程间通信(IPC)-跟系统内核关联大 -文件:通过访问文件进行多进程通信,可能会出现读写冲突,加互斥锁解决my_lock = Lock() -套接字(sokect):通过一个协议,连接两个进程,主要通过网络请求。比如进程1上传文件到云盘,进程2从云盘下载文件 -管道:用文件的内存缓冲区作为管道,实现进程间通信。匿名管道:主进程和子进程进行交互,具名管道:不同进程可以进行交互 -消息队列(queue):一个存在内核内存空间中的列表,,redis就是消息队列+socket -共享内存(了解):进程访问内核态同一块内存 -信号量(了解):不是用来传递数据的, 是用来传递消息,进程B要等到进程A执行到某一步操作后, 才会启动,进程A->发消息->内核->转发信息->进程B -''' -#文件 -def process_save_to_file(index,my_lock): - with my_lock: - with open('5.2.log','a',encoding='utf-8') as f: - f.write(f'\"{str(index)}\":{index},\n') - -#消息队列 -def process_save_to_queue(index,my_queue): - my_queue.put(index) - - -'''线程间通信--进程可以进行的通信,线程都可以完成。线程间通信强调的是线程之间传递对象引用 -共享变量:线程安全问题:线程有GIL锁, 但是拿到GIL锁不代表可以一直执行下去.现代计算机多线程也是A执行一会儿, B执行一会儿这样交替执行. -解决线程安全:将重要指令包装成原子操作(不可分割的),如加互斥锁lock = Lock() -''' - -#进行大量运算,以便让线程间互相争夺锁 -a = 0 -thread_lock = Lock() -def thread_shared_variables(): - global a - for i in range(10**6): - #如果不加锁,最后输出的a可能不等于0 - with thread_lock: - a += 1 - a -= 1 - -if __name__ == '__main__': - #进程Process改成线程Thread即可进行线程间的通信 - for i in range(10): - my_lock = Lock() - p = Process(target=process_save_to_file,args=(i,my_lock)) - p.start() - p.join() - print('---process_save_to_file is ok---') - - #进程Process改成线程Thread即可进行线程间的通信 - my_queue = Queue() - process_queue_arr = [] - for i in range(10): - p = Process(target=process_save_to_queue,args=(i,my_queue)) - process_queue_arr.append(p) - p.start() - p.join() - for i in process_queue_arr: - print(my_queue.get(),':',i) - print('---process_save_to_queue is ok---') - - thread_arr = [] - for i in range(3): - t = Thread(target=thread_shared_variables) - thread_arr.append(t) - t.start() - for i in thread_arr: - t.join() - print(a) +from multiprocessing import Process,Lock,Queue +from threading import Thread + +'''进程间通信(IPC)-跟系统内核关联大 +文件:通过访问文件进行多进程通信,可能会出现读写冲突,加互斥锁解决my_lock = Lock() +套接字(sokect):通过一个协议,连接两个进程,主要通过网络请求。比如进程1上传文件到云盘,进程2从云盘下载文件 +管道:用文件的内存缓冲区作为管道,实现进程间通信。匿名管道:主进程和子进程进行交互,具名管道:不同进程可以进行交互 +消息队列(queue):一个存在内核内存空间中的列表,,redis就是消息队列+socket +共享内存(了解):进程访问内核态同一块内存 +信号量(了解):不是用来传递数据的, 是用来传递消息,进程B要等到进程A执行到某一步操作后, 才会启动,进程A->发消息->内核->转发信息->进程B +''' +#文件 +def process_save_to_file(index,my_lock): + with my_lock: + with open('5.2.log','a',encoding='utf-8') as f: + f.write(f'\"{str(index)}\":{index},\n') + +#消息队列 +def process_save_to_queue(index,my_queue): + my_queue.put(index) + + +'''线程间通信--进程可以进行的通信,线程都可以完成。线程间通信强调的是线程之间传递对象引用 +共享变量:线程安全问题:线程有GIL锁, 但是拿到GIL锁不代表可以一直执行下去.现代计算机多线程也是A执行一会儿, B执行一会儿这样交替执行. +解决线程安全:将重要指令包装成原子操作(不可分割的),如加互斥锁lock = Lock() +''' + +#进行大量运算,以便让线程间互相争夺锁 +a = 0 +thread_lock = Lock() +def thread_shared_variables(): + global a + for i in range(10**6): + #如果不加锁,最后输出的a可能不等于0 + with thread_lock: + a += 1 + a -= 1 + +if __name__ == '__main__': + #进程Process改成线程Thread即可进行线程间的通信 + for i in range(10): + my_lock = Lock() + p = Process(target=process_save_to_file,args=(i,my_lock)) + p.start() + p.join() + print('---process_save_to_file is ok---') + + #进程Process改成线程Thread即可进行线程间的通信 + my_queue = Queue() + process_queue_arr = [] + for i in range(10): + p = Process(target=process_save_to_queue,args=(i,my_queue)) + process_queue_arr.append(p) + p.start() + p.join() + for i in process_queue_arr: + print(my_queue.get(),':',i) + print('---process_save_to_queue is ok---') + + thread_arr = [] + for i in range(3): + t = Thread(target=thread_shared_variables) + thread_arr.append(t) + t.start() + for i in thread_arr: + t.join() + print(a) print('---thread_shared_variables is ok---') \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\347\272\246\346\235\237\345\217\212\345\210\206\347\273\204.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\347\272\246\346\235\237\345\217\212\345\210\206\347\273\204.md" index 4cae7a26bd9a89fbe1787c80b690fb19b38a79e6..d1787a448078ab2ac900b0690fd6e41e757a54de 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\347\272\246\346\235\237\345\217\212\345\210\206\347\273\204.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202-\347\272\246\346\235\237\345\217\212\345\210\206\347\273\204.md" @@ -1,63 +1,63 @@ -1:简单使用Mysql约束, 并举例说明使用场景 - -``` -1:主键约束 primary key: -在关系表中作为记录的唯一标识使用,不可以为null,不可以重复 -create table test_1( - test_id int primary key auto_increment - ); -使用场景:在一张学生信息表中,通常学号是主键 - -2:非空约束 not null: -空白字符也是not null(select '' is null,返回值0) -有操作就会有记录。我们希望当表被操作时,不管结果如何,他都会有个值,即使值被人为设定为 '' -create table test_1( - test_id int primary key auto_increment, - test_name varchar(10) NOT NULL - ); -使用场景:交班费,某些同学已经交过,某些同学还没有交,就可以用not null区分这些同学 - -3:唯一约束 unique: -null值是可以重复的 -不可以向表中插入已经存在的值,可以使用唯一约束 -create table test_1( - test_id int primary key auto_increment, - test_name varchar(10) NOT NULL UNIQUE - ); -使用场景:在有些游戏中,玩家名是被设置为不可以重复的 - -4:外键约束 foreign key: -外键作用:保持数据的一致性和完整性,通过外键表达主表和从表的关系,避免冗余字段 -现在已经不推荐使用外键: - 性能问题:插数据需要验证 - 并发问题:高并发事务场景下,使用外键容易造成死锁 - 扩展问题:外键相当于把对象之间的关系交给数据库来维护,如果遇到分库分表,外键是不生效的。做数据迁移时,触发器,存储过程和外键都很难迁移,增加了维护成本 - 维护成本:需要有专业DBA来维护庞大的数据库关系 - -5:默认约束 default: -默认会填充当前字段 -create table test_1( - test_id int primary key auto_increment, - test_name varchar(10) NOT NULL UNIQUE, - test_create_time TIMESTAMP - ); -使用场景:用来记录某个数据被操作时的时间点 -``` - -2:练习使用分组查询 - -​ 图片测试 - -![第八周-第一节-grade表](.\images\第八周-第一节-grade表.png) - -![第八周-第一节-grade表](C:\Users\孤傲冷青双\Desktop\第八周-第一节-grade表.png) - -use test; -select count(*) as 班级人数, -AVG(total) as 班级总分平均分, -SUM(chinese) as 语文总分, -MAX(math) as 数学最高, -MIN(english) as 英语最低分, -gender as 性别 -from grade GROUP BY gender;![第八周-第一节-分组操作运行结果](C:\Users\孤傲冷青双\Desktop\第八周-第一节-分组操作运行结果.png) - +1:简单使用Mysql约束, 并举例说明使用场景 + +``` +1:主键约束 primary key: +在关系表中作为记录的唯一标识使用,不可以为null,不可以重复 +create table test_1( + test_id int primary key auto_increment + ); +使用场景:在一张学生信息表中,通常学号是主键 + +2:非空约束 not null: +空白字符也是not null(select '' is null,返回值0) +有操作就会有记录。我们希望当表被操作时,不管结果如何,他都会有个值,即使值被人为设定为 '' +create table test_1( + test_id int primary key auto_increment, + test_name varchar(10) NOT NULL + ); +使用场景:交班费,某些同学已经交过,某些同学还没有交,就可以用not null区分这些同学 + +3:唯一约束 unique: +null值是可以重复的 +不可以向表中插入已经存在的值,可以使用唯一约束 +create table test_1( + test_id int primary key auto_increment, + test_name varchar(10) NOT NULL UNIQUE + ); +使用场景:在有些游戏中,玩家名是被设置为不可以重复的 + +4:外键约束 foreign key: +外键作用:保持数据的一致性和完整性,通过外键表达主表和从表的关系,避免冗余字段 +现在已经不推荐使用外键: + 性能问题:插数据需要验证 + 并发问题:高并发事务场景下,使用外键容易造成死锁 + 扩展问题:外键相当于把对象之间的关系交给数据库来维护,如果遇到分库分表,外键是不生效的。做数据迁移时,触发器,存储过程和外键都很难迁移,增加了维护成本 + 维护成本:需要有专业DBA来维护庞大的数据库关系 + +5:默认约束 default: +默认会填充当前字段 +create table test_1( + test_id int primary key auto_increment, + test_name varchar(10) NOT NULL UNIQUE, + test_create_time TIMESTAMP + ); +使用场景:用来记录某个数据被操作时的时间点 +``` + +2:练习使用分组查询 + +​ 图片测试 + +![第八周-第一节-grade表](.\images\第八周-第一节-grade表.png) + +![第八周-第一节-grade表](C:\Users\孤傲冷青双\Desktop\第八周-第一节-grade表.png) + +use test; +select count(*) as 班级人数, +AVG(total) as 班级总分平均分, +SUM(chinese) as 语文总分, +MAX(math) as 数学最高, +MIN(english) as 英语最低分, +gender as 性别 +from grade GROUP BY gender;![第八周-第一节-分组操作运行结果](C:\Users\孤傲冷青双\Desktop\第八周-第一节-分组操作运行结果.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.md" index 9004df4e57a626f4936f006e76ed45c2eb865a78..faea32c1a97cce180797b35d44fae03348df9abd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.md" @@ -1,58 +1,58 @@ -索引 - -**实现原理:B-tree** - -``` -未创建索引时查询时长: -select * from grade where name = '同学9999' 0.865s -``` - -``` -创建索引后查询时长: -create index name_index on grade(name); -select * from grade where name = '同学9999'; 0.028s -``` - -``` -创建联合索引: -create index name_gender_index on grade (name,gender) -``` - -``` -查看索引: -show index from grade -``` - -``` -删除索引: -ALTER table grade drop index name_index -``` - -``` -查看当前查询语句有没有命中索引: -EXPLAIN select * from grade where name = '同学9999' - -单个字段可以命中联合索引,但有条件,必须符合左缀查询 -如果想命中索引,查询语句中涉及到的字段必须是联合索引创建时从左到右的顺序 -原理:在a_b_c_index 这样一个联合索引中,实际执行是先查出a的结果集合,再查b或c的结果集合 -EXPLAIN select * from grade where gender = 0 and name = '同学9999' 命中 -EXPLAIN select * from grade where gender = 0 无命中 -EXPLAIN select * from grade where name = '同学9999' 命中 -``` - -``` -MySQL优化 -1:合理建立索引 - 频繁作为查询条件的字段应该建立索引 - 唯一性差的字段不适合单独建立索引 - 更新频繁的字段不适合建立索引 - 避免不经过索引的操作如: - not in,!= 等等反向逻辑 - between 范围查找 - or逻辑两边都必须命中索引才会走索引查找 - 联合索引,不按左缀查询规则 -2:加缓存 - 数据库缓存 show VARIABLES LIKE '%query_cache%' - 用Redis做缓存 请求-Redis-未命中-MySQL-返回 -3:加固态 +索引 + +**实现原理:B-tree** + +``` +未创建索引时查询时长: +select * from grade where name = '同学9999' 0.865s +``` + +``` +创建索引后查询时长: +create index name_index on grade(name); +select * from grade where name = '同学9999'; 0.028s +``` + +``` +创建联合索引: +create index name_gender_index on grade (name,gender) +``` + +``` +查看索引: +show index from grade +``` + +``` +删除索引: +ALTER table grade drop index name_index +``` + +``` +查看当前查询语句有没有命中索引: +EXPLAIN select * from grade where name = '同学9999' + +单个字段可以命中联合索引,但有条件,必须符合左缀查询 +如果想命中索引,查询语句中涉及到的字段必须是联合索引创建时从左到右的顺序 +原理:在a_b_c_index 这样一个联合索引中,实际执行是先查出a的结果集合,再查b或c的结果集合 +EXPLAIN select * from grade where gender = 0 and name = '同学9999' 命中 +EXPLAIN select * from grade where gender = 0 无命中 +EXPLAIN select * from grade where name = '同学9999' 命中 +``` + +``` +MySQL优化 +1:合理建立索引 + 频繁作为查询条件的字段应该建立索引 + 唯一性差的字段不适合单独建立索引 + 更新频繁的字段不适合建立索引 + 避免不经过索引的操作如: + not in,!= 等等反向逻辑 + between 范围查找 + or逻辑两边都必须命中索引才会走索引查找 + 联合索引,不按左缀查询规则 +2:加缓存 + 数据库缓存 show VARIABLES LIKE '%query_cache%' + 用Redis做缓存 请求-Redis-未命中-MySQL-返回 +3:加固态 ``` \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.py" index 1af23f5098d55f16fd624b769da45eaaf14fb2c9..99125dfbda89ba01e6e4dd0282cdb46007d38a19 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202-pymsql\343\200\201\347\264\242\345\274\225\343\200\201\344\272\213\345\212\241.py" @@ -1,80 +1,80 @@ -import pymysql -import datetime -import random -import time - -#创建一个类用于存储连接MySQL的一些数据 -MYSQL_CONF = { - "host" : "localhost", - "user" : "root", - "password" : 'yz1255', - "db" : "test" -} - -#时间装饰器用于计时 -def time_deco(func): - def wrapper(*args,**kwargs): - start=time.time() - res=func(*args,**kwargs) - end=time.time() - print(f"{func.__name__}函数运行耗时为:{format(end-start,'.2f')}s") - return res - return wrapper - -#连接数据库 -mysql_con = pymysql.connect(**MYSQL_CONF) -#简单理解为真正执行语句的线程 -mysql_cursor = mysql_con.cursor() - -#单条执行,用时较多,适合用于debug -@time_deco -#insert_into_one函数运行耗时为:12.94s -def insert_into_one(): - #sid,name,chinese,math,english,total,gender,create_date - for i in range(10**4): - name = f"同学{i}" - chinese = float(format(random.uniform(0,100),'.1f')) - math = float(format(random.uniform(0,100),'.1f')) - english = float(format(random.uniform(0,100),'.1f')) - total = float(format((chinese + math + english),'.1f')) - #性别男为1,女为0 - gender = random.randint(0, 1) - - sql = f"insert into grade (name,chinese,math,english,total,gender) values ('{name}',{chinese},{math},{english},{total},{gender})" - #print(sql) - mysql_cursor.execute(sql) - mysql_con.commit() - -#多条执行,用时较少,对插入数据速度有要求时使用,但是如果执行过程有一处失败,则整个插入操作失败 -@time_deco -#insert_into_many函数运行耗时为:0.28s -def insert_into_many(): - values = [] - for i in range(10**4): - name = f"同学{i}" - chinese = float(format(random.uniform(0,100),'.1f')) - math = float(format(random.uniform(0,100),'.1f')) - english = float(format(random.uniform(0,100),'.1f')) - total = float(format((chinese + math + english),'.1f')) - #性别男为1,女为0 - gender = random.randint(0, 1) - - #将所有值包装成元组添加到values - values.append((name,chinese,math,english,total,gender)) - - sql = """insert into grade (name,chinese,math,english,total,gender) values (%s,%s,%s,%s,%s,%s)""" - #print(values) - mysql_cursor.executemany(sql,values) - mysql_con.commit() - -#查询语句 -def get_students(): - sql = "select * from grade where sid = 1" - mysql_cursor.execute(sql) - query_set = mysql_cursor.fetchall() - print(query_set) - -if __name__ == "__main__": - #insert_into_one() - #insert_into_many() +import pymysql +import datetime +import random +import time + +#创建一个类用于存储连接MySQL的一些数据 +MYSQL_CONF = { + "host" : "localhost", + "user" : "root", + "password" : 'yz1255', + "db" : "test" +} + +#时间装饰器用于计时 +def time_deco(func): + def wrapper(*args,**kwargs): + start=time.time() + res=func(*args,**kwargs) + end=time.time() + print(f"{func.__name__}函数运行耗时为:{format(end-start,'.2f')}s") + return res + return wrapper + +#连接数据库 +mysql_con = pymysql.connect(**MYSQL_CONF) +#简单理解为真正执行语句的线程 +mysql_cursor = mysql_con.cursor() + +#单条执行,用时较多,适合用于debug +@time_deco +#insert_into_one函数运行耗时为:12.94s +def insert_into_one(): + #sid,name,chinese,math,english,total,gender,create_date + for i in range(10**4): + name = f"同学{i}" + chinese = float(format(random.uniform(0,100),'.1f')) + math = float(format(random.uniform(0,100),'.1f')) + english = float(format(random.uniform(0,100),'.1f')) + total = float(format((chinese + math + english),'.1f')) + #性别男为1,女为0 + gender = random.randint(0, 1) + + sql = f"insert into grade (name,chinese,math,english,total,gender) values ('{name}',{chinese},{math},{english},{total},{gender})" + #print(sql) + mysql_cursor.execute(sql) + mysql_con.commit() + +#多条执行,用时较少,对插入数据速度有要求时使用,但是如果执行过程有一处失败,则整个插入操作失败 +@time_deco +#insert_into_many函数运行耗时为:0.28s +def insert_into_many(): + values = [] + for i in range(10**4): + name = f"同学{i}" + chinese = float(format(random.uniform(0,100),'.1f')) + math = float(format(random.uniform(0,100),'.1f')) + english = float(format(random.uniform(0,100),'.1f')) + total = float(format((chinese + math + english),'.1f')) + #性别男为1,女为0 + gender = random.randint(0, 1) + + #将所有值包装成元组添加到values + values.append((name,chinese,math,english,total,gender)) + + sql = """insert into grade (name,chinese,math,english,total,gender) values (%s,%s,%s,%s,%s,%s)""" + #print(values) + mysql_cursor.executemany(sql,values) + mysql_con.commit() + +#查询语句 +def get_students(): + sql = "select * from grade where sid = 1" + mysql_cursor.execute(sql) + query_set = mysql_cursor.fetchall() + print(query_set) + +if __name__ == "__main__": + #insert_into_one() + #insert_into_many() get_students() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\345\217\230\351\207\217\343\200\201\345\255\230\345\202\250\350\277\207\347\250\213 \345\222\214 \350\247\246\345\217\221\345\231\250.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\345\217\230\351\207\217\343\200\201\345\255\230\345\202\250\350\277\207\347\250\213 \345\222\214 \350\247\246\345\217\221\345\231\250.md" index 727f3e99d2f41ff7b2cc4449e9a40220555324b5..f62363d05fef99d688d4114dab70501a03887c10 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\345\217\230\351\207\217\343\200\201\345\255\230\345\202\250\350\277\207\347\250\213 \345\222\214 \350\247\246\345\217\221\345\231\250.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\253\345\221\250/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202-\345\217\230\351\207\217\343\200\201\345\255\230\345\202\250\350\277\207\347\250\213 \345\222\214 \350\247\246\345\217\221\345\231\250.md" @@ -1,44 +1,44 @@ -1:重点掌握用户变量,练习变量(存储过程)的赋值和使用 - -``` -用户变量声明和调用 -set @test_name = '2'; -select @test_name; -``` - -``` -创建存储过程 -CREATE PROCEDURE add_date_test(days INT) -BEGIN - DECLARE t varchar(255); - set t = DATE_FORMAT(SUBDATE(CURRENT_DATE,days),"%Y/%m/%d"); - select * from grade where create_date = t; -END -``` - -``` -调用存储过程 -call procedure add_date_test(0); -``` - -2:练习触发器 - -``` -创建触发器-同一张表创建多个触发器会报错 -create trigger change_gender -before insert -on grade -for each row -begin - if new.gender = '男' then - set new.gender = '1'; - elseif new.gender = '女' then - set new.gender = '0'; - elseif new.gender not in ('男','女') then - set new.gender = '?'; - end if; -end -``` - - - +1:重点掌握用户变量,练习变量(存储过程)的赋值和使用 + +``` +用户变量声明和调用 +set @test_name = '2'; +select @test_name; +``` + +``` +创建存储过程 +CREATE PROCEDURE add_date_test(days INT) +BEGIN + DECLARE t varchar(255); + set t = DATE_FORMAT(SUBDATE(CURRENT_DATE,days),"%Y/%m/%d"); + select * from grade where create_date = t; +END +``` + +``` +调用存储过程 +call procedure add_date_test(0); +``` + +2:练习触发器 + +``` +创建触发器-同一张表创建多个触发器会报错 +create trigger change_gender +before insert +on grade +for each row +begin + if new.gender = '男' then + set new.gender = '1'; + elseif new.gender = '女' then + set new.gender = '0'; + elseif new.gender not in ('男','女') then + set new.gender = '?'; + end if; +end +``` + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202.md" index ab626390e007aab1d9d283d488714a57e3ca0338..a41ea2b2c8de07674eb497f9d26cf5791f90361b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202.md" @@ -1,135 +1,135 @@ -一:在浏览器中输入URL后发生了什么? - -1:输入URL(统一资源定位符) - -​ 由协议-域名-路径组成。如访问电脑Y盘-file:///Y:/,访问网址https://gitee.com/等 - - - -2:通过DNS解析将域名解析成IP地址 - -​ 输入域名--->DNS服务器--->返回真实的IP地址--->通过IP地址访问服务器 - - - -3:客户端和目标服务器建立连接 - -​ 二者互相确认身份,然后建立连接通道,再进行数据发送,确保数据没有传错给第三者 - - - -4:客户端正式向服务器发送请求 - - - -5:服务器处理请求数据并返回结果给客户端 - - - -6:客户端(即浏览器)收到返回结果,做相应渲染后展现出网页 - - - -二:五层协议有哪五层?举例说明 - -1:应用层 - -``` -为进程(客户端应用)跟进程(服务端应用)提供服务,规定了进程之间数据交互的方式 -``` - -​ 比如在浏览器中访问百度服务器: -​ 我跟百度服务器说好了,待会用http协议进行对话 - -``` -应用层协议: -1:http/https(超文本传输协议) -2:ftp(文件传输协议) -3:dns(域名系统) -4:SMTP(邮箱传输协议) -``` - - - -2:传输层 - -​ 为主机的进程之间的通信提供服务 - -``` -进程<---->进程 -一个主机可以开启多个应用,同时跟不同的服务器进行通信,但是共用一个传输服务进行数据的发送和接收 -``` - -比如在浏览器中访问百度服务器: - -规定好数据交互的方式后,浏览器把数据发给主机,说这些数据你帮我发送到百度吧 - -``` -传输层协议 -1:TCP(传输控制协议) - 提供面向连接,尽可能可靠的数据传输服务 - 面向连接指客户端和服务端进行三次交互验证,TCP三次握手,四次挥手,建立连接后才发送数据 - FTP(文件传输) - HTTP/HTTPS(浏览网页) -2:UDP(用户数据协议) - 提供无连接的,不保证可靠性的数据传输。随意发送一个数据,谁接收到或没有接收到都没有关系。 - 例如直播,实况游戏。 -``` - - - -3:网络层 - -​ 决定了数据的转寄和路径选择,封装和分组的传输层产生的报文段或用户数据段 - -``` -主机<---->主机 -客户端和服务端身份确认 -``` - -比如在浏览器中访问百度服务器: - -我向百度发送请求,网络层确保我访问的是百度服务器的ip地址,而不是别的服务器的地址,百度也确保相应的数据是发送给我,而不是别人 - -``` -网络层协议: - IP协议: - 公网ip(传统的ip地址,他是唯一的) - 局域网(ipconfig查询ip地址) -``` - -​ - -4:网络链路层 - -​ 负责两台主机之间的数据传输,向网络层提供数据传输服务,检查数据的完整性 - -``` -网卡<---->网卡 -``` - -​ 比如在浏览器中访问百度服务器: - -​ 网络链路层检查我发送的请求有没有全部发送出去,有没有出错 - -``` -链路层作用(比特流在传输时肯定有误差,数据链路层作用是检错和纠错): - 流量控制 - 差错检测 - 差错控制 -``` - - - -5:物理层 - -​ 真正进行数据传输。在局部局域网上传数据帧,在设备节点传输比特流 - -``` -光纤<---->光纤 -``` - -​ 比如在浏览器中访问百度服务器: - -​ 应用层定好数据的接头暗号(http等协议)后,传输层将数据打包给网络层,网络层确定了双方身份无误,网络链路层检查数据是否完整后,物理层真正进行数据交互 - +一:在浏览器中输入URL后发生了什么? + +1:输入URL(统一资源定位符) + +​ 由协议-域名-路径组成。如访问电脑Y盘-file:///Y:/,访问网址https://gitee.com/等 + + + +2:通过DNS解析将域名解析成IP地址 + +​ 输入域名--->DNS服务器--->返回真实的IP地址--->通过IP地址访问服务器 + + + +3:客户端和目标服务器建立连接 + +​ 二者互相确认身份,然后建立连接通道,再进行数据发送,确保数据没有传错给第三者 + + + +4:客户端正式向服务器发送请求 + + + +5:服务器处理请求数据并返回结果给客户端 + + + +6:客户端(即浏览器)收到返回结果,做相应渲染后展现出网页 + + + +二:五层协议有哪五层?举例说明 + +1:应用层 + +``` +为进程(客户端应用)跟进程(服务端应用)提供服务,规定了进程之间数据交互的方式 +``` + +​ 比如在浏览器中访问百度服务器: +​ 我跟百度服务器说好了,待会用http协议进行对话 + +``` +应用层协议: +1:http/https(超文本传输协议) +2:ftp(文件传输协议) +3:dns(域名系统) +4:SMTP(邮箱传输协议) +``` + + + +2:传输层 + +​ 为主机的进程之间的通信提供服务 + +``` +进程<---->进程 +一个主机可以开启多个应用,同时跟不同的服务器进行通信,但是共用一个传输服务进行数据的发送和接收 +``` + +比如在浏览器中访问百度服务器: + +规定好数据交互的方式后,浏览器把数据发给主机,说这些数据你帮我发送到百度吧 + +``` +传输层协议 +1:TCP(传输控制协议) + 提供面向连接,尽可能可靠的数据传输服务 + 面向连接指客户端和服务端进行三次交互验证,TCP三次握手,四次挥手,建立连接后才发送数据 + FTP(文件传输) + HTTP/HTTPS(浏览网页) +2:UDP(用户数据协议) + 提供无连接的,不保证可靠性的数据传输。随意发送一个数据,谁接收到或没有接收到都没有关系。 + 例如直播,实况游戏。 +``` + + + +3:网络层 + +​ 决定了数据的转寄和路径选择,封装和分组的传输层产生的报文段或用户数据段 + +``` +主机<---->主机 +客户端和服务端身份确认 +``` + +比如在浏览器中访问百度服务器: + +我向百度发送请求,网络层确保我访问的是百度服务器的ip地址,而不是别的服务器的地址,百度也确保相应的数据是发送给我,而不是别人 + +``` +网络层协议: + IP协议: + 公网ip(传统的ip地址,他是唯一的) + 局域网(ipconfig查询ip地址) +``` + +​ + +4:网络链路层 + +​ 负责两台主机之间的数据传输,向网络层提供数据传输服务,检查数据的完整性 + +``` +网卡<---->网卡 +``` + +​ 比如在浏览器中访问百度服务器: + +​ 网络链路层检查我发送的请求有没有全部发送出去,有没有出错 + +``` +链路层作用(比特流在传输时肯定有误差,数据链路层作用是检错和纠错): + 流量控制 + 差错检测 + 差错控制 +``` + + + +5:物理层 + +​ 真正进行数据传输。在局部局域网上传数据帧,在设备节点传输比特流 + +``` +光纤<---->光纤 +``` + +​ 比如在浏览器中访问百度服务器: + +​ 应用层定好数据的接头暗号(http等协议)后,传输层将数据打包给网络层,网络层确定了双方身份无误,网络链路层检查数据是否完整后,物理层真正进行数据交互 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" index 777e5bb49319909d753820ef0bfb496ba144ab8f..f66de187cca67a47fd4b1b2dd81463deb8900198 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\205\255\345\221\250/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202.md" @@ -1,72 +1,72 @@ -``` -TCP/IP协议 -应用和硬件之间的承上启下作用 -应用-路由器-光猫-光纤-互联网 -``` - -1:TCP/IP协议三次握手 - -``` -作用:为了建立起可靠的TCP连接,尽可能地保证数据传输的正确性 -``` - -​ ① 客户端向服务端发送SYN(同步序列编号)标识数据包----------------------------------服务端确认了客户端的发送能力正常 - -​ ② 服务端向客户端发送SYN/ACK(此处SYN跟上面SYN不同)数据包-------------------服务端确认了自己的接收能力正常 - -``` -服务端已经发送了ACK,还要发送SYN的原因:服务端通知客户端,服务端收到的信息确实是客户端发送的信息,说明客户端到服务端的通信是正常的 -``` - -​ ③ 客户端向服务端发送ACK数据包-----------------------------------------------------------------服务端确认了自己发送能力正常,服务端确认了客户端接收能力正常 - - - -2:TCP/IP协议四次挥手 - -``` -客户端和服务端都可以主动结束通信,此处以客户端为主动结束通信方 -``` - -​ ① 客户端向服务端发送FIN数据包--------------------------------在发送fin时就已经关闭了客户端到服务端的通信 - -​ ② 服务端向客户端发送ACK数据包-------------------------------服务端已经知道了客户端到服务端的连接通道已经关闭 - -​ ③ 服务端向客户端发送FIN数据包--------------------------------关闭服务端到客户端的连接通道 - -​ ④ 客户端向服务端发送ACK数据包-------------------------------通知服务端,客户端已经知道了服务端到客户端的连接通道已经关闭 - - - -3:HTTPS加密过程 - -​ ① 客户端向服务端发起通信请求 - -​ ② 服务端向客户端返回证书和密钥 - -​ ③ 客户端在CA中心验证证书的真实性 - -​ ④ 验证完成后,客户端用公钥对所要发送的数据进行加密,加密后然后发给服务端 - -``` -非对称加密 -16 = 2 * 8 或者 4 * 4 -当拿到公钥16后 -私钥是某个素数2 -通过私钥得出唯一解8 -``` - -​ ⑤ 服务端收到加密后的请求数据后,使用私钥进行解密 - -​ ⑥ 为了节约资源,双方互相确认后,使用对称加密进行通信 - -``` -这里为中间人攻击提供了条件 -``` - -``` -中间人攻击 -混到客户端和服务端之间的通信,对服务端伪造客户端,对客户端伪造服务端,拦截甚至可以篡改通信产生的数据、报文 -产生的条件:客户端要主动信任中间人的证书 -``` - +``` +TCP/IP协议 +应用和硬件之间的承上启下作用 +应用-路由器-光猫-光纤-互联网 +``` + +1:TCP/IP协议三次握手 + +``` +作用:为了建立起可靠的TCP连接,尽可能地保证数据传输的正确性 +``` + +​ ① 客户端向服务端发送SYN(同步序列编号)标识数据包----------------------------------服务端确认了客户端的发送能力正常 + +​ ② 服务端向客户端发送SYN/ACK(此处SYN跟上面SYN不同)数据包-------------------服务端确认了自己的接收能力正常 + +``` +服务端已经发送了ACK,还要发送SYN的原因:服务端通知客户端,服务端收到的信息确实是客户端发送的信息,说明客户端到服务端的通信是正常的 +``` + +​ ③ 客户端向服务端发送ACK数据包-----------------------------------------------------------------服务端确认了自己发送能力正常,服务端确认了客户端接收能力正常 + + + +2:TCP/IP协议四次挥手 + +``` +客户端和服务端都可以主动结束通信,此处以客户端为主动结束通信方 +``` + +​ ① 客户端向服务端发送FIN数据包--------------------------------在发送fin时就已经关闭了客户端到服务端的通信 + +​ ② 服务端向客户端发送ACK数据包-------------------------------服务端已经知道了客户端到服务端的连接通道已经关闭 + +​ ③ 服务端向客户端发送FIN数据包--------------------------------关闭服务端到客户端的连接通道 + +​ ④ 客户端向服务端发送ACK数据包-------------------------------通知服务端,客户端已经知道了服务端到客户端的连接通道已经关闭 + + + +3:HTTPS加密过程 + +​ ① 客户端向服务端发起通信请求 + +​ ② 服务端向客户端返回证书和密钥 + +​ ③ 客户端在CA中心验证证书的真实性 + +​ ④ 验证完成后,客户端用公钥对所要发送的数据进行加密,加密后然后发给服务端 + +``` +非对称加密 +16 = 2 * 8 或者 4 * 4 +当拿到公钥16后 +私钥是某个素数2 +通过私钥得出唯一解8 +``` + +​ ⑤ 服务端收到加密后的请求数据后,使用私钥进行解密 + +​ ⑥ 为了节约资源,双方互相确认后,使用对称加密进行通信 + +``` +这里为中间人攻击提供了条件 +``` + +``` +中间人攻击 +混到客户端和服务端之间的通信,对服务端伪造客户端,对客户端伪造服务端,拦截甚至可以篡改通信产生的数据、报文 +产生的条件:客户端要主动信任中间人的证书 +``` + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/parse/parse_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/parse/parse_search.py" index 85d51bda649295d2bf7a9a676d85bf57c587d6cd..5e31a96778adfe7e358f16b0d8af06e32febaa2c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/parse/parse_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/parse/parse_search.py" @@ -1,8 +1,8 @@ - - - -def parse_search_a(): - return r"我是 Y:\pycharmprojects\new\parse\parse_search.py 下的parse_search_a函数" - -if __name__ == '__main__': + + + +def parse_search_a(): + return r"我是 Y:\pycharmprojects\new\parse\parse_search.py 下的parse_search_a函数" + +if __name__ == '__main__': print(parse_search_a()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/test/parser_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/test/parser_test.py" index 49ed2308b2faab0d8ab704666866c04c8b3dcac8..9404f1b335c755c651e7b061506e8e8b3ce84405 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/test/parser_test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/new/test/parser_test.py" @@ -1,17 +1,17 @@ - -import os -import sys - -#不将工作目录添加到路径列表,pycharm下从parse_search导入parse_search_a不报错,但终端运行会报错 -sys.path.append(os.getcwd()) -from new.parse.parse_search import parse_search_a - -#入口程序不能使用相对路径,否则会报错attempted relative import beyond top-level package -#from ..parse.parse_search import parse_search_a - -#包名不能和系统内置包名冲突,否则会报错No module named 'parser.search'; 'parser' is not a pac kage - - - -if __name__ == '__main__': + +import os +import sys + +#不将工作目录添加到路径列表,pycharm下从parse_search导入parse_search_a不报错,但终端运行会报错 +sys.path.append(os.getcwd()) +from new.parse.parse_search import parse_search_a + +#入口程序不能使用相对路径,否则会报错attempted relative import beyond top-level package +#from ..parse.parse_search import parse_search_a + +#包名不能和系统内置包名冲突,否则会报错No module named 'parser.search'; 'parser' is not a pac kage + + + +if __name__ == '__main__': print(parse_search_a()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202-python\350\267\257\345\276\204.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202-python\350\267\257\345\276\204.md" index 1807e868d62afcf1ce62daede39e5e1588653339..db797eb910657243ac882e181fec0e785b84c943 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202-python\350\267\257\345\276\204.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\200\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202-python\350\267\257\345\276\204.md" @@ -1,15 +1,15 @@ -课后作业 - -1:命令行运行程序 - -​ 没有把工作目录添加到路径列表会报错 - -![命令行运行失败](https://s3.ax1x.com/2021/03/04/6Z8sMD.png) - -​ 把工作目录添加到路径列表后正常 - -![命令行运成功](https://s3.ax1x.com/2021/03/04/6ZGh79.png) - - - +课后作业 + +1:命令行运行程序 + +​ 没有把工作目录添加到路径列表会报错 + +![命令行运行失败](https://s3.ax1x.com/2021/03/04/6Z8sMD.png) + +​ 把工作目录添加到路径列表后正常 + +![命令行运成功](https://s3.ax1x.com/2021/03/04/6ZGh79.png) + + + 2:在`/test`目录中增加`parser_test.py`模块做解析测试 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" index 510361e8a4ed9963007e73c2e5130fae97abce22..8f3c0b8b937d7642047f7507d62fe362d88250bc 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/jd_search.py" @@ -1,52 +1,52 @@ -import scrapy -from bs4 import BeautifulSoup -import json -from jd_crawler_scrapy.items import JdCrawlerScrapyItem - -class JdSearch(scrapy.Spider): - name = 'jd_search' - - def start_requests(self): - for keyword in ['gtx1080','鼠标']: - for page_num in range(1,11): - url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" - - # 选用scrapy.FormRequest而不是scrapy.Request - # 因为FormRequest可以选择get或post两种请求方式,Request只有get - yield scrapy.FormRequest( - url=url, - method='GET', - # 如果是post,需要加上formdata - # formdata = data, - callback=self.parse_search - ) - def parse_search(self,response): - print(response) - - soup = BeautifulSoup(response.text, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - try: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs["data-lazy-img"] if img else "" - price = price[0].i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop else "" - icons = json.dumps([res.text for res in icons[0].select('i')]) if icons else [] - - item = JdCrawlerScrapyItem() - item["sku_id"] = sku_id - item["img"] = img - item["price"] = price - item["title"] = title - item["shop"] = shop - item["icons"] = icons - yield item - except Exception as e: +import scrapy +from bs4 import BeautifulSoup +import json +from jd_crawler_scrapy.items import JdCrawlerScrapyItem + +class JdSearch(scrapy.Spider): + name = 'jd_search' + + def start_requests(self): + for keyword in ['gtx1080','鼠标']: + for page_num in range(1,11): + url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" + + # 选用scrapy.FormRequest而不是scrapy.Request + # 因为FormRequest可以选择get或post两种请求方式,Request只有get + yield scrapy.FormRequest( + url=url, + method='GET', + # 如果是post,需要加上formdata + # formdata = data, + callback=self.parse_search + ) + def parse_search(self,response): + print(response) + + soup = BeautifulSoup(response.text, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + try: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs["data-lazy-img"] if img else "" + price = price[0].i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop else "" + icons = json.dumps([res.text for res in icons[0].select('i')]) if icons else [] + + item = JdCrawlerScrapyItem() + item["sku_id"] = sku_id + item["img"] = img + item["price"] = price + item["title"] = title + item["shop"] = shop + item["icons"] = icons + yield item + except Exception as e: print(e.args) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" index e43bc4ff04eaf38e63dd40921b15741e304d486f..c0ab2508a203b417229c03dbcdf445fab4dc22d6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\270\211\350\212\202/jd_crawler_scrapy/spiders/run.py" @@ -1,5 +1,5 @@ -from scrapy import cmdline - -#脚本启动scrapy项目,debug时可以用到 -command = "scrapy crawl jd_search".split() +from scrapy import cmdline + +#脚本启动scrapy项目,debug时可以用到 +command = "scrapy crawl jd_search".split() cmdline.execute(command) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/jd_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/jd_search.py" index 5c9f4f7dbf785bee2f7ac41733c00730b870227e..b12087aacf4817655377ef5c3fb2806e931224b4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/jd_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/jd_search.py" @@ -1,23 +1,23 @@ -import scrapy - - -class JdSearch(scrapy.Spider): - name = "jd_search" - - def start_requests(self): - for keyword in ['gtx1080','鼠标']: - for page_num in range(1,11): - url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" - - #选用scrapy.FormRequest而不是scrapy.Request - #因为FormRequest可以选择get或post两种请求方式,Request只有get - yield scrapy.FormRequest( - url = url, - method = 'GET', - #如果是post,需要加上formdata - #formdata = data, - callback = self.parse_search - ) - - def parse_search(self,response): +import scrapy + + +class JdSearch(scrapy.Spider): + name = "jd_search" + + def start_requests(self): + for keyword in ['gtx1080','鼠标']: + for page_num in range(1,11): + url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" + + #选用scrapy.FormRequest而不是scrapy.Request + #因为FormRequest可以选择get或post两种请求方式,Request只有get + yield scrapy.FormRequest( + url = url, + method = 'GET', + #如果是post,需要加上formdata + #formdata = data, + callback = self.parse_search + ) + + def parse_search(self,response): print(response) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202-scrapy\345\237\272\347\241\200.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202-scrapy\345\237\272\347\241\200.md" index 3fb547429998b2f6ea5a5cf81bed1f180dba87a2..9e52133796574f6d435f9758ddeb9832dc1ff564 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202-scrapy\345\237\272\347\241\200.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\215\201\345\221\250/\347\254\254\344\272\214\350\212\202/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202-scrapy\345\237\272\347\241\200.md" @@ -1,54 +1,54 @@ -流程 - -1、engine从spiders获取初始请求任务requests - -2、engine将请求任务发送给scheduler,scheduler对请求调度后产生任务 - -3、scheduler将下一个请求任务返回给engine - -4、engine将请求任务发送给Downloader去完成下载,途径下载器中间件 - -5、一旦完成下载,将产生response对象返回给engine,途径下载器中间件 - -6、engine将response对象发给spiders进行解析处理,途径爬虫中间件 - -7、spiders解析response对象后,将解析结果items发给engine,返回新的请求requests - -8、如果engine得到的是items,则发给item pipelines做数据处理,如果是requests请求,则发给scheduler - -9、周而复始,直到没有任务产出 - - - -![Scrapy architecture](https://docs.scrapy.org/en/latest/_images/scrapy_architecture_02.png) - - - -教程 - -1、安装:pip install scrapy - -2、创建项目:scrapy startproject project_name - -3、目录结构: - -​ spiders(目录):用于存放spiders项目文件,一个scrapy项目下可以有多个爬虫实例 - -​ items:解析后的结构化结果 - -​ middlewares:下载器中间件和爬虫中间件 - -​ pipelines:处理items的组件,一般在pipelines中完成items插入数据库的操作 - -​ settings:统一化的全局爬虫配置文件 - -​ scrapy.cfg:项目配置文件 - -4、scrapy爬虫demo - -5、启动爬虫: - -​ 切入项目目录:cd project_name - -​ 启动:scrapy crawl spider_name - +流程 + +1、engine从spiders获取初始请求任务requests + +2、engine将请求任务发送给scheduler,scheduler对请求调度后产生任务 + +3、scheduler将下一个请求任务返回给engine + +4、engine将请求任务发送给Downloader去完成下载,途径下载器中间件 + +5、一旦完成下载,将产生response对象返回给engine,途径下载器中间件 + +6、engine将response对象发给spiders进行解析处理,途径爬虫中间件 + +7、spiders解析response对象后,将解析结果items发给engine,返回新的请求requests + +8、如果engine得到的是items,则发给item pipelines做数据处理,如果是requests请求,则发给scheduler + +9、周而复始,直到没有任务产出 + + + +![Scrapy architecture](https://docs.scrapy.org/en/latest/_images/scrapy_architecture_02.png) + + + +教程 + +1、安装:pip install scrapy + +2、创建项目:scrapy startproject project_name + +3、目录结构: + +​ spiders(目录):用于存放spiders项目文件,一个scrapy项目下可以有多个爬虫实例 + +​ items:解析后的结构化结果 + +​ middlewares:下载器中间件和爬虫中间件 + +​ pipelines:处理items的组件,一般在pipelines中完成items插入数据库的操作 + +​ settings:统一化的全局爬虫配置文件 + +​ scrapy.cfg:项目配置文件 + +4、scrapy爬虫demo + +5、启动爬虫: + +​ 切入项目目录:cd project_name + +​ 启动:scrapy crawl spider_name + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202.py" index f5222c720f55946a75f25e220e837993a42a597f..3f1fd719820f6f83f610d80b8bae6b8b0d50330e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202.py" @@ -1,61 +1,61 @@ -#通过datetime模块完成时间戳,datetime.datetime对象,格式化字符串三者的转换 -#from _datetime import datetime -import datetime -from datetime import timedelta -import time - -#获取指定时区的时间,这个now实际上是datetime.datetime对象,>>>datetime.datetime(2021, 1, 5, 22, 42, 10, 284946) -now = datetime.datetime.now(tz=None) -print("当前时区时间:",now) - -#格式化输出时间,datetime.datetime对象转化为字符串,>>> '2021-01-05 22:42:10' -now = now.strftime("%Y-%m-%d %H:%M:%S") -print("datetime.datetime->str:",now) -now_2 = now - -#字符串转化为datetime.datetime对象,>>> datetime.datetime(2021, 1, 5, 22, 42, 10) -now = datetime.datetime.strptime(now,"%Y-%m-%d %H:%M:%S") -print("str->datetime.datetime:",now) - -#datetime.datetime对象转化为时间戳timestamp,>>> 1609857730.0 -now = now.timestamp() -print("datetime.datetime->timestamp:",now) -now_1 = now - -#时间戳timestamp转化为datetime.datetime对象,>>> datetime.datetime(2021, 1, 5, 22, 42, 10) -now = datetime.datetime.fromtimestamp(now,tz=None) -print("timestamp->datetime.datetime:",now) - -#时间戳转化为字符串(时间戳->datetime.datetime->字符串) -now_1 = datetime.datetime.fromtimestamp(now_1,tz=None) -now_1 = now_1.strftime("%Y-%m-%d %H:%M:%S") -print("timestamp->str:",now_1) - -#字符串转化为时间戳(str->datetime.datetime->timestamp) -now_2 = datetime.datetime.strptime(now_2,"%Y-%m-%d %H:%M:%S") -now_2 = now_2.timestamp() -print("str->timestamp:",now_2) - -#封装一个函数get_date(day_delta),如果输入-1,返回当前日期减1的字符串 - -print("------------------------------------------------") -def get_date_deco(func): - def wrapperr(*args,**kwargs): - #这里的参数居然是传入get_date函数的参数day_delta - #for i in args: - #print(i) - result = func(*args,**kwargs) - print(f"当你传入参数{args}进行运算后的日期为:{result}") - return result - return wrapperr - -@get_date_deco -def get_date(day_delta): - day = datetime.datetime.now(tz=None) - print(f"当前日期为:{day.strftime('%Y-%m-%d')}") - #需要先进行时间运算后,再格式化日期,顺序相反会报错 - day = day + timedelta(days=day_delta) - day = day.strftime("%Y-%m-%d") - return day - +#通过datetime模块完成时间戳,datetime.datetime对象,格式化字符串三者的转换 +#from _datetime import datetime +import datetime +from datetime import timedelta +import time + +#获取指定时区的时间,这个now实际上是datetime.datetime对象,>>>datetime.datetime(2021, 1, 5, 22, 42, 10, 284946) +now = datetime.datetime.now(tz=None) +print("当前时区时间:",now) + +#格式化输出时间,datetime.datetime对象转化为字符串,>>> '2021-01-05 22:42:10' +now = now.strftime("%Y-%m-%d %H:%M:%S") +print("datetime.datetime->str:",now) +now_2 = now + +#字符串转化为datetime.datetime对象,>>> datetime.datetime(2021, 1, 5, 22, 42, 10) +now = datetime.datetime.strptime(now,"%Y-%m-%d %H:%M:%S") +print("str->datetime.datetime:",now) + +#datetime.datetime对象转化为时间戳timestamp,>>> 1609857730.0 +now = now.timestamp() +print("datetime.datetime->timestamp:",now) +now_1 = now + +#时间戳timestamp转化为datetime.datetime对象,>>> datetime.datetime(2021, 1, 5, 22, 42, 10) +now = datetime.datetime.fromtimestamp(now,tz=None) +print("timestamp->datetime.datetime:",now) + +#时间戳转化为字符串(时间戳->datetime.datetime->字符串) +now_1 = datetime.datetime.fromtimestamp(now_1,tz=None) +now_1 = now_1.strftime("%Y-%m-%d %H:%M:%S") +print("timestamp->str:",now_1) + +#字符串转化为时间戳(str->datetime.datetime->timestamp) +now_2 = datetime.datetime.strptime(now_2,"%Y-%m-%d %H:%M:%S") +now_2 = now_2.timestamp() +print("str->timestamp:",now_2) + +#封装一个函数get_date(day_delta),如果输入-1,返回当前日期减1的字符串 + +print("------------------------------------------------") +def get_date_deco(func): + def wrapperr(*args,**kwargs): + #这里的参数居然是传入get_date函数的参数day_delta + #for i in args: + #print(i) + result = func(*args,**kwargs) + print(f"当你传入参数{args}进行运算后的日期为:{result}") + return result + return wrapperr + +@get_date_deco +def get_date(day_delta): + day = datetime.datetime.now(tz=None) + print(f"当前日期为:{day.strftime('%Y-%m-%d')}") + #需要先进行时间运算后,再格式化日期,顺序相反会报错 + day = day + timedelta(days=day_delta) + day = day.strftime("%Y-%m-%d") + return day + get_date(10) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202.py" index 27bf897633d2d7c5734b97a763bab841e72d034a..987d7fde4dfdd2e849873c46b560e468393e9f8c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202.py" @@ -1,95 +1,95 @@ - -#将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. -''' -实例方法:先声明一个实例用于继承父类,再通过实例调用父类的方法 -静态方法:通过@staticmethod装饰器,可以直接调用类方法 -''' -class MyMath_1: - #实例方法 - def add_1(self,a,b): - return a+b - #静态方法 - @staticmethod - def add(a,b): - return a+b - - @staticmethod - def sub(a,b): - return a-b - - @staticmethod - def mul(a,b): - return a*b - - @staticmethod - def div(a,b): - return a/b - -m_1=MyMath_1() -print('实例方法',m_1.add_1(1,2)) - -print('静态方法',MyMath_1.add(1,2)) -print('静态方法',MyMath_1.sub(1,2)) -print('静态方法',MyMath_1.mul(1,2)) -print('静态方法',MyMath_1.div(1,2)) - -print('-----------------1--------------------') - -#为上节课自定义类添加以下功能 -''' -一:添加类属性 -二:添加类私有属性 -三:添加类方法或者类的私有属性 -四:在__init__方法中初始化实例属性 -五:在__init__方法中绑定私有实例属性 -六:在自定义类中实现__str__, 自定义输出格式 -''' -class Door(): - - #一:添加类属性 - UsedFor='我可以防盗' - other=None - - #二:添加类私有属性,不希望外部更改, 只作用于类内部,通过类._类名__变量名来访问私有属性 - __notes='屋里有私人物品,请慎重' - - #三:添加类方法或者类的私有属性 - #实验发现,当类方法名(不)为__new__时,创建实例时(不)会自动调用类方法 - @classmethod - def __new__(cls, *args, **kwargs): - print('这是一个类方法') - return super().__new__(cls) - # 类方法可以通过 实例名.类名.私有属性名 调用类的私有属性 - def new_1(cls): - return Door.__notes - - #四:在__init__方法中初始化实例属性 - #五:在__init__方法中绑定私有实例属性,实例的自有属性 - def __init__(self,special): - self.special='我的特点是:'+special - - - -d_1=Door('0') -print(d_1.new_1()) -print('--------------------------------------') - -wooden_door=Door("便宜") -print('我是木屋,'+wooden_door.special) -print('--------------------------------------') - -wooden_door=Door('other') -wooden_door.other='木屋.other' -glass_door=Door('other') -glass_door.other='玻璃门.other' -print(wooden_door.other) -print(glass_door.other) -print('--------------------------------------') - -# 六:在自定义类中实现__str__, 自定义输出格式 -class Test(list): - def __str__(self): - print() - return f'这个list长度为:{len(self)}' -test=Test(['1','2','3','4']) + +#将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. +''' +实例方法:先声明一个实例用于继承父类,再通过实例调用父类的方法 +静态方法:通过@staticmethod装饰器,可以直接调用类方法 +''' +class MyMath_1: + #实例方法 + def add_1(self,a,b): + return a+b + #静态方法 + @staticmethod + def add(a,b): + return a+b + + @staticmethod + def sub(a,b): + return a-b + + @staticmethod + def mul(a,b): + return a*b + + @staticmethod + def div(a,b): + return a/b + +m_1=MyMath_1() +print('实例方法',m_1.add_1(1,2)) + +print('静态方法',MyMath_1.add(1,2)) +print('静态方法',MyMath_1.sub(1,2)) +print('静态方法',MyMath_1.mul(1,2)) +print('静态方法',MyMath_1.div(1,2)) + +print('-----------------1--------------------') + +#为上节课自定义类添加以下功能 +''' +一:添加类属性 +二:添加类私有属性 +三:添加类方法或者类的私有属性 +四:在__init__方法中初始化实例属性 +五:在__init__方法中绑定私有实例属性 +六:在自定义类中实现__str__, 自定义输出格式 +''' +class Door(): + + #一:添加类属性 + UsedFor='我可以防盗' + other=None + + #二:添加类私有属性,不希望外部更改, 只作用于类内部,通过类._类名__变量名来访问私有属性 + __notes='屋里有私人物品,请慎重' + + #三:添加类方法或者类的私有属性 + #实验发现,当类方法名(不)为__new__时,创建实例时(不)会自动调用类方法 + @classmethod + def __new__(cls, *args, **kwargs): + print('这是一个类方法') + return super().__new__(cls) + # 类方法可以通过 实例名.类名.私有属性名 调用类的私有属性 + def new_1(cls): + return Door.__notes + + #四:在__init__方法中初始化实例属性 + #五:在__init__方法中绑定私有实例属性,实例的自有属性 + def __init__(self,special): + self.special='我的特点是:'+special + + + +d_1=Door('0') +print(d_1.new_1()) +print('--------------------------------------') + +wooden_door=Door("便宜") +print('我是木屋,'+wooden_door.special) +print('--------------------------------------') + +wooden_door=Door('other') +wooden_door.other='木屋.other' +glass_door=Door('other') +glass_door.other='玻璃门.other' +print(wooden_door.other) +print(glass_door.other) +print('--------------------------------------') + +# 六:在自定义类中实现__str__, 自定义输出格式 +class Test(list): + def __str__(self): + print() + return f'这个list长度为:{len(self)}' +test=Test(['1','2','3','4']) print(test) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202.py" index b6b96d655dbfd84b6d36c844cd71c3a60ae966b7..799672cad959c6d5d975401933812e33cb62ebb2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\227\240\345\275\242\344\271\213\345\210\203\344\270\266\346\234\200\344\270\272\350\207\264\345\221\275/\347\254\254\345\233\233\345\221\250/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202.py" @@ -1,56 +1,56 @@ -class MyMath: - def __init__(self,a,b): - if (type(a)==int or type(a)==float) and (type(b)==int or type(b)==float): - self.a=a - self.b=b - else: - print('输入数字好吧') - def add(self): - return self.a+self.b - def sub(self): - return self.a-self.b - def mul(self): - return self.a*self.b - def div(self): - if self.b==0: - return '分母不能为0' - else: - return self.a/self.b -m_1=MyMath(1,2) -print(m_1.add()) -print(m_1.sub()) -print(m_1.mul()) -print(m_1.div()) -print('-----------------1--------------------') - - -#将事物抽象出类,并创建实例 -class Door(): - UsedFor='我可以防盗' - def __init__(self,special): - self.special='我的特点是:'+special - -glass_door=Door('透光') -print(f'我是玻璃门,{glass_door.UsedFor},{glass_door.special}') -wooden_door=Door('便宜') -print(f'我是木门,{wooden_door.UsedFor},{wooden_door.special}') -iron_gate=Door('耐用') -print(f'我是铁门,{iron_gate.UsedFor},{iron_gate.special}') -print('-----------------2--------------------') - - -#创建多个继承作业2父类的子类 -class Glass_Door(Door): - name='我是玻璃门--' -class Wooden_Door(Door): - name='我是木门--' -class Iron_Gate(Door): - name='我是铁门--' - -glass_door=Glass_Door('透光') -print(glass_door.name,glass_door.UsedFor,glass_door.special) -wooden_door=Wooden_Door('便宜') -print(wooden_door.name,wooden_door.UsedFor,wooden_door.special) -iron_gate=Iron_Gate('耐用') -print(iron_gate.name,iron_gate.UsedFor,iron_gate.special) +class MyMath: + def __init__(self,a,b): + if (type(a)==int or type(a)==float) and (type(b)==int or type(b)==float): + self.a=a + self.b=b + else: + print('输入数字好吧') + def add(self): + return self.a+self.b + def sub(self): + return self.a-self.b + def mul(self): + return self.a*self.b + def div(self): + if self.b==0: + return '分母不能为0' + else: + return self.a/self.b +m_1=MyMath(1,2) +print(m_1.add()) +print(m_1.sub()) +print(m_1.mul()) +print(m_1.div()) +print('-----------------1--------------------') + + +#将事物抽象出类,并创建实例 +class Door(): + UsedFor='我可以防盗' + def __init__(self,special): + self.special='我的特点是:'+special + +glass_door=Door('透光') +print(f'我是玻璃门,{glass_door.UsedFor},{glass_door.special}') +wooden_door=Door('便宜') +print(f'我是木门,{wooden_door.UsedFor},{wooden_door.special}') +iron_gate=Door('耐用') +print(f'我是铁门,{iron_gate.UsedFor},{iron_gate.special}') +print('-----------------2--------------------') + + +#创建多个继承作业2父类的子类 +class Glass_Door(Door): + name='我是玻璃门--' +class Wooden_Door(Door): + name='我是木门--' +class Iron_Gate(Door): + name='我是铁门--' + +glass_door=Glass_Door('透光') +print(glass_door.name,glass_door.UsedFor,glass_door.special) +wooden_door=Wooden_Door('便宜') +print(wooden_door.name,wooden_door.UsedFor,wooden_door.special) +iron_gate=Iron_Gate('耐用') +print(iron_gate.name,iron_gate.UsedFor,iron_gate.special) print('-----------------3--------------------') \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" index 3bc16df6f3dfe63f7f57cc730a3cd407118cd50d..e52df6543ba1be750b5235928b1d297cc203cedb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" @@ -1,15 +1,15 @@ -4班-武明-第一周-第二节作业 - -课后作业 - -- 新建一个项目, 建立虚拟环境,在pycharm中配置虚拟环境 - -![ScreenClip](http://typorabypicgo.zhanghm.cc/ScreenClip.png) - - - -- 建立git仓库,并同步到码云: - - - +4班-武明-第一周-第二节作业 + +课后作业 + +- 新建一个项目, 建立虚拟环境,在pycharm中配置虚拟环境 + +![ScreenClip](http://typorabypicgo.zhanghm.cc/ScreenClip.png) + + + +- 建立git仓库,并同步到码云: + + + ![ScreenCladip](http://typorabypicgo.zhanghm.cc/ScreenCladip.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250_\347\254\2541\350\212\202_\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250_\347\254\2541\350\212\202_\344\275\234\344\270\232.md" index 2b06d96fedad7d67282c9fe8a515b1559cbb67a6..9505fdb4665715c22b75debc4492ef92b6b26090 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250_\347\254\2541\350\212\202_\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\200\345\221\250_\347\254\2541\350\212\202_\344\275\234\344\270\232.md" @@ -1,6 +1,6 @@ - - -环境变量: - -![ScreenClip](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAw0AAADrCAYAAAArFHriAAAAAXNSR0IArs4c%0A6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAEwySURB%0AVHhe7d15VxNZuDb8/jx1GPRAK/jIIMghIIgNjUHllQYFEdDQCg5NizKIILaC%0AgoACSlBoIBKBEkJc65w/n2/xnI9yvTVkqCQ1ZQBBLtf6rWVq2FW1966q+66J%0AX04XnEG0//zP/4wZRkREYfJx8njWr0REREcCkwYiogQwaUjOsarHWPYv41FV%0Atu74eBw73oo3BmWlcjlEREcZkwYiogQwaUjOj0wazvcuw/+mFS1v/FjuvRAx%0APRER6WPSQESUACYN++PY8Qt4tOzHmxbj5MIsaYimJBHLj3H+eHagbN6FICKy%0Ag0kDEVECmDTsj1QnDfLdBW1Zx1reKHcdtNMQEVEsJg1ERAlg0hAWDuzl4N2P%0A79+/K4LBefR4//JjVJ7vxbL/DVqUK/6BoL/3TWhe+bEhdXi4PHk++Q5B7PJj%0A5w8mAurjScHlxN5Z0N55CA4jIqJYTBqIiBLApCEsmBT4A8G5Mky+gh8RrEeN%0AjwjmA8lERKCvBvfhhMM4qDedP2Y54XUIzxs5jIiIYjFpICJKAJOGML3AXjtM%0Ad3xMMB++A6BOH2/SYDC/djny/6PuKminDQ4jIqJYTBqIiBLApCFMNynQDNMd%0A/yOSBp27CnrDiIgoFpMGIqIEMGkICwb22heKlc+ahoL1g5Q0hKdTptWMDw4j%0AIqJYTBqIiBLApCEsFNi/0byIrAnEk0ka5N9yAmLrRWiLpEEex68nERElhkkD%0AEVECmDSE6SUFB5WSRASSj+jkhIiIjDFpICJKAJOGsP1KGtQ7CuFPsAbFu1z+%0ARWgiovgxaSAiSgCThrDDdKeBiIgSw6SBiCgBTBqIiOgoYdJARJQAJg1ERHSU%0AMGkgIkoAkwYiIjpKmDQQESWASQMRER0lhkkDERERERGRzDBp+D+lvxMRERER%0AETFpICIiIiIic0waiIiIiIjIFJMGIiIiIiIyxaSBiIiIiIhMMWkgIiIiIiJT%0ATBqIiIiIiMgUkwYiIiIiIjJ1aJKGU1dG8Nm/gt4rNbrj7ThVch9v/DO4WZJ4%0AGQfJYdoe78aWQm8cERERER1scScNN9/68f379xj+t/d1p0+Vw5I0nCq5gd5l%0AP9649j6QZ9JARERERPsh4TsNh/Gq/VFNGs45m3C26krMcHmYPC56+F5g0kBE%0ARER0eDFpSLGDmDScvXAFl1s6IxIH+f/Rw/YSkwYiIiKiwyvlSYM6PPwI0+eB%0AG4HhwWBaHe9fHkH12XvS/1fQ65IfPVLnkYPtU66Z2PmVx5PU5anLkOYbiJ0u%0APG14HYIBvHadU/G4kx6zpCG6bvxR9WdYdza2J1iGEW3icLaqfs8ThmCSYEVv%0AXiIiIiI6WFKaNKjDwoG4NoAO/l8bKAeDZDmBqJED+UCyEHw/IiJRiEkapPki%0AplOXqyznrVqeMk4qM7hM7Trvd9IQXOeI5CZm3SLHq/PZ2x7tPEaCicPlG3LC%0AUK87TaroJQh69OYlIiIiooMltUmD5g6BlhwI6wXTahnaJMP4d2zSoJ1OLjsy%0AAagZWAktP9EgOxGGSYMc7AeSI71p9cZrpWJ7lDsMUsKwn48lBTFJICIiIjq8%0AfrmZX5jSpMEo8N2vpEGdLnzFPnY++0F2IuJPGgLrbVB3qdqe8DsM9brvOOw1%0AJg1EREREh1dqkwZlWGTAfPNtMMDdp6QhKviWr9Af6MeTAusaHB+cT/7dK9+h%0Asbk9wTL1hBMGzYvQ+5w4MGkgIiIiOrxS/yJ04Mp48FGacBC8T0lDYDnB5X+W%0Akha9K/N7nTQEly+LTgxCw6PqT1t34cTA3vZo1yFaudEnV6XEQR4XPXwvMGkg%0AIiIiOrwSThqIiIiIiOhoYNJARERERESmmDQQEREREZEpJg1ERERERGQq4a8n%0AERERERHR0cA7DUREREREZIpJg4Xy4f9LGnp1REREREQ/Nz6eZEEvcD7K9OqI%0AiIiIiH5uhncaSKUXOB9lenVERERERD83wzsN//Ef/0FERERERMSkgYiIiIiI%0AzBk+nqQ3MRERERERHT1MGoiIiIiIyNQvNXw8iYiIiIiITPCdBiIiIiIiMsXH%0Ak4iIiIiIyBSTBiIiIiIiMsV3GoiIiIiIyBTfaSAiIiIiIlNMGoiIiIiIyBTf%0AaSAiIiIiIlNMGoiIiIiIyBSTBiIiIiIiMsWkgYiIiIiITPFFaCIiIiIiMsU7%0ADUREREREZIp3GoiIiIiIyBSTBiIiIiIiMsXHk4iIiIiIyBSTBiIiIiIiMsWk%0AgYiIiIiITDFpICIiIiIiU3wRmoiIiIiITPFOAxERERERmfqlhncaiIiIiIjI%0AxL49niQIZ3DlTheuFAm64392P/v2H/X2JSIiIvqZ7dvjSYKQhevj21h5dF53%0A/M/uZ9/+/dy+09Vt+NN1BUXpe5Og7HX5RERERIdNXEmDkF2O9uF3+NcrQlz/%0AhImey8hPsx9YZTWNYXvtMc7HMc/PxGz7BaEY9xf9+P79u2JXXMfixF9w5qXH%0ATGtGKLoDt38C1zIjlyEIZej514fR+r2r+2Ta1+76CUIaihsfYbC/HeezwtOm%0AavuMypel5zvxcGwBa5siNtcW8LK7BrlCcsuL149sXyIiIjq6bCcNgpCJ2kEP%0AxPlHqK8ohaOmHS9XRMy6imKmNSJkNWBM9KC3Kk13/M/ObPuDScPkrTMoKCjA%0AmdIauN58wbeZDuTHEZj+yKAymfZNdv32evsEoQidc9+w+uoWah0lKL90H++k%0A5GGsKUd3+r3CpIGIiIh+BNsvQgtCJXrXtjB0MRwQnqhqxb3mChzTBLVClhNP%0ApWTCO9mGgqhgVxCO4Y+XIjx91UiLGScHPV8x2Hodz91eiFsezA+3oFgTHFX2%0ArsEz0ILmkQV4RRHr7n/QUZYVLiO7HB3Ds1j5KmLLs4jXD53I01z1ziy+hqHZ%0ANWyJG/g0dgv13XPwvWgIjbcqP6OwHr2Tn6Rx37D1ZTHiTotQ9hD/up+hd8qL%0ATXcPnPUDWN7yYrarAumBbTXffjVpeNWYER5W3IVF/xRuZAvK/927btzRvDOQ%0A7hzGhjiKK1IdCZW98PjDdyqC/Iv3USwtS63fHTy/9QeGF9T6nRtqQlFGuDyz%0A+gu2z0BLE0YC7aPMr3mEx2z7lPGZRWjsm8LSugjRu4ypvj9wJrB8O+uX55oN%0Ab5f/FRo0y7Azv1n7yUzLz7qMxzODaMgJD6t9ugHxWZ06XkoqGjqbcS5H/86Q%0AVf8+DO1LRERER5ftF6EFwYkRcQ09FeZBhJBzDROiHz4pmCnVCRyP1Y9CXB9A%0AtSZYk6lByzeszfShuaoUZbUuTHzZwfvbBaFp5KBe9Mygv+U3OMpq4Br3YNfd%0AhSIlaMrE7/KdkI9P0FBZCsfFTkxKwelUW36g/DzcercD73Q36spLUX65Wwre%0APDFJg3H5p9A6vobZ/hb8Xl6i3mlZFfG29bRavpw0bLyF60IVHsxt4UPPJZxr%0AG8PWxhBqNPVgvP06SUO+Cx/8M2iTAlVBOI3b7334/KAsMH06Lo9sYHPkMjLk%0A9cvMwZniYhRf7MWSNE9nmfR/+Xdhjjpeqd9trE734kaVAw5nF2Y2tqX1PxUo%0Az6r+5PlFrEw9jph/6qY6f5DR9slKu93YWR7FjWoHSquaMfxJhLvboYyzWj9Z%0Aenauchem4OITrOgmDWbbZ95+VuVHk+u/4Z9teJ5cCPw+jfq+eaxvLuNNT2zy%0AYNW/D0v7EhER0dGU8qRBlnEiDznH9R9RETKvYHTLi4EavaDKLwUpJ0LDSqQg%0Ac3f8GjIDwZsc1O9OtiIr8Fso6cZn/wSuH5eDpgr0rokYdobLlef3BeYX0uvx%0A0reGR5Xh9a/pX49JGozKD06jVfH3CsSRS8r/laTB24/fpHkvPPFg/PoxCAWd%0A+Oh/iauB8pTpDLc/MmkQMk6jbuAzfFLSIl9JloedbJnA9lovKqSAXMi8LJWz%0AgWfOcJKhzGf6+IpUv23hx2mqB9bD629VfxbzBxlvXx5c834piA237/GqdvS7%0AapAdR/kyofS+FDjrJQ325g/Stp+WXvnRhJzrUnL8BX3VkfV/vPAiXM9msb6x%0AjNdS8lAeSB7s9O/D0L5ERER0NMXxTkM4aRAuP4O4vY1t2XRHXC+DCkIGroxs%0Awvu0NvTYjjpcDloin8nOaZuC//3tUPnKnQBNECM/7lJ77aLyiIdeUqPMP+tS%0A5heyWjDpj3z8o+zhUuydBoPy5d85Nd0Yc69hQ1S3fce3G5pfSRrWB3BBWpaS%0ANFzLDCQN0cGt0farScOuTy3bJ5X9bXkMbY5j4WmO1+PF1jr6azLUK/reIfyu%0AefxEmSaOZ95L7y/C/6oxMN6i/izmD4qnfbXsli8zThrM5zdrPy2rpEHILMbt%0AqQ18eXEVOQbTHCuoxd3xVeyMNSn1oLd+0f37MLQvERERHU2JJQ1Zp5RHIyrv%0AzYWCjujpzWTUDWPz6zBqtc9b2wiqooN6LcOgKDC/kNGAMd8yHjrC46uk8syS%0ABi0hUyp/YwvT9+pQXqo+GlI/uBJ30iDT3341aXjrKlXKLsr/NSLoVqfJQO3T%0AdWw8u4KGURHrAzWx06Q6qAzWXxxBpd321Yqn/ESSBqv20zJLGoTjDtyalNpg%0A5g7Kde5AyV9fOuFoxIOXi/Cuf8Dw9bPK+x166xeTNByS9iUiIqKjJ46k4Twe%0AeyJfhC7snMfuREvocZ4gs8eTZEK6E8MbGxjWPHqhBi2Rj2+U3luMeTzJOGkw%0AePxirCnwzHcRuty7+He4AYXHMnD8zB/od2/aTxqK7krB2ms0BQJhOTisHfQm%0AlDTob3/sOw160iofYXXtHd6tfcGTC7F1LJxJNKi0qj/7QaX+9sU+npRV7cLQ%0AnVrN40k2y08kabBoPy2jpEE4WY2euQ2sT7pQFvU5VvkdhJyK6+gZX8KmV0oW%0AOutQqEkq7PRv2WFoXyIiIjp64kgajqPu2Xrgk6slcFS34eXqNmZdZyKns3gR%0AWplGyIBzyIsNKUAPXklVg5ZteN71ofl88EXNHan8qBehDZOGwIueH3pxtSL4%0Aouk3BF/0lGVf6Mbs1134d3extdgHV/+i/aThWD1eiBt4KwW5jrNlqL35FC8+%0Ahh9viitp0N1+e0mDPF232w+/0d97yLqOCZ8Hoy2VOCu/KJuXHZjPKqg0r794%0Agkq97ZOpL0I/x40LpSi90IKRJRELd0sC81itXzqycws0LypPol3+f8FpZKdb%0AB72W7WdV/vFqPJbW98vbO6gpCkwny81WtlH+utijhQ8Y+fMSzkQlFGr51v1b%0Ane7gty8REREdPbaTBplwohKu5/NY3ZD/uNtnTPbWo0DzCIoyTfCTq29jP7mq%0AlVE7CO/WKC4FrpgGg6pRV+CTlOI6Fp63okRzRdUsqJcJ2efQMTKHNWX9PmGi%0A5xLyoz4ZKWRk4VR+Do5LAdlvfR5sPK0NjTNPStKQX9+HmdUtfBM9mHvWjKpb%0AUwklDbLY7bebNPyKlkkfVh5VGozPRPntcSxt7qif5By/ZvtKsln9xRtURm+f%0ATH4XoGlgGsvewCdXnzSgMHTl3yrozYVrVueTo/5FdBXbSBqs2s+q/NwOzOp9%0A8jT0TkA6MqL2BS07/Vud7nC0LxERER0tcSUNqSSkV2NwXZSCFPVFX72gJdXk%0AgOtkvnyFuAgO511MebekIP2k7rR7LXr77RJOtmDKt4KH5XtXT6mQ6Pb9rOz2%0A78PSvkRERHS02P7kaqrJV36rBzwQXzQofxxuf5IGKZD96offvwPR48b4/drQ%0AS6j7LXr79abRI7+86lt6aPjo10GR6Pb9rOz278PSvkRERHS0/LA7DURERERE%0AdDgoSYP8bDSTBiIiIiIi0sOkgYiIiIiITDFpICIiIiIiU8qL0EwaiIiIiIjI%0ACO80EBERERGRKSYNRERERERkSkkaojFpICIiiiTU9GN9exvbMk8/qvn3VIhs%0AEbKu43Vw39meR2ch953DiEnDTyrr7FXcf/4ej5zcMYmIzrpe4nVvG87npOmO%0At0OoHcSWdxRNxcUoLsrFcSYNR87p6jb86bqCovS9a/vDeP622r+EtGzkyftN%0AWSdm/G7cKTqc+85+tP9BZjtpEIRi3F/0K48yyXbFdSxO/AVnXnrMtGaEojtw%0A+ydwLTOywvfjL0Kbid6+oImWLN3pzWT+1oc13yK6HfbrRhBOoGM6dvlTbTm6%0A05s5ceEB5rwrGOv+A6XZ9urzZ9l+QchG9b0prGz5lPn94gic0ondTvlCdjna%0Ah9/hX6+ILY8bYw+cyIvjwCCcqIRrdA6rG/L8i3j9Vx3y08Lzm5Vvp/7T8514%0AOLaAtU0Rm2sLeNldE/qL5vHsP4KQDscDN8RZFwo165cMIfMaJvx+eAdrka7U%0Adx465/zwL95H8T4FVmb1IxNyLuBPqX3WpPYRvyxi4lE9CuNoX8vyrdpfyED+%0AlT64RaledP7qd7LrZ8Vs+cH2i+5/8bSf5fZbjLeSbP1l5tegY+gjvEsjqM9P%0ALHFQkob1AVyIXraN/i9knUP7SGD91pfwtq8RRRnhcoSsUrQMzWBZOj6I3iVM%0APbma0va3Ylm/FsfHvW7/IKvzSyLHN7vHT0FIQ3HjIwz2t+N8Vuy0RvFNPMzO%0A30JmA8bEXeyuPcZ5TftY9T91+9T927+7ja8r8xi5fR4notpYlmj92t2/1HU9%0AnEmDVfsbSfb8fpDEnTRM3jqDgoICnCmtgevNF3yb6UB+HBt2cJOGdPx6ukDZ%0ANllpfS8+Sgfuh+czdKc3IqQVo+ujD56ntXFdhRKEHNya8WPmz9LQOshys+I7%0AuQkZVehf28D49TykxbX8n2T7T97EtH8Zg1dKUSiXkZ+DY9J6WJUvCL+iftSL%0Arbm/cbWiFI7aWxhb28Z8Z3HMMvQIwnE4n61DnH+Eemn+strbeO35humO/MB4%0A8/Kt6l8QiqSTwDesvrqFWkcJyi/dxzvp4DLWpCY98ew/aYW3MCsu4kFZfG1r%0ARjkR7C5h6d0gqqUTiZDbjkm3G6v7lDRY188xXHm+IZ3oenC5/CxKa9ql+t/B%0Au1sFMWXpsS7fvP1lJe3T8Er1/uzFPHajg/Yk188O0+UrJ/LP+Ls63Acru+aw%0A8+6WrROXdf+3rh8rqag/5aJC3xI2x5p0AyYrpkmDRf8/37smbX+vtP0lKK1u%0Aw8s1H9xdper80v5//tEytheH0FRVitILNzCyJOLDn/aOP6lgXr9Wx6+9b3+Z%0AnfNLIse3VMUfySYNVufvtJoBfJ19i7fiAv7UPN5j1f+C2zd2U9q3C4tRUf8Q%0As5sbeNkYeVEu2fq1s38d5qQhUcme3w+SuJOGV43hjiIUd2HRP4UbUjYs/9+9%0AG9kR0p3D2BBHcUXagYTKXnhMrmSpnXoHz2/9geEFL8QtD+aGmiKvxGSXo2N4%0AFitfA1cqHjqRF8h01fm/YqClCSNuzfwJXKnJLOnA1JclDF0+FVfgLcttmZCW%0A/QZNOfHNJwi5cM368aY5/iv7WtlNY9hZ7oFDcwVAJjgeYtk3ieZfw8MznENS%0A+7xE/bHIaQ/y9gtZTjxdEeGdbEOBzroZJ6Xm5QsZ9fhnewV/lYfnO9E6Cf98%0AZygpFjKL0Ng3haV1+UrgMqb6/sCZQP8UhPN47NnC0MVwklPctYDd8evIlPu3%0AjfKD9OpfyLqMxzODaNDUa+1TKUh6VqeOV/r/NkZd1/E80P/nh1tQHFMPOWh+%0AvYmV/mplvbTjkqGeCCbQ3z+Hvuo05NycwNjTZ1jXBE0ZhfXonfwkBSbfsCVf%0ACe65HHGlsVIKqjwDLWgeWZCmEbHu/gcdZfb2B+v6KcXDJb90EM4Mjb/wxIPt%0A0frQbzPW5Zu3v/y7+lYPrhRmQmh4EXulP8n1s8N0+enn4Rp5gLrA9sknsS63%0AD1NtuaFplOEG+59l/7dRPzKz/TtV9SfktGFmJ7GgxfxOg3H/D160mLp5IjRP%0AvhS4Dd2qClwZPiPV9660/sdC47Nru/Gi24msqGXpief4bsS0fi2OX6lqfytW%0A55dEj292jp95rtlw3OJ/hQZt/VjEN8HprBidv4McD5ew+siJtikfJm78Ghpu%0A3f/UpEGbFJX/tQzfy0al/wWHpaJ+rfavRJOGvYz/5ITe3V0ilaM+kbD0sFz6%0AfzoaX+5IiZV6x8W0/eNYfiLn94MkuaQh34UP/hm0SRsqCKdx+70Pnx+UBaZP%0Ax+WRDWyOXEaG3Gkzc3BGfp7tYi+WpHk6y6T/y78Lc9TxgZ12dboXN6occDi7%0AMLOxjbetpwLlZeL3QQ/Ej0/QUFkKx8VOTErB21Rb8EqGPL+IlanHEfNP3VTn%0At0vIb8TY6hKG6+O7Ui8TMmvw1ONTrr7EPa+QB9e8H5M97Rj9sAav91+8H4oN%0A+qzIgdfOi6sxyxcEB3qWdzB+LTvwOw3V/V/w7VVjxBWFg779Qo50wBH98EkH%0Aw4iTWmUP/pVfsNrZwa5/F77gC1dfh1ArTWdVvnBMKnd3EV3F4TKPSQdw7RW3%0A0m63dEAfxY1qB0qrmjH8SZQONA51fsGJEXENPRUZqBtawaTUL3PapuCfdSlX%0Aau2Ur5Rjs/7l/avhn214nlwI/Fb3H89MH5qr5Ct5Lkx82cH725FXWrPrhrHu%0AHcXlqNveyVJPBJO44XyMucdOtIxNoOXqAL6GTlqn0Dq+htn+FvxeXgJHTTte%0ArorS/n06VIbcd0XPDPpbfoOjrAaucQ923V0oMqkHI7H1kwnnkAfeiXaUZmcg%0AM78OQ0siJlvzYua1I7Z88/aPmFc36E3t+pnRW360tIq/sfrtNZqiH48w2v+s%0A+r/N+jEqXyvZ+hOEcvy9shsKBuJhnjSY9f90KQjwYmvKhbPHY7dLECrQuybi%0AWYLPsNs9vtuhW78Wx69Utb8ZO+eXRI9vdo6f6dm56pXii0+wEh00WsQ3wems%0AGJ2/ZeqFLxHPr8iPB33C1silUMBv3f/k7YtMGnI7ZuB/fztU/6mqX6v9K5Gk%0AYa/jv1O3ZrA55JTKkfbDyU9YeNEg1UE+OufX8KhSXU/T9re5/ETP7wdJwkmD%0AkHEadQOf4ZNO6sFM+qSUpW6v9aJCyv6EzMsY3dqQDoKRt7DMH0/yRzxjXj2w%0ADlHaMdTx6kF12BnuiCVSEOcbvxa4kmE+v13KAdMnwvP5HUZcF5Bj0rDR8m+9%0Ag8+7gKn5VXjXlzHz9AZKdE4QegSpg/75wS/tFP1orq5EZf09zHzdxcc78d2e%0A/n3Qi/WBat1xFT3LoZOIWp/bGGuKvJJ7GLY/40Qeco6Hr1jJDA/axaeUK3VW%0A5ctXVu983MHaPy0oyU6Xgo5aPF7YwYaU6atJrZp0vG0NXyk8XtWOflcNspXx%0AwZNiDjpm/FjrrYw6aZqXH9oOm/Uv5FyXgqsv6KsO3t4M9H/NlUx5/9gN7B/K%0ANJnn8eTfLbxpVg9kja/8WLyvPh6RrOBJqyW7GgPT85gba0dOdfikpTdPxd8r%0AEfunfMLcnWwNXVkVSrrxWTpWXLfZh7Si60cZlunA7UkPfLu7UmK5hY+9zrj6%0At1Zs/Zu3f8S8OkGZMjyF62fGaPmh8dIJyznkxeZove7VRN39z7L/268fvfK1%0Akq2/4PPekzfUADseVkmDWf8XTtVhwC1Kx0g3xh53oCY/fFck2aRBZuf4bode%0A/VofH1PX/kaszi/JHN/sHD9D05bel84xkUFjaJxBfGOX2flbyGrC651p3Dwp%0AIK32KTbXHuFcYB2s+p+6fTpJg6b+U1W/VvtXYknD3sZ/aZdHsC2fezIaMT75%0ACq+m7yBfqEL/+jt0RN110Wt/u8tP9Px+kMSdNOz61Cu4Pt8uvi2Poc0Rvp0q%0AHK/Hi6119Ndk4Fj9KETvEH7XPF6kTGOaNER26tL7i/BLB0F1fPCgEx4feVAy%0An98uIes0is86UPXHQ7z7Kl+pUjNZK8H62ZzvRdOFClRe6cSbNR8+Pyw3zSjN%0AOB5I6z/dEdezt7WDX40POhU9WBX/Qb1U94LjAZZ2pHaIvpJ4yLc/noN2dPnH%0AytoxsbYDvxR0iCtLWNteQ2/omcPY/qVl56RoVn6oHBv1L2QW4/bUBr68uBo6%0A6Oitn7L8wJUk+cqjo3sh4uW1PUkastJQ3tqPLmcuhKigKaemG2PuNWyI6jFk%0ARzqG+F40hMpQ7jRoDrJCZhFqr12M+26bfv1k4rdHn+GV+mfjhXOorHPh9dq6%0AFFTFfyVfv3z7QZF+UJa69bNimTRkNeCVqB7H9cbr2Y+gMSjZ+gsFNa3hxzvs%0AskwaTPq/Ml16Dsr/uIOh91JyI35Ed4V6/kxF0mDn+G6HUf8wPz7ubftbnV+S%0APb5ZHT8jpt3DpMHs/J3mHMLWpwc4K29vVjMmfR/gyleXY9X/9LZPmzSksn6t%0A9q/EkoZg/wnPE9m/kov/lP1FrtviLkwPtqF7Zgg1GU0YD3xIJWJaw6TBevmJ%0Ant8PkriThreuUuUKblH+rxHPwqnTZKD26To2nl1Bw6godf6a2GlSnTSEgqLk%0AOo0e5ZlLzZVPM0JWCyb9y3hQFp5WfuZzd6ELhQk2/K/yM6OL9yJOOlZqBrzw%0ADv6uO045Ma2KGLmcqWybb7IFv5qUfRi3P56Dtl75QlomcvLy4exbhjjVhlOB%0AcXr9SyvcP9Xb72+NHr8wKF+PXv0Lxx24NSntYzN3UK69CqSzfpH7h3rl8fmV%0AcCC4N0mDZp20J61MqX42tjB9rw7lpepdoPrBFdOkIRGG9ZNej5c7a3h0Pqp+%0AFu7G1T+N699e+yvT6gW9KVo/O6yShpzWt/CtPMK5QHBgh9X2x1M/VpKtP/mu%0A450PUlDTsgd3Ggz6v3ZaZVxaDq6MrMH3tlW5aJGSpCHO47sRs/5hfHzc2/a3%0AOr8ke3yzOn5GTLuHSYPZ+bui51/4d75ha2tLImJn14fXzYHH0ayOvzrbp308%0AKZX1a7V/pTRpSFH8J2TdwFvxGZx1zzDlKkLT2BRaK6S2DCRpEdMmkTRoxXN+%0AP0iSeqdBT1rlI6yuvcO7tS94ciH2FrNwJtGkQT2oxtyeGmvSvBORRKfJuIA7%0AL3tx9XR4/jN3PsAvHdTlx0+002aezIv5qo+QcVU6aS3hXml42uwbE9j9eCfm%0AhT7d+YXTqGy4iorc8LTy9ukt30zZg8/YfdOsfDFIb7z8ws/G8A10zu5IWW74%0AVtph2n6zxxeMk1L75aeXdsG98zni6xB6jydlVbswdKdWmT+eF/10y7dR/8LJ%0AavTMbWB90oWyqM+9qf0/8vZ66b3F0O11QajEE48fu9KJxudT7e7GHvTldw9q%0Ab9/H/RvnbSWLQZYnraK7Uru8RlPoxfE01A56U5o0mNbPsSa83vWgtzLcPjnt%0A01JQaT+pNa9/++2vG/TaXL9E20fLNCgUCqQT/i7c3WdjxgXpP56UuhdhE3k8%0AKZ72FYQLGFjfloJr42UYSTRpENLl/XsATWfC4zOvjYe2Q/dFaOd9vHzgjDk+%0AmTE6vmvpHX+1zPqHTP/4mLr212N1frF7fDNidfyMmNYsaTCIb+wyOn/LgXjn%0AvA+Tt4pDX+D5Y8SLzWGneicggaThXM8ydl7+ob6In8L6tdq/Eksa9jj+E2rw%0AdGMKXV1vMXIlDecfTaOnsx9fJ1pi2yKBpCHZ8/tBkvKkQZ6u2+2HX/6OsM6V%0AKvmvAk74PBhtqcRZ+ZnzvECmbFXpwRdhPkgVr3yyTX5R6RsiX4RJptPkoW1K%0AlBrsLpxlJShzyi/abGPmVmHkdPntmNmWdp7VR6iM6DQn8MdLL7zT93HlnLR+%0ANW14ubKNj3ejgjLD+XPQMinCO9WNuvKzcDj/xFtv+EUfu9Iv9MEjjqHxRGzd%0Ay9KqeuFZXsSiOI2bmmf1Dsv2W70oaZw02CxfOjjfmvkGz1DsV0vUF6Gf48YF%0A+ZOILconERfulgTmO446vU8Kttsr36r+hePVeCwt78vbO6gpCn+6rSA3Wz3o%0AK/1fKld+ke988EWxHcy61Bf55P0n50zwPQ+V661O0pDdgkn5ZHDP3sk2yPKk%0AdaweL8QNvJWSLMfZMtTefIoXH5dSljRY149av1tzavvIn4wcX9uB+57D1uNz%0A1uWbt7/8nsCJ/CIUFUk6JuBf6YdT/n9hTuAZdHvrl3D7WCw/OF2a/BWe3Xnc%0AztevE+MXoa223+b+YVh+aupPllHZi1VROkac1N9GMwknDVIydvv9Nr5I+7d8%0A/CmpbEDfB+l4JAV9alCt+eSqtP+qx5dvoU+a2mV0fA8yPv7a6x/Gx6/UtL8R%0Aq/OL3eObEevjZzqycwP7vPIi7CTalWPAaWRr/1aFQXxjl9H5W8iWH0eSAm1N%0A0pklJZ2+f3tQJvcfm0lD9CdXXwU+uZrK+rXavxJLGvY6/ivE3QU3JiYm0V0i%0AIKdtEuPjE6FHxaza32r5yZ7fg2UeBHuQNPwqBWc+rDyqNBififLb41ja3FE/%0AXSVl8nYzRSH7HDpCfxznEyZ6LiE/sMMm22lkabk16Hq5AM+WdPLxuDH+sC5U%0AfpBwsh6jHhFfZ1zKzhgx7kQFbkvrt6L88Ro3Xv91GfnR73SYzS8vf0xe/jdl%0A/rEHF3EqjkcEZPIVdblzrr1qRmHUspXxaVXok68YzHTE3HY9DNsf+iTj2/g+%0AuaqMs1F+TtMYtqQD3nXNHYkg+VnDpoHpwB9fWsbUk4aIOlb/eNF86I9LaT8J%0AF2RWvln9C7kdmNX7pF/o9r/c/79isDXwyUBxHQvPW1FicsVL7/ay8tzs7ge4%0A4vwT/9YnrTTk1/dhZnUL30QP5p41o+rWVOqSBov6kaeR67f75Uflj+fIn+yb%0A7G3AGZtXBO2Ub9b+weNnzPyaZ2btrF/C7WNj+fKJsabfg523rTgZGBbNbP+z%0A6v929g+j8lNVf8LJGjxxi1jqqUjoZJzM40lpeU48CBx/RO8KZkdu47wmOAz+%0AcTf5j6epx5erusdwM2bHd2W8wfHXTv3KTI+PKWh/M3bOL1rxP55kfPwMfrI7%0Apn78kV+UMopvguOtGJ2/M+qGpZinH79p26ywEwv+ObjypOOrraRBXX/5j7tt%0ArMzhuSvyj7ulon7t7F+JJA2yvYz/5EfrG19J5W6NoUlqc6H2Kda2tjDXGUwa%0AzdvfzvKTOb8HyzgIbCcNdgknWzDlW8FDzfecaX8JJ6pw//1XiCtTuOVgO5B9%0A8nfAd2baD9yBilRsn8Tl1g/A/VXEp2cNMRdD7FKSBr8PO/LnnD39qGY7UIod%0A1vO31f4l34V5rXwK3YfdBJIGOhhSnjTIL6f4TJ6HpP0hpGWjuK4D9ZpnFInM%0ACMJJdExv401z+LleOjjYPsk5VdOCxorcpG73C8dzURR8RKMoN+LRHaJUOYzn%0Ab6v9S96mvNDjTQU4kWDiTj9WypMGIiIiIiL6uTBpICIiIiIiU0waiIiIiIjI%0AFJMGIiIiIiIyxaSBiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjLF%0ApIEOnNPVbfjTdQVF/OMvPwTrPzmsPzJz1PsH9w+iw8t20pDbMYPv37/H8Ps9%0A6K08GDu/kNWCycD6yH+Z2q/5y9SCUIaef30YrU9sXYu73JptnkLrr/GXY7Z+%0AqbDX5e8HQUhDceMjDPa343yW/XW3275C0R24/RO4lhk73VFrn7KHS/C9aIgY%0AZlX/ZvVn5aD3T7P1s7v/J9p/D4JUtI8gZKP63hRWtnxqXYkjcB6gNv7Rku0f%0AB71+rY4Ph3n/IKI4kob0rFwUFBRIitE57cfSk4uB33k4kUAAsRfMTnrJJg3p%0A2afV7a18IB0UmTQcNEwa4qeXNFg5qklDKvb/gy4V7SOcvIlp/zIGr5SiUK6v%0A/BwcO0BtfNgd9PpN5vhARAdf3I8nCUImWib8WLxfGjm8uAvuXTfuFIUPFunO%0AYWyIo7giHUDUoO4rBluv47nbC3HLg/nhFhRrDi7CiUq4RuewtiFCXF/CZO9V%0AFMZxC1NI/wNju8t4UCbgePNr+N1dOBM4oKrL38HzW39geEFd/txQE4oy4lu+%0AkOfCnE7QYGv7TNYvFazKFzKL0Ng3haV1afu8y5jq+wNntNufXY6O4VmsfBWx%0A5VnE64dO5KWp4622z6r95d+VvWvwDLSgeWQBXlHEuvsfdJRlhabPc81qrua+%0AQkNU3WQWX8PQ7Bq2xA18GruF+u65UNBr1b5CZS88fn+o/NByFu+jONhHDnj7%0AWNWfVf9NO+XEo6llqU22sDx5B629nyKSBrP6t1N/aYX16JtektZtB76tNcyN%0AdqBcczUx2fo1658yq/qxYmf9jPZ/mVX/tdz/TNovuP8NtDRhJLD/Kf1b275W%0A9W/RP1LR/02T8j1sP6HsIf51P0PvlBeb7h446wewvOXFbFcF0gPbkOzykz0/%0Ame5fNtpXmW6P6tdO/WVI/at38pM07zdsfVnERM9l5AfPDzaOD5b7h43zj1X9%0AENHeSl3SIJzG7fc+fH5QFvidjssjG9gcuYwM6eCg7vTfsDbTh+aqUpTVujDx%0AZQfvbxcEpj8G57Mv8E51oa78LEqrW/Hi323Mu4oilmNGEGowtDGHW6el5dU9%0Aw7fpdpwIHJjU5W9jdboXN6occDi7MLOxjbetpwLj7S3fPGkw3j51GuP1SwWr%0A8ku73dhZHsWNagdKq5ox/EmEu9sRmDcTvw96IH58gobKUjgudmJSCm6m2vID%0A463az7z95WHySUv0zKC/5Tc4ymrgGvdgVwpMigLj07MDd7MuPsFKzEk1D7fe%0A7cA73S21TynKL3dLyYsnKmkwad/MHJwpLkbxxV4s+WfQWSb9X/5dmBNav4Pc%0APjKz+rPqv4KQhfrRrxDnHqG+Qqq/Kw8xtuyNSBpM69+i/uT+0/jyG7xvXKgu%0AKcLZygb0vvfiY7faH5Qykqhfq/4ps+pfVuysn1nSYFZ/MvP9z6r95P4tYmXq%0AcUT/nroZPH6Z17+d41tS7VPZg3+3t7G9s4Nd/y588v9lX4dQK5Wx1+2nBL0b%0Ab+G6UIUHc1v40HMJ59rGsLUxhJoULD8V5yfz45tF++5x/VrX3ym0jq9htr8F%0Av5eXwFHTjperonR8Pa2un43jq/n22zn/GNcPEe2PlCUNspMtE9he60VFmnSQ%0AybyM0a0NPHNmBOaTd3q/tJOfCE1fIp1Ed8evIVM5KFWid82LvurwgSTfNY/d%0AyRZkaQ4uiQotvy0nNKx6YB3iyKXAeHvLN08ajLdPO+2PIAfdrnm/dJAPr9/x%0Aqnb0u2qQrdR/hbT9Ioad6aHx8vr7Qu1jvX1m7S+TT1q7k62h+hRKuvHZP4Hr%0Ax6PqsvS+dOKJOqmk1+Olbw2PKsPDavrXo5IG4/YNOqi3z63aR/5tVn9W/Vcd%0AL7dvmjqvkIaLQ18jkoYgvfoPjTOoP0HIlZJGPz7esR9ExcOqf8q/7favZJgl%0ADUG6/ddy/7NqP6vjl3n97/nx1ShoLD4VWP+9bT8l6PX24zdp3gtPPBi/fgxC%0AQSc++l/iagqWn8r60+8fFu27x/VrVX/BMrUq/l5J6Piqv/02zz8Wx3ci2lsp%0ATRqE4/V4sbWO/poMHKsfhegdwu/Bx0OUnT7ymXPludn3t5GrHBScGBH98O0E%0ArqAoV1V24Z91KeOD8yRKb/ml9xfhf9UYGG9v+eZJg/H2aaf9EfTWL3K8vP1r%0A6KmIWv/A9tvZPrP2l8knLe1BXn5co/baxYhHuJTheicV5XnryMeftM/kW7Vv%0A0MFNGszbR2ZWf1b9V699jd5pSCRpkBW2TmJzx4vFmXGM9j9Am7MoFLAky6p/%0Ayr/t9q9kJJ402Nn/zNrPun+b1b9V+cEykmWcVO5t+ylB7/oALkhlKUHvtcxA%0A0Ku2Q7LLT2X92e0f8Ry/kt4+i/pTyqvpxph7DRuiuv07vt2Y40fiSYP5+tut%0AHyLaW6lNGoQM1D5dx8azK2gYFbE+UBN+nlRnp1cOChFJgwdDDcErKAH5J0Jl%0AJMPqoGN3+UcuaQi1j/X2mbW/LPqkZUT3pJLRgDHfMh46wsOqpPKOctKgZdV/%0A9do31UmD3P655VfQeucv9L+YhWdHxNTN/JjpEmHVP+XfdvtXMvY2aTBrP+v+%0AbVb/VuUHy0hW3EFtitov4aTB5vJTWX/7mjTY3T6r+suUyt/YwvS9OpSXqtte%0AP7iy90lDYP3t1g8R7a2UJg2ytMpHWF17h3drX/DkgvoohEzd6SMfbym9txj1%0AeJKI51fCtydTyeqgY3f5Qt5tzPun0Xoi8qBotX3aac3Iz47W3r6P+zfOx33b%0A24ze4xFZ1S4M3ak1fzxprEnzTor19hm1v8xuUKB/UilCl3sX/w43oPBYBo6f%0A+QP97s34k4YzySUNP6p95N/mQY15/w2Of1anjk/48SSD+pPfYcnMOo4MzYuX%0A53qWlf4RfKY5GVb9U/6dTNBpl9H+r6Xff632P6v2szp+mdf/Xh9fg4yD2r1t%0AP+ukIbnlp7L+9iZpSHL7rOqv6K603NdoCj05kIbawch3opThNo6v+ttv5/xj%0AL2nIPJmH3KzIcw8RpUbKkwZBKEa32w//2mOc15zA1J1+G553fWg+H3zRaQez%0AruCLtMfhHF7HtrsfjdL4suobGHJvYaEr/CJoMqxPuvaWLz9b/2J7E2PtZeon%0A7wpOIzs9eFAz3j67hOwWTO5K9XtPv36Tob6I+Rw3LpSi9EILRpZELNwtUcbJ%0A7aq8iPahF1crgi86f0Pki2jW22fU/jLzk3I6snPl+gy+KDeJdk39ytNkX+jG%0A7Ndd+Hd3sbXYB1f/YvxJQ9Z1TPg8GG2pxFn5SmFedsR4Kz+qfWTm9Wfef9UX%0AoTfUFw3lF6EvR74Ibaf+lekM6k9tdx+Wnt9EjaMIReVX0PvhG9Z6q0LzJsOq%0Af8qSCTrtMt7/revPfP+zaj+r45d5/e/18TXIOKjd2/azThqSW36y9WfVP2wf%0Av/aofi3r75jU78UNvJWSXMfZMtTefIoXH3X+zovh8cFq++2cf2zUT347Zrb9%0A2F19hEppvbXjiCh5e5A0/IqWSR9WHlVGDVeDzlFX4JOd4joWnreiRHPwkz9p%0A1zn6AWub39RPEvZHfhI1GXYOOnaWLx/8zt4YhdsrYtcvBcf+RXQVBw/65ttn%0AR5pzCFu7H+AqTM12awmZxWgamMaytO7K9j1pQKFm+4Tsc+gYCX5S8BMmei4h%0APxDw2N0+o/aXmZ+Uc+Ga1flkX6B+Q9NlZOFUfg6OSwnJb30ebDytDcxv86Qi%0A9d/y2+NY2txRy4/zSviPbB+roMqq/6bl1eHxzCo2A59cbXyg/WStzfo3qb/M%0A0mYMvVvBxrYPO1seLLy6gyqTK/LxMuufsmSCTruM93/r+rPc/0zaz07/tqr/%0AvTy+Bpk9nrKX7WcV9CrTJLn8ZOrPqn/YPn7tUf1aJ11pyK/vw8zqFr6JHsw9%0Aa0bVranYpMHg+GBr/7A8/9ion5P1GPWI+DrjCn3qlYhSJ+6kwYpwsgVTvhU8%0ALI/cYfV2+p9JqrbP8XAJOzPtoedQDwq722fU/qkgn5BO5stXp4rgcN7FlHcL%0ArxpP6k67Vw5q+xARERHtpZQnDfLLSz6dvyTKpMGaIJxEx/Q23jSHn3s+KOxu%0An1H7p4IgVGPwq3x1dweix43x+7X7Grwf5PYhIiIi2kspTxqIiIiIiOjnwqSB%0AiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjLFpIGIiIiIiEz9UpNf%0AyKSBiIiIiIgM/XKTSQMREREREZngnQYiIiIiIjLFdxriIGS1YNLvQW+loPzl%0AY7/mLx8LQjHuL/rxqjEjNH1l7xrEkUuh32aKu9z4/v27wu+fQuuvkX/p2Gp8%0Asi6PiFjoKpa2IwutYyLcPZXK8CvPv2GmPTdm+nglsv5lD5fge9EQ+m1W/0RE%0ARES0d5g0xGEvk4b07NMoKChAQeUDuHWCaqvxyar4ewWex1XSdpTi4eg83o00%0AIE1KIG5M+vDiapruPPFIZP2ZNBAREREdDLbfaRCEIjR0NuNcTnrMuFSMtyOj%0AsB69k5/gFb9h68siJnouIz9t/4JGIf0PjO0u40GZgOPNr+F3d+FMHEmDcKIS%0ArtE5rG2IENeXMNl7FYXpkesv5LkwZxJUm40XssvRMTyLla8itjyLeP3QiTyb%0A9ZPvmsP2aL20HZcwOvECL8ZdyBMKcOfjOh5XBbbRonx5ez0DLWgeWZDaSMS6%0A+x90lGWFxitlmKx/2iknHk0tY0PcwvLkHbT2fopMGkzqn4iIiIj2ThxJw2nU%0A981jfXMZb3pig/9kx1sRhFNoHV/DbH8Lfi8vgaOmHS9XRbxtPa07fTRBqMXQ%0A121sb0eZ7kCuzcBTEGowtDGHW6cFCHXP8G26HSdsJg2CcAzOZ1/gnepCXflZ%0AlFa34sW/25h3FYWmV6ZLMGkQhEz8PuiB+PEJGipL4bjYicl1EVNt+RHTGcls%0AGoN/6iayczswNdKJ7sk+nBcq0Lvmxp0z0vbaKF/ZXs8M+lt+g6OsBq5xD3al%0AwL5IU7/G65+F+tGvEOceob6iFOVXHmJs2RuZNJjUPxERERHtnbgfTzpeeBGu%0AZ7NY31jGayn4L48K/pMdHw/5kRq7j//IQemp4mIUR8s/gfQUBJ7BpGHXF05I%0Adnx+TdJQKQXgXvRVh5eV75rH7mQLsmwE1VbjBSXAFzHsDNdnSbcbvvFryLSx%0AfULtILbkK/eVvZj+6wJuTIyhMb0OI98m0ZwlJw3W5ctJw+5ka2h7hJJufPZP%0A4Prx8PKN11+uH7l89VEoQUjDxaGvEUkDEREREf0YCb/TcKygFnfHV7Ez1qQb%0AdCc7Xk9OTTfG3GvYEINB+e6BCSqDScNbV2koIWl85tEkDU6MiH74dsJJxfbO%0ALvyzrog7HYknDXL5a+ipCA9XnvuPKt+I4HiAJU8fqhtfYao9B85n0/jT0YxJ%0AcRhOaX475cc8jpVZhNprF1GcGZ4nnvWPfqeBiIiIiH6MuJMG+QrwCUcjHrxc%0AhHf9A4avn0WaNuhNcrwRIVMKKje2MH2vDuWlalBeP7hiO6hMxeNJZqwfT5KD%0AYg+GGjR3OWRRdzpSnjS8v20vachpx4xvFK477zFySYDjwQwGml34sNwDhzS/%0AnfKjkwY9TBqIiIiIDh/bf6dBENKRU3EdPeNL2PRKwX5nHQq1j50kOd6KUHQX%0Abv9rNGWo88jJR+1g5DPvZvbr8STjpEF9/Ob5FfPHsYS825j3T6P1hP46GY03%0AfHxorAkZdpKGtHq89L3FyMgsHjoEnJQSgvEnfVgNJAV2yreXNBitv1o/z+rU%0A8vl4EhEREdHBEceL0JV4tPABI39ewpms2CA02fFWhGP1eCFu4O2dWjjOlqH2%0A5lO8+HhwrkRbJw3H4Rxex7a7H43nS1FWfQND7i0sdDlC0yvTpUvbub2JsfYy%0AFMqfKC04jWzNF5aMxodeVP7Qi6sVUvm1Lkx8+Wb7RWhBqEL/+hzevXuLm1JA%0AL1wawfTkJDZeNip3guyUbytpMFx/+UXoDfVFa/lF6MuxL0ITERER0Y9h+/Ek%0A+U5BRuAqv55kx1uRrzzn1/dhZnUL30QP5p41o+rW1KFJGpRpTlSic/QD1ja/%0AQfQuY6q/CUVRdSLX09kbo3B7Rez6/fD7F9FVrEkaTMYL2efQMRL8pOsnTPRc%0AQn7UJ12NyJ/E7XJL83lHUCcnCeUPsSiK+NJfHZ7GonxbSYPJ+qfl1eHxzCo2%0AA59cbXwwx6SBiIiI6ADgH3cjIiIiIiJTTBqIiIiIiMiU7XcaiIiIiIjoaOKd%0ABiIiIiIiMsWkgYiIiIiITDFpICIiIiIiU3yngYiIiIiITPFOAxERERERmWLS%0AQEREREREppg0EBERERGRqSP5TsPp6jb86bqConRBd3wqZJ29ivvP3+OR0/4y%0Azrpe4nVvG87npOmOJyIiIiL6EY5c0iAIaShufITB/nacz4o/aRCK7sDtn8C1%0ATON5T1x4gDnvCsa6/0Bptv1lZObXoGPoI7xLI6jPZ+JARERERAcDH0+Kk1XS%0AIGRUoX9tA+PX85AmJJCUCNmo7lvC5lgTTiQwPxERERFRqtlOGgShCA2dzTiX%0Akx4zLhXjrQhCGXr+/YrB1ut47vZC3PJgfrgFxZrgvbJ3DZ6BFjSPLMArilh3%0A/4OOsqzQ+DzXLL5//67w+1+hQROUB8sfaGnCSKD8uaGm0CNMQmUvPH5/aP5Q%0AOYv3UawpJ7tpDDvLPXCkxQb8GYX16J38JK3bN2x9WcREz2Xk60wn5LRhZseN%0AO0Wx44iIiIiI9lscScNp1PfNY31zGW96YoP/ZMdbUYP6b1ib6UNzVSnKal2Y%0A+LKD97cLQtPISYPomUF/y29wlNXANe7BrrsLRYGgPj07FwUFBSi4+AQrukmD%0AiJWpx7hR5YDD2YWZjW1M3Tyljs/MwZniYhRf7MWSfwadZdL/5d+FOcjQlCOv%0Aw86LqzF3GQThFFrH1zDb34Lfy0vgqGnHy1URb1tPR0ynTluOv1d28bIxsQSL%0AiIiIiCiV4n486XjhRbiezWJ9YxmvpeC/PCr4T3a8ETWo90tB/InQsJJuN3bH%0AryEzEKDLAfvuZCuyAr+Fkm589k/g+vGoAL70vhT46yUNUvltOaFh1QPrEEcu%0AhX4r01k8nvT7oBfrA9W646JV/L0SU75MEPLQOefH5I3smHFERERERPst4Xca%0AjhXU4u74KnbGmpAedVU9FeOjqUG9D6P14Wlz2qbgf38buYH5lTsNmiBcyCxC%0A7bWLEY8wKcMNk4bI8kvvL8L/qjH0W5nOImmoHfxqmDTk1HRjzL2GDXEb29vb%0A2PHtwveiIWa6UNLQ+mvMOCIiIiKi/RZ30iB/feiEoxEPXi7Cu/4Bw9fPRjyK%0Ak+x4I4kkDUb2MmmoGfDCO/h7zHAh04mRjS1M36tDean6aFP94IpB0pCPOx+k%0ApKGFdxqIiIiI6Mez/clVQUhHTsV19IwvYdMrBfuddSjUPPaT7HgroceHNI8n%0Ald5bjHk8ac+ThjPmSUPZg8/YfdOMY1GJkFB0V5rvNZoy1OFy8lQ76DVIGi5g%0AYH0bI5f52VUiIiIi+vHieBG6Eo8WPmDkz0s4o/P3DZIdb0UN6rfhedeH5vOl%0AcFzsxOT6DmZdUS9CGyQNctKSnVugeRF6Eu3y/wtOIztdCJRvI2nIuo4Jnwej%0ALZU4K78InRd5NyD9Qh884hgaT0Ruo3CsHi/EDby9UwvH2TLU3nyKFx+XdJOG%0AjMperIpSYnIy/noiIiIiIkq1OJKGdGQErpLrSXa8lWDSMOoKfHJVXMfC81aU%0AaK74mycNuXDN6nwy1b+IruI4kgYhE+W3x7G0uaPOP34t4utJ8lei2qZErL1q%0ARqFme+U7C/n1fZhZ3cI30YO5Z82oujUVkzQIJ2vwxC1iqafC1rseRERERER7%0ALeEXofebXlB/UAknqnD//VeIK1O45bC/vrn1A3B/FfHpWQPyA38fgoiIiIjo%0AR7P9TsOPdpiSBpmQlo3iug7Ul9pf31M1LWisyOUdBiIiIiI6UA7NnQYiIiIi%0AIvoxDs2dBiIiIiIi+jF4p4GIiIiIiEwxaSAiIiIiIlNMGoiIiIiIyBSTBiIi%0AIiIiMsWkgYiIiIiITDFpICIiIiIiU/zkKhERERERmbJ9p0EQinF/0Y9XjRmh%0AYZW9axBHLkVMZ6S4y43v378r/P4ptP4a+VePrcYn6/KIiIWuYmk7stA6JsLd%0AU6kMv/L8G2bac2Omj1ci61/2cAm+Fw2644iIiIiIDop9SxrSs0+joKAABZUP%0A4NYJqq3GJ6vi7xV4HldJ21GKh6PzeDfSgDQpgbgx6cOLq2m688QjkfVn0kBE%0AREREh0FKkwbhRCVco3NY2xAhri9hsvcqCtMjg2chz4U5k6DabLyQXY6O4Vms%0AfBWx5VnE64dO5KXZSy7yXXPYHq2XtuMSRide4MW4C3lCAe58XMfjKrUMq/Ll%0A7fUMtKB5ZAFeUcS6+x90lGWFxitlmKx/2iknHk0tY0PcwvLkHbT2fmLSQERE%0AREQHXsqSBkE4BuezL/BOdaGu/CxKq1vx4t9tzLuKQtMr0yWYNAhCJn4f9ED8%0A+AQNlaVwXOzE5LqIqbb8iOmMZDaNwT91E9m5HZga6UT3ZB/OCxXoXXPjzhnB%0AVvnK9npm0N/yGxxlNXCNe7Dr7kKREF5X4/XPQv3oV4hzj1BfUYryKw8xtuxl%0A0kBEREREB17cScOubxvb26odn1+TNFRKAbgXfdXhYDnfNY/dyRZk2QiqrcYL%0ASoAvYtiZHhpW0u2Gb/waMjXlGxFqB7ElBfhnKnsx/dcF3JgYQ2N6HUa+TaI5%0AS04arMuXk4bdydbQ9ggl3fjsn8D14+HlG6+/XD9y+eqjUIKQhotDX5k0EBER%0AEdGBZ/vrScGk4a2rFMXFxYrGZx5N0uDEiOiHbyecVGzv7MI/60JuSpIGufw1%0A9FSEh+e0TcWUb0RwPMCSpw/Vja8w1Z4D57Np/OloxqQ4DKc0v53yYx7HyixC%0A7bWLKM4MzxPP+vOdBiIiIiI6DFL4eJIcFHsw1KAmFCH5J5C+l0nD+9v2koac%0Adsz4RuG68x4jlwQ4HsxgoNmFD8s9cJglDZryo5MGPUwaiIiIiOhnoyQN8mdC%0Ak08a1Mdvnl8JP96jR8i7jXn/NFpP6Af6RuMNHx8aa0KGnaQhrR4vfW8xMjKL%0Ahw4BJ6WEYPxJH1YDSYGd8u0lDUbrr9bPszq1fD6eRERERESHhfJ4UmqShuNw%0ADq9j292PxvOlKKu+gSH3Fha6HKHplenS6/FiexNj7WUolD9RWnAa2ZovLBmN%0AD72o/KEXVyuk8mtdmPjyzfaL0IJQhf71Obx79xY3pYBeuDSC6clJbLxsRJqS%0ANFiXbytpMFx/+UXoDfVFa/lF6Mt8EZqIiIiIDoeUJQ3KNCcq0Tn6AWub3yB6%0AlzHV34SijOgr7uk4e2MUbq+IXb8ffv8iuoo1SYPJeCH7HDpGgp90/YSJnkvI%0Aj/qkqxFBKEKXW5rPO4I6OUkof4hFUcSX/urwNBbl20oaTNY/La8Oj2dWsRn4%0A5GrjgzkmDURERER04NlOGoiIiIiI6Ghi0kBERERERKZsvwhNRERERERHk+1P%0ArhIRERER0dF0aJIG+W6IGb15iIiIiIgoeUwaiIiIiIjIFJMGIiIiIiIyxaSB%0AiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjL1y422Dly6cpVJAxER%0AERER6frl48InXKipZdJARERERES6fikpLYtIGIySBkEoQkNnM87lpMeMS8V4%0AK3qJgpbePERERERElDzb7zQIwmnU981jfXMZb3pig/9kx1vRSxS09OYhIiIi%0AIqLkxf0i9PHCi3A9m8X6xjJeS8F/eVTwn+x4I3qJgpbePERERERElLyEv550%0ArKAWd8dXsTPWhHRBSPn4aHqJgpbePERERERElLy4kwZBSMMJRyMevFyEd/0D%0Ahq+fRZom6E92vBG9REFLbx4iIiIiIkpeHO80pCOn4jp6xpew6ZWC/c46FB7X%0AJgPJjbeilyho6c1DRERERETJiyNpqMSjhQ8Y+fMSzmTFBvvJjreilyho6c1D%0ARERERETJi+tOQ0aGcbCf7HgreomClt48RERERESUvIRfhN5veomClt48RERE%0ARESUPCYNRERERERkikkDERERERGZYtJARERERESmDk3SQEREREREPwaTBiIi%0AIiIiMsWkgYiIiIiITDFpICIiIiIiU0waiIiIiIjIFJMGIiIiIiIy9YucIBAR%0AERERERnRvdNARIdPeuYxShG9+iUiIjrKmDQQ/ST0gl9KjF79EhERHWVMGoh+%0AEnrBLyVGr36JiIiOMiYNRD8JveCXEqNXv0REREcZkwain4Re8EuJ0atfIiKi%0Ao4xJA/0QBUXFuFx/FTfaOvBH03WcOftfutORfXrBLyVGr36JiIiOspQkDf/f%0AH426w4n0XGu5gc9L/8K7sRWy6lnH3XsPkFdYpDsPWdMLfs1o69+K3vw/M736%0AjUdB0VkMPx/Fv6sepf4WPy/hTvd93WmJiIgOg5QkDfJJcfj5Pygtr9Qdf1QF%0AAy7t//VEz/cza23rCG339PtZdD/4Cy9ejYeGPe4b1J3vRzqV34E3/gnczC+M%0Aa9x+0wt+zcj17Vn/in/GwvVvRG/+/ZJ28QP+H/4XcxczdcdbScvowX/jf/Aw%0Aw/78evUbjws1tTF1uP51c1+S4oPUJ/fKUdhGIqKDJmVJg0y+qtZ+u1M6MepP%0AZ+ZUvhO9S374l56gxuREoJ4s/Pj+/bvC719Cb+3BPHHIQbFM+3890fMF6yK4%0AjeFtDZ8kax4vRY6b6NDMH1lHss+PnaHxQWZl7IWSsnPKHYVgf+kbeKoMv9lx%0AOzRM5rxcHzNvkLZurNperx716sGKWYBykIIXveDXjFzXcx8WcOr/5KF/YCii%0ADaJFz5uW4cTc/0LnX3zB+X7Y76TBca4CFy9dweDQsGLuw8dQPeafOas7T1Ai%0AfTY4z5t2tQ/uV5/UHj+sjtupdpD2OyKioyKlSUPQ2+l3+O33Wt1pjcgnoM9L%0ASzaThvDJ4lT7xL6fsPaTUi9RQcPNidjkShkWCPpj6igQVGiTAqsy9kL7LVdE%0APzFKGvqfDsXMGySvo93AX93ucGKh1ks4uLLLLEA5SMGLXvBrJljfM+/nlMSh%0Ab/BpRDto6c0fVDv/v/h/807dcQfBfiYN8iN2evUXdPvPu/ji3VD6vN78ifTZ%0AH5E0RB8/TtU+wZsEEvJEHaT9jojoqNiTpEH2xfsVf/3dizNnS3Tn0ZJPOJ/l%0AE5AmAVCG6VxJjj5ZaH+r8xiMC/5fWobdK3jJ0t5J0N5ZiBY9n1Z00hC9jaHh%0Ayvap9RVdR+r4cGBhpwzt8FR59Lgvoo8YJQ0Tb6dj5pWF+kn0ehv2lcgATBZM%0AOoJ18EYOfgJ1oQ4LX+WNCcJ0+k50XctJbHCayL48gd7AlVl1efJ8gTsmoWRP%0AbaPg/PEmN3rBrxltnTffaEVxyX8p+612eJDe/EF6SUPaX/8TuPMg/fvfD6iV%0AAnb1MaP/wX8ro/4HDy7OK7/npPnVf3JgLwf4gX//06OWpQn6Q//XlB9ctjpO%0A809n/uD6WdGrXzs+LS3r1p/s/dyHUFLh/rysO79Rn/3Ue1PpGxHHAqmv7b55%0AGNFn5L5k1l+V+RLo51rB/hx9/IgcH+9+pN/3Lcsy2e/k4URElDp7ljQEWT2j%0Arj1J2rlrEH2ykIPqUNAVdTLTTqv+P3wl3erElwrBOtD+X0/0fFoxSYNcRwZ3%0AA+TgQj6pRtdRULAsO2XojUvWg55Hutsf7dX4hO786no/CQUX1n0lMgBT6yXQ%0A1wLBSGRwoplW8zum7wR+R9e1Mo9mnUL1HVhWsB2Vq7QR/VLT/w3axQ694NdM%0AsL7/vNslJfdnsfjJOODVmz8oOmlQkoNAoqAdryYNwH//pQ4P/g7O+zCQTIST%0AA/U9htikQZ4skBAEEpHohMBofu00ZvTq1w7PF69SX0vLK2hubUOXlCTI7+38%0A2XUPN262w/1pSRkvJ2d685v22ajjY3h/VwPuUF+O7q9K/9P0Ubv9XDOf/DtI%0Ae8yNlmj5en3fuizz/U5bFhERJW/Pkgb5ipv8lRy96bW0B/jok6Ke4IkneFVJ%0Ae3LQnoTC0wZOLJr/q+MiT84HVfQJ0OyEbZU0yOPlsuyUoTcuWVf/aIroI0Z3%0AGuRAK3pembLemiAiuD3R0wUFg6lgX5GFAqvovqITtJjVZ3DZ2nHy+mmXJZPL%0AjF6Wtv61AZ86nRRUWewDRvSCXzNyXb+bm0fxf5WaJgwyvfmDopMG+XfMPynI%0Ajw7wo38r84XuDqjvTMgJRmzSoClDmS78knT0uxbR88vT2KFXv3bMf3Qr9fXg%0Ar78xOTUTU49ByytruvOb9lmlr+kEzbpJg6Zva+eLo58bHSPNjh+Jlq/X9+2W%0AZbTfaecjIqLkpTxpWP+6hSf9gygqcehOq6V3glQO+CZBk/ZkoT0ZKuMOWNIg%0AB8XBwDj4fz3R82nJJ0SzxCg0XFMX0duqjo8+QZuXoR2eKvIL8jPv5kJ9Jbjt%0A2qRBDqZKHOUx88qigwi9oELLrI1j+kocwU5wnF7SoLc+0csyShpC00vrIu8H%0A2mF26AW/ZoJ1Lj9jH/y/0TTRw7V0k4ZA8K+110mD+khU8O6C/vzyPHbo1a8d%0AN9tvw7O+odxZCN510PPw717d+a2OS8Hjgfa4EN2Hovurdr+Op58brYtShsEx%0AOtnytX3fbllG+x0REaXSGfz/wnT9jNevfRcAAAAASUVORK5CYII=) - + + +环境变量: + +![ScreenClip](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAw0AAADrCAYAAAArFHriAAAAAXNSR0IArs4c%0A6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAEwySURB%0AVHhe7d15VxNZuDb8/jx1GPRAK/jIIMghIIgNjUHllQYFEdDQCg5NizKIILaC%0AgoACSlBoIBKBEkJc65w/n2/xnI9yvTVkqCQ1ZQBBLtf6rWVq2FW1966q+66J%0AX04XnEG0//zP/4wZRkREYfJx8njWr0REREcCkwYiogQwaUjOsarHWPYv41FV%0Atu74eBw73oo3BmWlcjlEREcZkwYiogQwaUjOj0wazvcuw/+mFS1v/FjuvRAx%0APRER6WPSQESUACYN++PY8Qt4tOzHmxbj5MIsaYimJBHLj3H+eHagbN6FICKy%0Ag0kDEVECmDTsj1QnDfLdBW1Zx1reKHcdtNMQEVEsJg1ERAlg0hAWDuzl4N2P%0A79+/K4LBefR4//JjVJ7vxbL/DVqUK/6BoL/3TWhe+bEhdXi4PHk++Q5B7PJj%0A5w8mAurjScHlxN5Z0N55CA4jIqJYTBqIiBLApCEsmBT4A8G5Mky+gh8RrEeN%0AjwjmA8lERKCvBvfhhMM4qDedP2Y54XUIzxs5jIiIYjFpICJKAJOGML3AXjtM%0Ad3xMMB++A6BOH2/SYDC/djny/6PuKminDQ4jIqJYTBqIiBLApCFMNynQDNMd%0A/yOSBp27CnrDiIgoFpMGIqIEMGkICwb22heKlc+ahoL1g5Q0hKdTptWMDw4j%0AIqJYTBqIiBLApCEsFNi/0byIrAnEk0ka5N9yAmLrRWiLpEEex68nERElhkkD%0AEVECmDSE6SUFB5WSRASSj+jkhIiIjDFpICJKAJOGsP1KGtQ7CuFPsAbFu1z+%0ARWgiovgxaSAiSgCThrDDdKeBiIgSw6SBiCgBTBqIiOgoYdJARJQAJg1ERHSU%0AMGkgIkoAkwYiIjpKmDQQESWASQMRER0lhkkDERERERGRzDBp+D+lvxMRERER%0AETFpICIiIiIic0waiIiIiIjIFJMGIiIiIiIyxaSBiIiIiIhMMWkgIiIiIiJT%0ATBqIiIiIiMgUkwYiIiIiIjJ1aJKGU1dG8Nm/gt4rNbrj7ThVch9v/DO4WZJ4%0AGQfJYdoe78aWQm8cERERER1scScNN9/68f379xj+t/d1p0+Vw5I0nCq5gd5l%0AP9649j6QZ9JARERERPsh4TsNh/Gq/VFNGs45m3C26krMcHmYPC56+F5g0kBE%0ARER0eDFpSLGDmDScvXAFl1s6IxIH+f/Rw/YSkwYiIiKiwyvlSYM6PPwI0+eB%0AG4HhwWBaHe9fHkH12XvS/1fQ65IfPVLnkYPtU66Z2PmVx5PU5anLkOYbiJ0u%0APG14HYIBvHadU/G4kx6zpCG6bvxR9WdYdza2J1iGEW3icLaqfs8ThmCSYEVv%0AXiIiIiI6WFKaNKjDwoG4NoAO/l8bKAeDZDmBqJED+UCyEHw/IiJRiEkapPki%0AplOXqyznrVqeMk4qM7hM7Trvd9IQXOeI5CZm3SLHq/PZ2x7tPEaCicPlG3LC%0AUK87TaroJQh69OYlIiIiooMltUmD5g6BlhwI6wXTahnaJMP4d2zSoJ1OLjsy%0AAagZWAktP9EgOxGGSYMc7AeSI71p9cZrpWJ7lDsMUsKwn48lBTFJICIiIjq8%0AfrmZX5jSpMEo8N2vpEGdLnzFPnY++0F2IuJPGgLrbVB3qdqe8DsM9brvOOw1%0AJg1EREREh1dqkwZlWGTAfPNtMMDdp6QhKviWr9Af6MeTAusaHB+cT/7dK9+h%0Asbk9wTL1hBMGzYvQ+5w4MGkgIiIiOrxS/yJ04Mp48FGacBC8T0lDYDnB5X+W%0Akha9K/N7nTQEly+LTgxCw6PqT1t34cTA3vZo1yFaudEnV6XEQR4XPXwvMGkg%0AIiIiOrwSThqIiIiIiOhoYNJARERERESmmDQQEREREZEpJg1ERERERGQq4a8n%0AERERERHR0cA7DUREREREZIpJg4Xy4f9LGnp1REREREQ/Nz6eZEEvcD7K9OqI%0AiIiIiH5uhncaSKUXOB9lenVERERERD83wzsN//Ef/0FERERERMSkgYiIiIiI%0AzBk+nqQ3MRERERERHT1MGoiIiIiIyNQvNXw8iYiIiIiITPCdBiIiIiIiMsXH%0Ak4iIiIiIyBSTBiIiIiIiMsV3GoiIiIiIyBTfaSAiIiIiIlNMGoiIiIiIyBTf%0AaSAiIiIiIlNMGoiIiIiIyBSTBiIiIiIiMsWkgYiIiIiITPFFaCIiIiIiMsU7%0ADUREREREZIp3GoiIiIiIyBSTBiIiIiIiMsXHk4iIiIiIyBSTBiIiIiIiMsWk%0AgYiIiIiITDFpICIiIiIiU3wRmoiIiIiITPFOAxERERERmfqlhncaiIiIiIjI%0AxL49niQIZ3DlTheuFAm64392P/v2H/X2JSIiIvqZ7dvjSYKQhevj21h5dF53%0A/M/uZ9/+/dy+09Vt+NN1BUXpe5Og7HX5RERERIdNXEmDkF2O9uF3+NcrQlz/%0AhImey8hPsx9YZTWNYXvtMc7HMc/PxGz7BaEY9xf9+P79u2JXXMfixF9w5qXH%0ATGtGKLoDt38C1zIjlyEIZej514fR+r2r+2Ta1+76CUIaihsfYbC/HeezwtOm%0AavuMypel5zvxcGwBa5siNtcW8LK7BrlCcsuL149sXyIiIjq6bCcNgpCJ2kEP%0AxPlHqK8ohaOmHS9XRMy6imKmNSJkNWBM9KC3Kk13/M/ObPuDScPkrTMoKCjA%0AmdIauN58wbeZDuTHEZj+yKAymfZNdv32evsEoQidc9+w+uoWah0lKL90H++k%0A5GGsKUd3+r3CpIGIiIh+BNsvQgtCJXrXtjB0MRwQnqhqxb3mChzTBLVClhNP%0ApWTCO9mGgqhgVxCO4Y+XIjx91UiLGScHPV8x2Hodz91eiFsezA+3oFgTHFX2%0ArsEz0ILmkQV4RRHr7n/QUZYVLiO7HB3Ds1j5KmLLs4jXD53I01z1ziy+hqHZ%0ANWyJG/g0dgv13XPwvWgIjbcqP6OwHr2Tn6Rx37D1ZTHiTotQ9hD/up+hd8qL%0ATXcPnPUDWN7yYrarAumBbTXffjVpeNWYER5W3IVF/xRuZAvK/927btzRvDOQ%0A7hzGhjiKK1IdCZW98PjDdyqC/Iv3USwtS63fHTy/9QeGF9T6nRtqQlFGuDyz%0A+gu2z0BLE0YC7aPMr3mEx2z7lPGZRWjsm8LSugjRu4ypvj9wJrB8O+uX55oN%0Ab5f/FRo0y7Azv1n7yUzLz7qMxzODaMgJD6t9ugHxWZ06XkoqGjqbcS5H/86Q%0AVf8+DO1LRERER5ftF6EFwYkRcQ09FeZBhJBzDROiHz4pmCnVCRyP1Y9CXB9A%0AtSZYk6lByzeszfShuaoUZbUuTHzZwfvbBaFp5KBe9Mygv+U3OMpq4Br3YNfd%0AhSIlaMrE7/KdkI9P0FBZCsfFTkxKwelUW36g/DzcercD73Q36spLUX65Wwre%0APDFJg3H5p9A6vobZ/hb8Xl6i3mlZFfG29bRavpw0bLyF60IVHsxt4UPPJZxr%0AG8PWxhBqNPVgvP06SUO+Cx/8M2iTAlVBOI3b7334/KAsMH06Lo9sYHPkMjLk%0A9cvMwZniYhRf7MWSNE9nmfR/+Xdhjjpeqd9trE734kaVAw5nF2Y2tqX1PxUo%0Az6r+5PlFrEw9jph/6qY6f5DR9slKu93YWR7FjWoHSquaMfxJhLvboYyzWj9Z%0Aenauchem4OITrOgmDWbbZ95+VuVHk+u/4Z9teJ5cCPw+jfq+eaxvLuNNT2zy%0AYNW/D0v7EhER0dGU8qRBlnEiDznH9R9RETKvYHTLi4EavaDKLwUpJ0LDSqQg%0Ac3f8GjIDwZsc1O9OtiIr8Fso6cZn/wSuH5eDpgr0rokYdobLlef3BeYX0uvx%0A0reGR5Xh9a/pX49JGozKD06jVfH3CsSRS8r/laTB24/fpHkvPPFg/PoxCAWd%0A+Oh/iauB8pTpDLc/MmkQMk6jbuAzfFLSIl9JloedbJnA9lovKqSAXMi8LJWz%0AgWfOcJKhzGf6+IpUv23hx2mqB9bD629VfxbzBxlvXx5c834piA237/GqdvS7%0AapAdR/kyofS+FDjrJQ325g/Stp+WXvnRhJzrUnL8BX3VkfV/vPAiXM9msb6x%0AjNdS8lAeSB7s9O/D0L5ERER0NMXxTkM4aRAuP4O4vY1t2XRHXC+DCkIGroxs%0Awvu0NvTYjjpcDloin8nOaZuC//3tUPnKnQBNECM/7lJ77aLyiIdeUqPMP+tS%0A5heyWjDpj3z8o+zhUuydBoPy5d85Nd0Yc69hQ1S3fce3G5pfSRrWB3BBWpaS%0ANFzLDCQN0cGt0farScOuTy3bJ5X9bXkMbY5j4WmO1+PF1jr6azLUK/reIfyu%0AefxEmSaOZ95L7y/C/6oxMN6i/izmD4qnfbXsli8zThrM5zdrPy2rpEHILMbt%0AqQ18eXEVOQbTHCuoxd3xVeyMNSn1oLd+0f37MLQvERERHU2JJQ1Zp5RHIyrv%0AzYWCjujpzWTUDWPz6zBqtc9b2wiqooN6LcOgKDC/kNGAMd8yHjrC46uk8syS%0ABi0hUyp/YwvT9+pQXqo+GlI/uBJ30iDT3341aXjrKlXKLsr/NSLoVqfJQO3T%0AdWw8u4KGURHrAzWx06Q6qAzWXxxBpd321Yqn/ESSBqv20zJLGoTjDtyalNpg%0A5g7Kde5AyV9fOuFoxIOXi/Cuf8Dw9bPK+x166xeTNByS9iUiIqKjJ46k4Twe%0AeyJfhC7snMfuREvocZ4gs8eTZEK6E8MbGxjWPHqhBi2Rj2+U3luMeTzJOGkw%0AePxirCnwzHcRuty7+He4AYXHMnD8zB/od2/aTxqK7krB2ms0BQJhOTisHfQm%0AlDTob3/sOw160iofYXXtHd6tfcGTC7F1LJxJNKi0qj/7QaX+9sU+npRV7cLQ%0AnVrN40k2y08kabBoPy2jpEE4WY2euQ2sT7pQFvU5VvkdhJyK6+gZX8KmV0oW%0AOutQqEkq7PRv2WFoXyIiIjp64kgajqPu2Xrgk6slcFS34eXqNmZdZyKns3gR%0AWplGyIBzyIsNKUAPXklVg5ZteN71ofl88EXNHan8qBehDZOGwIueH3pxtSL4%0Aouk3BF/0lGVf6Mbs1134d3extdgHV/+i/aThWD1eiBt4KwW5jrNlqL35FC8+%0Ahh9viitp0N1+e0mDPF232w+/0d97yLqOCZ8Hoy2VOCu/KJuXHZjPKqg0r794%0Agkq97ZOpL0I/x40LpSi90IKRJRELd0sC81itXzqycws0LypPol3+f8FpZKdb%0AB72W7WdV/vFqPJbW98vbO6gpCkwny81WtlH+utijhQ8Y+fMSzkQlFGr51v1b%0Ane7gty8REREdPbaTBplwohKu5/NY3ZD/uNtnTPbWo0DzCIoyTfCTq29jP7mq%0AlVE7CO/WKC4FrpgGg6pRV+CTlOI6Fp63okRzRdUsqJcJ2efQMTKHNWX9PmGi%0A5xLyoz4ZKWRk4VR+Do5LAdlvfR5sPK0NjTNPStKQX9+HmdUtfBM9mHvWjKpb%0AUwklDbLY7bebNPyKlkkfVh5VGozPRPntcSxt7qif5By/ZvtKsln9xRtURm+f%0ATH4XoGlgGsvewCdXnzSgMHTl3yrozYVrVueTo/5FdBXbSBqs2s+q/NwOzOp9%0A8jT0TkA6MqL2BS07/Vud7nC0LxERER0tcSUNqSSkV2NwXZSCFPVFX72gJdXk%0AgOtkvnyFuAgO511MebekIP2k7rR7LXr77RJOtmDKt4KH5XtXT6mQ6Pb9rOz2%0A78PSvkRERHS02P7kaqrJV36rBzwQXzQofxxuf5IGKZD96offvwPR48b4/drQ%0AS6j7LXr79abRI7+86lt6aPjo10GR6Pb9rOz278PSvkRERHS0/LA7DURERERE%0AdDgoSYP8bDSTBiIiIiIi0sOkgYiIiIiITDFpICIiIiIiU8qL0EwaiIiIiIjI%0ACO80EBERERGRKSYNRERERERkSkkaojFpICIiiiTU9GN9exvbMk8/qvn3VIhs%0AEbKu43Vw39meR2ch953DiEnDTyrr7FXcf/4ej5zcMYmIzrpe4nVvG87npOmO%0At0OoHcSWdxRNxcUoLsrFcSYNR87p6jb86bqCovS9a/vDeP622r+EtGzkyftN%0AWSdm/G7cKTqc+85+tP9BZjtpEIRi3F/0K48yyXbFdSxO/AVnXnrMtGaEojtw%0A+ydwLTOywvfjL0Kbid6+oImWLN3pzWT+1oc13yK6HfbrRhBOoGM6dvlTbTm6%0A05s5ceEB5rwrGOv+A6XZ9urzZ9l+QchG9b0prGz5lPn94gic0ondTvlCdjna%0Ah9/hX6+ILY8bYw+cyIvjwCCcqIRrdA6rG/L8i3j9Vx3y08Lzm5Vvp/7T8514%0AOLaAtU0Rm2sLeNldE/qL5vHsP4KQDscDN8RZFwo165cMIfMaJvx+eAdrka7U%0Adx465/zwL95H8T4FVmb1IxNyLuBPqX3WpPYRvyxi4lE9CuNoX8vyrdpfyED+%0AlT64RaledP7qd7LrZ8Vs+cH2i+5/8bSf5fZbjLeSbP1l5tegY+gjvEsjqM9P%0ALHFQkob1AVyIXraN/i9knUP7SGD91pfwtq8RRRnhcoSsUrQMzWBZOj6I3iVM%0APbma0va3Ylm/FsfHvW7/IKvzSyLHN7vHT0FIQ3HjIwz2t+N8Vuy0RvFNPMzO%0A30JmA8bEXeyuPcZ5TftY9T91+9T927+7ja8r8xi5fR4notpYlmj92t2/1HU9%0AnEmDVfsbSfb8fpDEnTRM3jqDgoICnCmtgevNF3yb6UB+HBt2cJOGdPx6ukDZ%0ANllpfS8+Sgfuh+czdKc3IqQVo+ujD56ntXFdhRKEHNya8WPmz9LQOshys+I7%0AuQkZVehf28D49TykxbX8n2T7T97EtH8Zg1dKUSiXkZ+DY9J6WJUvCL+iftSL%0Arbm/cbWiFI7aWxhb28Z8Z3HMMvQIwnE4n61DnH+Eemn+strbeO35humO/MB4%0A8/Kt6l8QiqSTwDesvrqFWkcJyi/dxzvp4DLWpCY98ew/aYW3MCsu4kFZfG1r%0ARjkR7C5h6d0gqqUTiZDbjkm3G6v7lDRY188xXHm+IZ3oenC5/CxKa9ql+t/B%0Au1sFMWXpsS7fvP1lJe3T8Er1/uzFPHajg/Yk188O0+UrJ/LP+Ls63Acru+aw%0A8+6WrROXdf+3rh8rqag/5aJC3xI2x5p0AyYrpkmDRf8/37smbX+vtP0lKK1u%0Aw8s1H9xdper80v5//tEytheH0FRVitILNzCyJOLDn/aOP6lgXr9Wx6+9b3+Z%0AnfNLIse3VMUfySYNVufvtJoBfJ19i7fiAv7UPN5j1f+C2zd2U9q3C4tRUf8Q%0As5sbeNkYeVEu2fq1s38d5qQhUcme3w+SuJOGV43hjiIUd2HRP4UbUjYs/9+9%0AG9kR0p3D2BBHcUXagYTKXnhMrmSpnXoHz2/9geEFL8QtD+aGmiKvxGSXo2N4%0AFitfA1cqHjqRF8h01fm/YqClCSNuzfwJXKnJLOnA1JclDF0+FVfgLcttmZCW%0A/QZNOfHNJwi5cM368aY5/iv7WtlNY9hZ7oFDcwVAJjgeYtk3ieZfw8MznENS%0A+7xE/bHIaQ/y9gtZTjxdEeGdbEOBzroZJ6Xm5QsZ9fhnewV/lYfnO9E6Cf98%0AZygpFjKL0Ng3haV1+UrgMqb6/sCZQP8UhPN47NnC0MVwklPctYDd8evIlPu3%0AjfKD9OpfyLqMxzODaNDUa+1TKUh6VqeOV/r/NkZd1/E80P/nh1tQHFMPOWh+%0AvYmV/mplvbTjkqGeCCbQ3z+Hvuo05NycwNjTZ1jXBE0ZhfXonfwkBSbfsCVf%0ACe65HHGlsVIKqjwDLWgeWZCmEbHu/gcdZfb2B+v6KcXDJb90EM4Mjb/wxIPt%0A0frQbzPW5Zu3v/y7+lYPrhRmQmh4EXulP8n1s8N0+enn4Rp5gLrA9sknsS63%0AD1NtuaFplOEG+59l/7dRPzKz/TtV9SfktGFmJ7GgxfxOg3H/D160mLp5IjRP%0AvhS4Dd2qClwZPiPV9660/sdC47Nru/Gi24msqGXpief4bsS0fi2OX6lqfytW%0A55dEj292jp95rtlw3OJ/hQZt/VjEN8HprBidv4McD5ew+siJtikfJm78Ghpu%0A3f/UpEGbFJX/tQzfy0al/wWHpaJ+rfavRJOGvYz/5ITe3V0ilaM+kbD0sFz6%0AfzoaX+5IiZV6x8W0/eNYfiLn94MkuaQh34UP/hm0SRsqCKdx+70Pnx+UBaZP%0Ax+WRDWyOXEaG3Gkzc3BGfp7tYi+WpHk6y6T/y78Lc9TxgZ12dboXN6occDi7%0AMLOxjbetpwLlZeL3QQ/Ej0/QUFkKx8VOTErB21Rb8EqGPL+IlanHEfNP3VTn%0At0vIb8TY6hKG6+O7Ui8TMmvw1ONTrr7EPa+QB9e8H5M97Rj9sAav91+8H4oN%0A+qzIgdfOi6sxyxcEB3qWdzB+LTvwOw3V/V/w7VVjxBWFg779Qo50wBH98EkH%0Aw4iTWmUP/pVfsNrZwa5/F77gC1dfh1ArTWdVvnBMKnd3EV3F4TKPSQdw7RW3%0A0m63dEAfxY1qB0qrmjH8SZQONA51fsGJEXENPRUZqBtawaTUL3PapuCfdSlX%0Aau2Ur5Rjs/7l/avhn214nlwI/Fb3H89MH5qr5Ct5Lkx82cH725FXWrPrhrHu%0AHcXlqNveyVJPBJO44XyMucdOtIxNoOXqAL6GTlqn0Dq+htn+FvxeXgJHTTte%0ArorS/n06VIbcd0XPDPpbfoOjrAaucQ923V0oMqkHI7H1kwnnkAfeiXaUZmcg%0AM78OQ0siJlvzYua1I7Z88/aPmFc36E3t+pnRW360tIq/sfrtNZqiH48w2v+s%0A+r/N+jEqXyvZ+hOEcvy9shsKBuJhnjSY9f90KQjwYmvKhbPHY7dLECrQuybi%0AWYLPsNs9vtuhW78Wx69Utb8ZO+eXRI9vdo6f6dm56pXii0+wEh00WsQ3wems%0AGJ2/ZeqFLxHPr8iPB33C1silUMBv3f/k7YtMGnI7ZuB/fztU/6mqX6v9K5Gk%0AYa/jv1O3ZrA55JTKkfbDyU9YeNEg1UE+OufX8KhSXU/T9re5/ETP7wdJwkmD%0AkHEadQOf4ZNO6sFM+qSUpW6v9aJCyv6EzMsY3dqQDoKRt7DMH0/yRzxjXj2w%0ADlHaMdTx6kF12BnuiCVSEOcbvxa4kmE+v13KAdMnwvP5HUZcF5Bj0rDR8m+9%0Ag8+7gKn5VXjXlzHz9AZKdE4QegSpg/75wS/tFP1orq5EZf09zHzdxcc78d2e%0A/n3Qi/WBat1xFT3LoZOIWp/bGGuKvJJ7GLY/40Qeco6Hr1jJDA/axaeUK3VW%0A5ctXVu983MHaPy0oyU6Xgo5aPF7YwYaU6atJrZp0vG0NXyk8XtWOflcNspXx%0AwZNiDjpm/FjrrYw6aZqXH9oOm/Uv5FyXgqsv6KsO3t4M9H/NlUx5/9gN7B/K%0ANJnn8eTfLbxpVg9kja/8WLyvPh6RrOBJqyW7GgPT85gba0dOdfikpTdPxd8r%0AEfunfMLcnWwNXVkVSrrxWTpWXLfZh7Si60cZlunA7UkPfLu7UmK5hY+9zrj6%0At1Zs/Zu3f8S8OkGZMjyF62fGaPmh8dIJyznkxeZove7VRN39z7L/268fvfK1%0Akq2/4PPekzfUADseVkmDWf8XTtVhwC1Kx0g3xh53oCY/fFck2aRBZuf4bode%0A/VofH1PX/kaszi/JHN/sHD9D05bel84xkUFjaJxBfGOX2flbyGrC651p3Dwp%0AIK32KTbXHuFcYB2s+p+6fTpJg6b+U1W/VvtXYknD3sZ/aZdHsC2fezIaMT75%0ACq+m7yBfqEL/+jt0RN110Wt/u8tP9Px+kMSdNOz61Cu4Pt8uvi2Poc0Rvp0q%0AHK/Hi6119Ndk4Fj9KETvEH7XPF6kTGOaNER26tL7i/BLB0F1fPCgEx4feVAy%0An98uIes0is86UPXHQ7z7Kl+pUjNZK8H62ZzvRdOFClRe6cSbNR8+Pyw3zSjN%0AOB5I6z/dEdezt7WDX40POhU9WBX/Qb1U94LjAZZ2pHaIvpJ4yLc/noN2dPnH%0AytoxsbYDvxR0iCtLWNteQ2/omcPY/qVl56RoVn6oHBv1L2QW4/bUBr68uBo6%0A6Oitn7L8wJUk+cqjo3sh4uW1PUkastJQ3tqPLmcuhKigKaemG2PuNWyI6jFk%0ARzqG+F40hMpQ7jRoDrJCZhFqr12M+26bfv1k4rdHn+GV+mfjhXOorHPh9dq6%0AFFTFfyVfv3z7QZF+UJa69bNimTRkNeCVqB7H9cbr2Y+gMSjZ+gsFNa3hxzvs%0AskwaTPq/Ml16Dsr/uIOh91JyI35Ed4V6/kxF0mDn+G6HUf8wPz7ubftbnV+S%0APb5ZHT8jpt3DpMHs/J3mHMLWpwc4K29vVjMmfR/gyleXY9X/9LZPmzSksn6t%0A9q/EkoZg/wnPE9m/kov/lP1FrtviLkwPtqF7Zgg1GU0YD3xIJWJaw6TBevmJ%0Ant8PkriThreuUuUKblH+rxHPwqnTZKD26To2nl1Bw6godf6a2GlSnTSEgqLk%0AOo0e5ZlLzZVPM0JWCyb9y3hQFp5WfuZzd6ELhQk2/K/yM6OL9yJOOlZqBrzw%0ADv6uO045Ma2KGLmcqWybb7IFv5qUfRi3P56Dtl75QlomcvLy4exbhjjVhlOB%0AcXr9SyvcP9Xb72+NHr8wKF+PXv0Lxx24NSntYzN3UK69CqSzfpH7h3rl8fmV%0AcCC4N0mDZp20J61MqX42tjB9rw7lpepdoPrBFdOkIRGG9ZNej5c7a3h0Pqp+%0AFu7G1T+N699e+yvT6gW9KVo/O6yShpzWt/CtPMK5QHBgh9X2x1M/VpKtP/mu%0A450PUlDTsgd3Ggz6v3ZaZVxaDq6MrMH3tlW5aJGSpCHO47sRs/5hfHzc2/a3%0AOr8ke3yzOn5GTLuHSYPZ+bui51/4d75ha2tLImJn14fXzYHH0ayOvzrbp308%0AKZX1a7V/pTRpSFH8J2TdwFvxGZx1zzDlKkLT2BRaK6S2DCRpEdMmkTRoxXN+%0AP0iSeqdBT1rlI6yuvcO7tS94ciH2FrNwJtGkQT2oxtyeGmvSvBORRKfJuIA7%0AL3tx9XR4/jN3PsAvHdTlx0+002aezIv5qo+QcVU6aS3hXml42uwbE9j9eCfm%0AhT7d+YXTqGy4iorc8LTy9ukt30zZg8/YfdOsfDFIb7z8ws/G8A10zu5IWW74%0AVtph2n6zxxeMk1L75aeXdsG98zni6xB6jydlVbswdKdWmT+eF/10y7dR/8LJ%0AavTMbWB90oWyqM+9qf0/8vZ66b3F0O11QajEE48fu9KJxudT7e7GHvTldw9q%0Ab9/H/RvnbSWLQZYnraK7Uru8RlPoxfE01A56U5o0mNbPsSa83vWgtzLcPjnt%0A01JQaT+pNa9/++2vG/TaXL9E20fLNCgUCqQT/i7c3WdjxgXpP56UuhdhE3k8%0AKZ72FYQLGFjfloJr42UYSTRpENLl/XsATWfC4zOvjYe2Q/dFaOd9vHzgjDk+%0AmTE6vmvpHX+1zPqHTP/4mLr212N1frF7fDNidfyMmNYsaTCIb+wyOn/LgXjn%0AvA+Tt4pDX+D5Y8SLzWGneicggaThXM8ydl7+ob6In8L6tdq/Eksa9jj+E2rw%0AdGMKXV1vMXIlDecfTaOnsx9fJ1pi2yKBpCHZ8/tBkvKkQZ6u2+2HX/6OsM6V%0AKvmvAk74PBhtqcRZ+ZnzvECmbFXpwRdhPkgVr3yyTX5R6RsiX4RJptPkoW1K%0AlBrsLpxlJShzyi/abGPmVmHkdPntmNmWdp7VR6iM6DQn8MdLL7zT93HlnLR+%0ANW14ubKNj3ejgjLD+XPQMinCO9WNuvKzcDj/xFtv+EUfu9Iv9MEjjqHxRGzd%0Ay9KqeuFZXsSiOI2bmmf1Dsv2W70oaZw02CxfOjjfmvkGz1DsV0vUF6Gf48YF%0A+ZOILconERfulgTmO446vU8Kttsr36r+hePVeCwt78vbO6gpCn+6rSA3Wz3o%0AK/1fKld+ke988EWxHcy61Bf55P0n50zwPQ+V661O0pDdgkn5ZHDP3sk2yPKk%0AdaweL8QNvJWSLMfZMtTefIoXH5dSljRY149av1tzavvIn4wcX9uB+57D1uNz%0A1uWbt7/8nsCJ/CIUFUk6JuBf6YdT/n9hTuAZdHvrl3D7WCw/OF2a/BWe3Xnc%0AztevE+MXoa223+b+YVh+aupPllHZi1VROkac1N9GMwknDVIydvv9Nr5I+7d8%0A/CmpbEDfB+l4JAV9alCt+eSqtP+qx5dvoU+a2mV0fA8yPv7a6x/Gx6/UtL8R%0Aq/OL3eObEevjZzqycwP7vPIi7CTalWPAaWRr/1aFQXxjl9H5W8iWH0eSAm1N%0A0pklJZ2+f3tQJvcfm0lD9CdXXwU+uZrK+rXavxJLGvY6/ivE3QU3JiYm0V0i%0AIKdtEuPjE6FHxaza32r5yZ7fg2UeBHuQNPwqBWc+rDyqNBififLb41ja3FE/%0AXSVl8nYzRSH7HDpCfxznEyZ6LiE/sMMm22lkabk16Hq5AM+WdPLxuDH+sC5U%0AfpBwsh6jHhFfZ1zKzhgx7kQFbkvrt6L88Ro3Xv91GfnR73SYzS8vf0xe/jdl%0A/rEHF3EqjkcEZPIVdblzrr1qRmHUspXxaVXok68YzHTE3HY9DNsf+iTj2/g+%0AuaqMs1F+TtMYtqQD3nXNHYkg+VnDpoHpwB9fWsbUk4aIOlb/eNF86I9LaT8J%0AF2RWvln9C7kdmNX7pF/o9r/c/79isDXwyUBxHQvPW1FicsVL7/ay8tzs7ge4%0A4vwT/9YnrTTk1/dhZnUL30QP5p41o+rWVOqSBov6kaeR67f75Uflj+fIn+yb%0A7G3AGZtXBO2Ub9b+weNnzPyaZ2btrF/C7WNj+fKJsabfg523rTgZGBbNbP+z%0A6v929g+j8lNVf8LJGjxxi1jqqUjoZJzM40lpeU48CBx/RO8KZkdu47wmOAz+%0AcTf5j6epx5erusdwM2bHd2W8wfHXTv3KTI+PKWh/M3bOL1rxP55kfPwMfrI7%0Apn78kV+UMopvguOtGJ2/M+qGpZinH79p26ywEwv+ObjypOOrraRBXX/5j7tt%0ArMzhuSvyj7ulon7t7F+JJA2yvYz/5EfrG19J5W6NoUlqc6H2Kda2tjDXGUwa%0AzdvfzvKTOb8HyzgIbCcNdgknWzDlW8FDzfecaX8JJ6pw//1XiCtTuOVgO5B9%0A8nfAd2baD9yBilRsn8Tl1g/A/VXEp2cNMRdD7FKSBr8PO/LnnD39qGY7UIod%0A1vO31f4l34V5rXwK3YfdBJIGOhhSnjTIL6f4TJ6HpP0hpGWjuK4D9ZpnFInM%0ACMJJdExv401z+LleOjjYPsk5VdOCxorcpG73C8dzURR8RKMoN+LRHaJUOYzn%0Ab6v9S96mvNDjTQU4kWDiTj9WypMGIiIiIiL6uTBpICIiIiIiU0waiIiIiIjI%0AFJMGIiIiIiIyxaSBiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjLF%0ApIEOnNPVbfjTdQVF/OMvPwTrPzmsPzJz1PsH9w+iw8t20pDbMYPv37/H8Ps9%0A6K08GDu/kNWCycD6yH+Z2q/5y9SCUIaef30YrU9sXYu73JptnkLrr/GXY7Z+%0AqbDX5e8HQUhDceMjDPa343yW/XW3275C0R24/RO4lhk73VFrn7KHS/C9aIgY%0AZlX/ZvVn5aD3T7P1s7v/J9p/D4JUtI8gZKP63hRWtnxqXYkjcB6gNv7Rku0f%0AB71+rY4Ph3n/IKI4kob0rFwUFBRIitE57cfSk4uB33k4kUAAsRfMTnrJJg3p%0A2afV7a18IB0UmTQcNEwa4qeXNFg5qklDKvb/gy4V7SOcvIlp/zIGr5SiUK6v%0A/BwcO0BtfNgd9PpN5vhARAdf3I8nCUImWib8WLxfGjm8uAvuXTfuFIUPFunO%0AYWyIo7giHUDUoO4rBluv47nbC3HLg/nhFhRrDi7CiUq4RuewtiFCXF/CZO9V%0AFMZxC1NI/wNju8t4UCbgePNr+N1dOBM4oKrL38HzW39geEFd/txQE4oy4lu+%0AkOfCnE7QYGv7TNYvFazKFzKL0Ng3haV1afu8y5jq+wNntNufXY6O4VmsfBWx%0A5VnE64dO5KWp4622z6r95d+VvWvwDLSgeWQBXlHEuvsfdJRlhabPc81qrua+%0AQkNU3WQWX8PQ7Bq2xA18GruF+u65UNBr1b5CZS88fn+o/NByFu+jONhHDnj7%0AWNWfVf9NO+XEo6llqU22sDx5B629nyKSBrP6t1N/aYX16JtektZtB76tNcyN%0AdqBcczUx2fo1658yq/qxYmf9jPZ/mVX/tdz/TNovuP8NtDRhJLD/Kf1b275W%0A9W/RP1LR/02T8j1sP6HsIf51P0PvlBeb7h446wewvOXFbFcF0gPbkOzykz0/%0Ame5fNtpXmW6P6tdO/WVI/at38pM07zdsfVnERM9l5AfPDzaOD5b7h43zj1X9%0AENHeSl3SIJzG7fc+fH5QFvidjssjG9gcuYwM6eCg7vTfsDbTh+aqUpTVujDx%0AZQfvbxcEpj8G57Mv8E51oa78LEqrW/Hi323Mu4oilmNGEGowtDGHW6el5dU9%0Aw7fpdpwIHJjU5W9jdboXN6occDi7MLOxjbetpwLj7S3fPGkw3j51GuP1SwWr%0A8ku73dhZHsWNagdKq5ox/EmEu9sRmDcTvw96IH58gobKUjgudmJSCm6m2vID%0A463az7z95WHySUv0zKC/5Tc4ymrgGvdgVwpMigLj07MDd7MuPsFKzEk1D7fe%0A7cA73S21TynKL3dLyYsnKmkwad/MHJwpLkbxxV4s+WfQWSb9X/5dmBNav4Pc%0APjKz+rPqv4KQhfrRrxDnHqG+Qqq/Kw8xtuyNSBpM69+i/uT+0/jyG7xvXKgu%0AKcLZygb0vvfiY7faH5Qykqhfq/4ps+pfVuysn1nSYFZ/MvP9z6r95P4tYmXq%0AcUT/nroZPH6Z17+d41tS7VPZg3+3t7G9s4Nd/y588v9lX4dQK5Wx1+2nBL0b%0Ab+G6UIUHc1v40HMJ59rGsLUxhJoULD8V5yfz45tF++5x/VrX3ym0jq9htr8F%0Av5eXwFHTjperonR8Pa2un43jq/n22zn/GNcPEe2PlCUNspMtE9he60VFmnSQ%0AybyM0a0NPHNmBOaTd3q/tJOfCE1fIp1Ed8evIVM5KFWid82LvurwgSTfNY/d%0AyRZkaQ4uiQotvy0nNKx6YB3iyKXAeHvLN08ajLdPO+2PIAfdrnm/dJAPr9/x%0Aqnb0u2qQrdR/hbT9Ioad6aHx8vr7Qu1jvX1m7S+TT1q7k62h+hRKuvHZP4Hr%0Ax6PqsvS+dOKJOqmk1+Olbw2PKsPDavrXo5IG4/YNOqi3z63aR/5tVn9W/Vcd%0AL7dvmjqvkIaLQ18jkoYgvfoPjTOoP0HIlZJGPz7esR9ExcOqf8q/7favZJgl%0ADUG6/ddy/7NqP6vjl3n97/nx1ShoLD4VWP+9bT8l6PX24zdp3gtPPBi/fgxC%0AQSc++l/iagqWn8r60+8fFu27x/VrVX/BMrUq/l5J6Piqv/02zz8Wx3ci2lsp%0ATRqE4/V4sbWO/poMHKsfhegdwu/Bx0OUnT7ymXPludn3t5GrHBScGBH98O0E%0ArqAoV1V24Z91KeOD8yRKb/ml9xfhf9UYGG9v+eZJg/H2aaf9EfTWL3K8vP1r%0A6KmIWv/A9tvZPrP2l8knLe1BXn5co/baxYhHuJTheicV5XnryMeftM/kW7Vv%0A0MFNGszbR2ZWf1b9V699jd5pSCRpkBW2TmJzx4vFmXGM9j9Am7MoFLAky6p/%0Ayr/t9q9kJJ402Nn/zNrPun+b1b9V+cEykmWcVO5t+ylB7/oALkhlKUHvtcxA%0A0Ku2Q7LLT2X92e0f8Ry/kt4+i/pTyqvpxph7DRuiuv07vt2Y40fiSYP5+tut%0AHyLaW6lNGoQM1D5dx8azK2gYFbE+UBN+nlRnp1cOChFJgwdDDcErKAH5J0Jl%0AJMPqoGN3+UcuaQi1j/X2mbW/LPqkZUT3pJLRgDHfMh46wsOqpPKOctKgZdV/%0A9do31UmD3P655VfQeucv9L+YhWdHxNTN/JjpEmHVP+XfdvtXMvY2aTBrP+v+%0AbVb/VuUHy0hW3EFtitov4aTB5vJTWX/7mjTY3T6r+suUyt/YwvS9OpSXqtte%0AP7iy90lDYP3t1g8R7a2UJg2ytMpHWF17h3drX/DkgvoohEzd6SMfbym9txj1%0AeJKI51fCtydTyeqgY3f5Qt5tzPun0Xoi8qBotX3aac3Iz47W3r6P+zfOx33b%0A24ze4xFZ1S4M3ak1fzxprEnzTor19hm1v8xuUKB/UilCl3sX/w43oPBYBo6f%0A+QP97s34k4YzySUNP6p95N/mQY15/w2Of1anjk/48SSD+pPfYcnMOo4MzYuX%0A53qWlf4RfKY5GVb9U/6dTNBpl9H+r6Xff632P6v2szp+mdf/Xh9fg4yD2r1t%0AP+ukIbnlp7L+9iZpSHL7rOqv6K603NdoCj05kIbawch3opThNo6v+ttv5/xj%0AL2nIPJmH3KzIcw8RpUbKkwZBKEa32w//2mOc15zA1J1+G553fWg+H3zRaQez%0AruCLtMfhHF7HtrsfjdL4suobGHJvYaEr/CJoMqxPuvaWLz9b/2J7E2PtZeon%0A7wpOIzs9eFAz3j67hOwWTO5K9XtPv36Tob6I+Rw3LpSi9EILRpZELNwtUcbJ%0A7aq8iPahF1crgi86f0Pki2jW22fU/jLzk3I6snPl+gy+KDeJdk39ytNkX+jG%0A7Ndd+Hd3sbXYB1f/YvxJQ9Z1TPg8GG2pxFn5SmFedsR4Kz+qfWTm9Wfef9UX%0AoTfUFw3lF6EvR74Ibaf+lekM6k9tdx+Wnt9EjaMIReVX0PvhG9Z6q0LzJsOq%0Af8qSCTrtMt7/revPfP+zaj+r45d5/e/18TXIOKjd2/azThqSW36y9WfVP2wf%0Av/aofi3r75jU78UNvJWSXMfZMtTefIoXH3X+zovh8cFq++2cf2zUT347Zrb9%0A2F19hEppvbXjiCh5e5A0/IqWSR9WHlVGDVeDzlFX4JOd4joWnreiRHPwkz9p%0A1zn6AWub39RPEvZHfhI1GXYOOnaWLx/8zt4YhdsrYtcvBcf+RXQVBw/65ttn%0AR5pzCFu7H+AqTM12awmZxWgamMaytO7K9j1pQKFm+4Tsc+gYCX5S8BMmei4h%0APxDw2N0+o/aXmZ+Uc+Ga1flkX6B+Q9NlZOFUfg6OSwnJb30ebDytDcxv86Qi%0A9d/y2+NY2txRy4/zSviPbB+roMqq/6bl1eHxzCo2A59cbXyg/WStzfo3qb/M%0A0mYMvVvBxrYPO1seLLy6gyqTK/LxMuufsmSCTruM93/r+rPc/0zaz07/tqr/%0AvTy+Bpk9nrKX7WcV9CrTJLn8ZOrPqn/YPn7tUf1aJ11pyK/vw8zqFr6JHsw9%0Aa0bVranYpMHg+GBr/7A8/9ion5P1GPWI+DrjCn3qlYhSJ+6kwYpwsgVTvhU8%0ALI/cYfV2+p9JqrbP8XAJOzPtoedQDwq722fU/qkgn5BO5stXp4rgcN7FlHcL%0ArxpP6k67Vw5q+xARERHtpZQnDfLLSz6dvyTKpMGaIJxEx/Q23jSHn3s+KOxu%0An1H7p4IgVGPwq3x1dweix43x+7X7Grwf5PYhIiIi2kspTxqIiIiIiOjnwqSB%0AiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjLFpIGIiIiIiEz9UpNf%0AyKSBiIiIiIgM/XKTSQMREREREZngnQYiIiIiIjLFdxriIGS1YNLvQW+loPzl%0AY7/mLx8LQjHuL/rxqjEjNH1l7xrEkUuh32aKu9z4/v27wu+fQuuvkX/p2Gp8%0Asi6PiFjoKpa2IwutYyLcPZXK8CvPv2GmPTdm+nglsv5lD5fge9EQ+m1W/0RE%0ARES0d5g0xGEvk4b07NMoKChAQeUDuHWCaqvxyar4ewWex1XSdpTi4eg83o00%0AIE1KIG5M+vDiapruPPFIZP2ZNBAREREdDLbfaRCEIjR0NuNcTnrMuFSMtyOj%0AsB69k5/gFb9h68siJnouIz9t/4JGIf0PjO0u40GZgOPNr+F3d+FMHEmDcKIS%0ArtE5rG2IENeXMNl7FYXpkesv5LkwZxJUm40XssvRMTyLla8itjyLeP3QiTyb%0A9ZPvmsP2aL20HZcwOvECL8ZdyBMKcOfjOh5XBbbRonx5ez0DLWgeWZDaSMS6%0A+x90lGWFxitlmKx/2iknHk0tY0PcwvLkHbT2fopMGkzqn4iIiIj2ThxJw2nU%0A981jfXMZb3pig/9kx1sRhFNoHV/DbH8Lfi8vgaOmHS9XRbxtPa07fTRBqMXQ%0A121sb0eZ7kCuzcBTEGowtDGHW6cFCHXP8G26HSdsJg2CcAzOZ1/gnepCXflZ%0AlFa34sW/25h3FYWmV6ZLMGkQhEz8PuiB+PEJGipL4bjYicl1EVNt+RHTGcls%0AGoN/6iayczswNdKJ7sk+nBcq0Lvmxp0z0vbaKF/ZXs8M+lt+g6OsBq5xD3al%0AwL5IU7/G65+F+tGvEOceob6iFOVXHmJs2RuZNJjUPxERERHtnbgfTzpeeBGu%0AZ7NY31jGayn4L48K/pMdHw/5kRq7j//IQemp4mIUR8s/gfQUBJ7BpGHXF05I%0Adnx+TdJQKQXgXvRVh5eV75rH7mQLsmwE1VbjBSXAFzHsDNdnSbcbvvFryLSx%0AfULtILbkK/eVvZj+6wJuTIyhMb0OI98m0ZwlJw3W5ctJw+5ka2h7hJJufPZP%0A4Prx8PKN11+uH7l89VEoQUjDxaGvEUkDEREREf0YCb/TcKygFnfHV7Ez1qQb%0AdCc7Xk9OTTfG3GvYEINB+e6BCSqDScNbV2koIWl85tEkDU6MiH74dsJJxfbO%0ALvyzrog7HYknDXL5a+ipCA9XnvuPKt+I4HiAJU8fqhtfYao9B85n0/jT0YxJ%0AcRhOaX475cc8jpVZhNprF1GcGZ4nnvWPfqeBiIiIiH6MuJMG+QrwCUcjHrxc%0AhHf9A4avn0WaNuhNcrwRIVMKKje2MH2vDuWlalBeP7hiO6hMxeNJZqwfT5KD%0AYg+GGjR3OWRRdzpSnjS8v20vachpx4xvFK477zFySYDjwQwGml34sNwDhzS/%0AnfKjkwY9TBqIiIiIDh/bf6dBENKRU3EdPeNL2PRKwX5nHQq1j50kOd6KUHQX%0Abv9rNGWo88jJR+1g5DPvZvbr8STjpEF9/Ob5FfPHsYS825j3T6P1hP46GY03%0AfHxorAkZdpKGtHq89L3FyMgsHjoEnJQSgvEnfVgNJAV2yreXNBitv1o/z+rU%0A8vl4EhEREdHBEceL0JV4tPABI39ewpms2CA02fFWhGP1eCFu4O2dWjjOlqH2%0A5lO8+HhwrkRbJw3H4Rxex7a7H43nS1FWfQND7i0sdDlC0yvTpUvbub2JsfYy%0AFMqfKC04jWzNF5aMxodeVP7Qi6sVUvm1Lkx8+Wb7RWhBqEL/+hzevXuLm1JA%0AL1wawfTkJDZeNip3guyUbytpMFx/+UXoDfVFa/lF6MuxL0ITERER0Y9h+/Ek%0A+U5BRuAqv55kx1uRrzzn1/dhZnUL30QP5p41o+rW1KFJGpRpTlSic/QD1ja/%0AQfQuY6q/CUVRdSLX09kbo3B7Rez6/fD7F9FVrEkaTMYL2efQMRL8pOsnTPRc%0AQn7UJ12NyJ/E7XJL83lHUCcnCeUPsSiK+NJfHZ7GonxbSYPJ+qfl1eHxzCo2%0AA59cbXwwx6SBiIiI6ADgH3cjIiIiIiJTTBqIiIiIiMiU7XcaiIiIiIjoaOKd%0ABiIiIiIiMsWkgYiIiIiITDFpICIiIiIiU3yngYiIiIiITPFOAxERERERmWLS%0AQEREREREppg0EBERERGRqSP5TsPp6jb86bqConRBd3wqZJ29ivvP3+OR0/4y%0Azrpe4nVvG87npOmOJyIiIiL6EY5c0iAIaShufITB/nacz4o/aRCK7sDtn8C1%0ATON5T1x4gDnvCsa6/0Bptv1lZObXoGPoI7xLI6jPZ+JARERERAcDH0+Kk1XS%0AIGRUoX9tA+PX85AmJJCUCNmo7lvC5lgTTiQwPxERERFRqtlOGgShCA2dzTiX%0Akx4zLhXjrQhCGXr+/YrB1ut47vZC3PJgfrgFxZrgvbJ3DZ6BFjSPLMArilh3%0A/4OOsqzQ+DzXLL5//67w+1+hQROUB8sfaGnCSKD8uaGm0CNMQmUvPH5/aP5Q%0AOYv3UawpJ7tpDDvLPXCkxQb8GYX16J38JK3bN2x9WcREz2Xk60wn5LRhZseN%0AO0Wx44iIiIiI9lscScNp1PfNY31zGW96YoP/ZMdbUYP6b1ib6UNzVSnKal2Y%0A+LKD97cLQtPISYPomUF/y29wlNXANe7BrrsLRYGgPj07FwUFBSi4+AQrukmD%0AiJWpx7hR5YDD2YWZjW1M3Tyljs/MwZniYhRf7MWSfwadZdL/5d+FOcjQlCOv%0Aw86LqzF3GQThFFrH1zDb34Lfy0vgqGnHy1URb1tPR0ynTluOv1d28bIxsQSL%0AiIiIiCiV4n486XjhRbiezWJ9YxmvpeC/PCr4T3a8ETWo90tB/InQsJJuN3bH%0AryEzEKDLAfvuZCuyAr+Fkm589k/g+vGoAL70vhT46yUNUvltOaFh1QPrEEcu%0AhX4r01k8nvT7oBfrA9W646JV/L0SU75MEPLQOefH5I3smHFERERERPst4Xca%0AjhXU4u74KnbGmpAedVU9FeOjqUG9D6P14Wlz2qbgf38buYH5lTsNmiBcyCxC%0A7bWLEY8wKcMNk4bI8kvvL8L/qjH0W5nOImmoHfxqmDTk1HRjzL2GDXEb29vb%0A2PHtwveiIWa6UNLQ+mvMOCIiIiKi/RZ30iB/feiEoxEPXi7Cu/4Bw9fPRjyK%0Ak+x4I4kkDUb2MmmoGfDCO/h7zHAh04mRjS1M36tDean6aFP94IpB0pCPOx+k%0ApKGFdxqIiIiI6Mez/clVQUhHTsV19IwvYdMrBfuddSjUPPaT7HgroceHNI8n%0Ald5bjHk8ac+ThjPmSUPZg8/YfdOMY1GJkFB0V5rvNZoy1OFy8lQ76DVIGi5g%0AYH0bI5f52VUiIiIi+vHieBG6Eo8WPmDkz0s4o/P3DZIdb0UN6rfhedeH5vOl%0AcFzsxOT6DmZdUS9CGyQNctKSnVugeRF6Eu3y/wtOIztdCJRvI2nIuo4Jnwej%0ALZU4K78InRd5NyD9Qh884hgaT0Ruo3CsHi/EDby9UwvH2TLU3nyKFx+XdJOG%0AjMperIpSYnIy/noiIiIiIkq1OJKGdGQErpLrSXa8lWDSMOoKfHJVXMfC81aU%0AaK74mycNuXDN6nwy1b+IruI4kgYhE+W3x7G0uaPOP34t4utJ8lei2qZErL1q%0ARqFme+U7C/n1fZhZ3cI30YO5Z82oujUVkzQIJ2vwxC1iqafC1rseRERERER7%0ALeEXofebXlB/UAknqnD//VeIK1O45bC/vrn1A3B/FfHpWQPyA38fgoiIiIjo%0AR7P9TsOPdpiSBpmQlo3iug7Ul9pf31M1LWisyOUdBiIiIiI6UA7NnQYiIiIi%0AIvoxDs2dBiIiIiIi+jF4p4GIiIiIiEwxaSAiIiIiIlNMGoiIiIiIyBSTBiIi%0AIiIiMsWkgYiIiIiITDFpICIiIiIiU/zkKhERERERmbJ9p0EQinF/0Y9XjRmh%0AYZW9axBHLkVMZ6S4y43v378r/P4ptP4a+VePrcYn6/KIiIWuYmk7stA6JsLd%0AU6kMv/L8G2bac2Omj1ci61/2cAm+Fw2644iIiIiIDop9SxrSs0+joKAABZUP%0A4NYJqq3GJ6vi7xV4HldJ21GKh6PzeDfSgDQpgbgx6cOLq2m688QjkfVn0kBE%0AREREh0FKkwbhRCVco3NY2xAhri9hsvcqCtMjg2chz4U5k6DabLyQXY6O4Vms%0AfBWx5VnE64dO5KXZSy7yXXPYHq2XtuMSRide4MW4C3lCAe58XMfjKrUMq/Ll%0A7fUMtKB5ZAFeUcS6+x90lGWFxitlmKx/2iknHk0tY0PcwvLkHbT2fmLSQERE%0AREQHXsqSBkE4BuezL/BOdaGu/CxKq1vx4t9tzLuKQtMr0yWYNAhCJn4f9ED8%0A+AQNlaVwXOzE5LqIqbb8iOmMZDaNwT91E9m5HZga6UT3ZB/OCxXoXXPjzhnB%0AVvnK9npm0N/yGxxlNXCNe7Dr7kKREF5X4/XPQv3oV4hzj1BfUYryKw8xtuxl%0A0kBEREREB17cScOubxvb26odn1+TNFRKAbgXfdXhYDnfNY/dyRZk2QiqrcYL%0ASoAvYtiZHhpW0u2Gb/waMjXlGxFqB7ElBfhnKnsx/dcF3JgYQ2N6HUa+TaI5%0AS04arMuXk4bdydbQ9ggl3fjsn8D14+HlG6+/XD9y+eqjUIKQhotDX5k0EBER%0AEdGBZ/vrScGk4a2rFMXFxYrGZx5N0uDEiOiHbyecVGzv7MI/60JuSpIGufw1%0A9FSEh+e0TcWUb0RwPMCSpw/Vja8w1Z4D57Np/OloxqQ4DKc0v53yYx7HyixC%0A7bWLKM4MzxPP+vOdBiIiIiI6DFL4eJIcFHsw1KAmFCH5J5C+l0nD+9v2koac%0Adsz4RuG68x4jlwQ4HsxgoNmFD8s9cJglDZryo5MGPUwaiIiIiOhnoyQN8mdC%0Ak08a1Mdvnl8JP96jR8i7jXn/NFpP6Af6RuMNHx8aa0KGnaQhrR4vfW8xMjKL%0Ahw4BJ6WEYPxJH1YDSYGd8u0lDUbrr9bPszq1fD6eRERERESHhfJ4UmqShuNw%0ADq9j292PxvOlKKu+gSH3Fha6HKHplenS6/FiexNj7WUolD9RWnAa2ZovLBmN%0AD72o/KEXVyuk8mtdmPjyzfaL0IJQhf71Obx79xY3pYBeuDSC6clJbLxsRJqS%0ANFiXbytpMFx/+UXoDfVFa/lF6Mt8EZqIiIiIDoeUJQ3KNCcq0Tn6AWub3yB6%0AlzHV34SijOgr7uk4e2MUbq+IXb8ffv8iuoo1SYPJeCH7HDpGgp90/YSJnkvI%0Aj/qkqxFBKEKXW5rPO4I6OUkof4hFUcSX/urwNBbl20oaTNY/La8Oj2dWsRn4%0A5GrjgzkmDURERER04NlOGoiIiIiI6Ghi0kBERERERKZsvwhNRERERERHk+1P%0ArhIRERER0dF0aJIG+W6IGb15iIiIiIgoeUwaiIiIiIjIFJMGIiIiIiIyxaSB%0AiIiIiIhMMWkgIiIiIiJTTBqIiIiIiMgUkwYiIiIiIjL1y422Dly6cpVJAxER%0AERER6frl48InXKipZdJARERERES6fikpLYtIGIySBkEoQkNnM87lpMeMS8V4%0AK3qJgpbePERERERElDzb7zQIwmnU981jfXMZb3pig/9kx1vRSxS09OYhIiIi%0AIqLkxf0i9PHCi3A9m8X6xjJeS8F/eVTwn+x4I3qJgpbePERERERElLyEv550%0ArKAWd8dXsTPWhHRBSPn4aHqJgpbePERERERElLy4kwZBSMMJRyMevFyEd/0D%0Ahq+fRZom6E92vBG9REFLbx4iIiIiIkpeHO80pCOn4jp6xpew6ZWC/c46FB7X%0AJgPJjbeilyho6c1DRERERETJiyNpqMSjhQ8Y+fMSzmTFBvvJjreilyho6c1D%0ARERERETJi+tOQ0aGcbCf7HgreomClt48RERERESUvIRfhN5veomClt48RERE%0ARESUPCYNRERERERkikkDERERERGZYtJARERERESmDk3SQEREREREPwaTBiIi%0AIiIiMsWkgYiIiIiITDFpICIiIiIiU0waiIiIiIjIFJMGIiIiIiIy9YucIBAR%0AERERERnRvdNARIdPeuYxShG9+iUiIjrKmDQQ/ST0gl9KjF79EhERHWVMGoh+%0AEnrBLyVGr36JiIiOMiYNRD8JveCXEqNXv0REREcZkwain4Re8EuJ0atfIiKi%0Ao4xJA/0QBUXFuFx/FTfaOvBH03WcOftfutORfXrBLyVGr36JiIiOspQkDf/f%0AH426w4n0XGu5gc9L/8K7sRWy6lnH3XsPkFdYpDsPWdMLfs1o69+K3vw/M736%0AjUdB0VkMPx/Fv6sepf4WPy/hTvd93WmJiIgOg5QkDfJJcfj5Pygtr9Qdf1QF%0AAy7t//VEz/cza23rCG339PtZdD/4Cy9ejYeGPe4b1J3vRzqV34E3/gnczC+M%0Aa9x+0wt+zcj17Vn/in/GwvVvRG/+/ZJ28QP+H/4XcxczdcdbScvowX/jf/Aw%0Aw/78evUbjws1tTF1uP51c1+S4oPUJ/fKUdhGIqKDJmVJg0y+qtZ+u1M6MepP%0AZ+ZUvhO9S374l56gxuREoJ4s/Pj+/bvC719Cb+3BPHHIQbFM+3890fMF6yK4%0AjeFtDZ8kax4vRY6b6NDMH1lHss+PnaHxQWZl7IWSsnPKHYVgf+kbeKoMv9lx%0AOzRM5rxcHzNvkLZurNperx716sGKWYBykIIXveDXjFzXcx8WcOr/5KF/YCii%0ADaJFz5uW4cTc/0LnX3zB+X7Y76TBca4CFy9dweDQsGLuw8dQPeafOas7T1Ai%0AfTY4z5t2tQ/uV5/UHj+sjtupdpD2OyKioyKlSUPQ2+l3+O33Wt1pjcgnoM9L%0ASzaThvDJ4lT7xL6fsPaTUi9RQcPNidjkShkWCPpj6igQVGiTAqsy9kL7LVdE%0APzFKGvqfDsXMGySvo93AX93ucGKh1ks4uLLLLEA5SMGLXvBrJljfM+/nlMSh%0Ab/BpRDto6c0fVDv/v/h/807dcQfBfiYN8iN2evUXdPvPu/ji3VD6vN78ifTZ%0AH5E0RB8/TtU+wZsEEvJEHaT9jojoqNiTpEH2xfsVf/3dizNnS3Tn0ZJPOJ/l%0AE5AmAVCG6VxJjj5ZaH+r8xiMC/5fWobdK3jJ0t5J0N5ZiBY9n1Z00hC9jaHh%0Ayvap9RVdR+r4cGBhpwzt8FR59Lgvoo8YJQ0Tb6dj5pWF+kn0ehv2lcgATBZM%0AOoJ18EYOfgJ1oQ4LX+WNCcJ0+k50XctJbHCayL48gd7AlVl1efJ8gTsmoWRP%0AbaPg/PEmN3rBrxltnTffaEVxyX8p+612eJDe/EF6SUPaX/8TuPMg/fvfD6iV%0AAnb1MaP/wX8ro/4HDy7OK7/npPnVf3JgLwf4gX//06OWpQn6Q//XlB9ctjpO%0A809n/uD6WdGrXzs+LS3r1p/s/dyHUFLh/rysO79Rn/3Ue1PpGxHHAqmv7b55%0AGNFn5L5k1l+V+RLo51rB/hx9/IgcH+9+pN/3Lcsy2e/k4URElDp7ljQEWT2j%0Arj1J2rlrEH2ykIPqUNAVdTLTTqv+P3wl3erElwrBOtD+X0/0fFoxSYNcRwZ3%0AA+TgQj6pRtdRULAsO2XojUvWg55Hutsf7dX4hO786no/CQUX1n0lMgBT6yXQ%0A1wLBSGRwoplW8zum7wR+R9e1Mo9mnUL1HVhWsB2Vq7QR/VLT/w3axQ694NdM%0AsL7/vNslJfdnsfjJOODVmz8oOmlQkoNAoqAdryYNwH//pQ4P/g7O+zCQTIST%0AA/U9htikQZ4skBAEEpHohMBofu00ZvTq1w7PF69SX0vLK2hubUOXlCTI7+38%0A2XUPN262w/1pSRkvJ2d685v22ajjY3h/VwPuUF+O7q9K/9P0Ubv9XDOf/DtI%0Ae8yNlmj5en3fuizz/U5bFhERJW/Pkgb5ipv8lRy96bW0B/jok6Ke4IkneFVJ%0Ae3LQnoTC0wZOLJr/q+MiT84HVfQJ0OyEbZU0yOPlsuyUoTcuWVf/aIroI0Z3%0AGuRAK3pembLemiAiuD3R0wUFg6lgX5GFAqvovqITtJjVZ3DZ2nHy+mmXJZPL%0AjF6Wtv61AZ86nRRUWewDRvSCXzNyXb+bm0fxf5WaJgwyvfmDopMG+XfMPynI%0Ajw7wo38r84XuDqjvTMgJRmzSoClDmS78knT0uxbR88vT2KFXv3bMf3Qr9fXg%0Ar78xOTUTU49ByytruvOb9lmlr+kEzbpJg6Zva+eLo58bHSPNjh+Jlq/X9+2W%0AZbTfaecjIqLkpTxpWP+6hSf9gygqcehOq6V3glQO+CZBk/ZkoT0ZKuMOWNIg%0AB8XBwDj4fz3R82nJJ0SzxCg0XFMX0duqjo8+QZuXoR2eKvIL8jPv5kJ9Jbjt%0A2qRBDqZKHOUx88qigwi9oELLrI1j+kocwU5wnF7SoLc+0csyShpC00vrIu8H%0A2mF26AW/ZoJ1Lj9jH/y/0TTRw7V0k4ZA8K+110mD+khU8O6C/vzyPHbo1a8d%0AN9tvw7O+odxZCN510PPw717d+a2OS8Hjgfa4EN2Hovurdr+Op58brYtShsEx%0AOtnytX3fbllG+x0REaXSGfz/wnT9jNevfRcAAAAASUVORK5CYII=) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232.md" index 24a5dcfac6bcd0088ec1bbb162a77ce54c5758cc..d5ee2d94b13e1dc5d0bb13cf8bd11440f1b09b64 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232.md" @@ -1,29 +1,29 @@ -# 什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景 -''' -关系型数据库: -创建在关系模型基础上的数据库, 用来存储和管理结构化的数据; -例如:某个门店的vip会员数据,有用户名、手机号、余额等形成结构化信息的数据表, -同时又有个人消费情况的消费信息数据表,通过用户名或者手机号可查询; - -非关系型数据库: -创建在Nosql系统存储(键对值)基础上的数据库, 既可以存储结构化的数据, 也可以存储非结构化的数据; -例如:一个包含姓名和个人简介的数据库; - -区别: -一个通过关系型数据库存储,一个通过其他方式如键对值存储; -''' - -# 什么是事务, 事务的特点 -''' -事务是关系型数据库操作的基本工作单元; -特点: -1、原子性(Atomicity):全部操作不可分割,要么全部完成,要么全部不执行; -2、一致性(Consistency):执行结果一致,不管是否是多个事务同时执行或者先后执行; -3、隔离性(Isolation):事务执行不受其他事务影响; -4、持久性(Durability):即便数据库出现故障,已提交的事务对数据库的改变也不会丢失; -''' -# 完成Mysql服务端和Navicat的安装 - -# 完成数据库和数据表的基础操作 - +# 什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景 +''' +关系型数据库: +创建在关系模型基础上的数据库, 用来存储和管理结构化的数据; +例如:某个门店的vip会员数据,有用户名、手机号、余额等形成结构化信息的数据表, +同时又有个人消费情况的消费信息数据表,通过用户名或者手机号可查询; + +非关系型数据库: +创建在Nosql系统存储(键对值)基础上的数据库, 既可以存储结构化的数据, 也可以存储非结构化的数据; +例如:一个包含姓名和个人简介的数据库; + +区别: +一个通过关系型数据库存储,一个通过其他方式如键对值存储; +''' + +# 什么是事务, 事务的特点 +''' +事务是关系型数据库操作的基本工作单元; +特点: +1、原子性(Atomicity):全部操作不可分割,要么全部完成,要么全部不执行; +2、一致性(Consistency):执行结果一致,不管是否是多个事务同时执行或者先后执行; +3、隔离性(Isolation):事务执行不受其他事务影响; +4、持久性(Durability):即便数据库出现故障,已提交的事务对数据库的改变也不会丢失; +''' +# 完成Mysql服务端和Navicat的安装 + +# 完成数据库和数据表的基础操作 + # ![20210127sql](http://typorabypicgo.zhanghm.cc/20210127sql.png) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" index 72f700ce1de55709684b5de83372e16be48ac813..581bf92786326307297f1b55f9347995aa620d23 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232.md" @@ -1,18 +1,18 @@ -#### 第七周-第2节作业 - -- 通过navicat建表, 包含当前常用的数据类型. - - ``` - INSERT INTO test(float_field, double_field) values(123.22, 123123.22) - ``` - - ![20210129_table](http://typorabypicgo.zhanghm.cc/20210129_table.png) - -- 练习常用的运算符 - - ![20210129_operators](http://typorabypicgo.zhanghm.cc/20210129_operators.png) - -- 练习常用的函数 - - ![20210129_functions](http://typorabypicgo.zhanghm.cc/20210129_functions.png) - +#### 第七周-第2节作业 + +- 通过navicat建表, 包含当前常用的数据类型. + + ``` + INSERT INTO test(float_field, double_field) values(123.22, 123123.22) + ``` + + ![20210129_table](http://typorabypicgo.zhanghm.cc/20210129_table.png) + +- 练习常用的运算符 + + ![20210129_operators](http://typorabypicgo.zhanghm.cc/20210129_operators.png) + +- 练习常用的函数 + + ![20210129_functions](http://typorabypicgo.zhanghm.cc/20210129_functions.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2543\350\212\202\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2543\350\212\202\344\275\234\344\270\232.md" index 987d735c033fcf09f2ffd1ce737e0845948f1425..3836215641c92139eb7e7a157f94478c0a01b6df 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2543\350\212\202\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\270\203\345\221\250-\347\254\2543\350\212\202\344\275\234\344\270\232.md" @@ -1,78 +1,78 @@ -#### 第七周-第3节作业 - -- 练习CRUD操作 - -增-单条插入: - -![insert_one](http://typorabypicgo.zhanghm.cc/insert_one.png) - -增-多条插入 - -![insert_many](http://typorabypicgo.zhanghm.cc/insert_many.png) - -retrieve:获取所有记录 - -![retrieve_all_records](http://typorabypicgo.zhanghm.cc/retrieve_all_records.png) - - - -条件查询: - -![retrieve_by_condition](http://typorabypicgo.zhanghm.cc/retrieve_by_condition.png) - -模糊匹配: - -![retrieve_fuzzy_match](http://typorabypicgo.zhanghm.cc/retrieve_fuzzy_match.png) - -限制返回条数: - -![limit](http://typorabypicgo.zhanghm.cc/limit.png) - -过滤重复值: - -![distinct](http://typorabypicgo.zhanghm.cc/distinct.png) - -排序-升序: - -![order_ASC_升序](http://typorabypicgo.zhanghm.cc/order_ASC_%E5%8D%87%E5%BA%8F.png) - -排序-降序: - -![order_DESC_降序](http://typorabypicgo.zhanghm.cc/order_DESC_%E9%99%8D%E5%BA%8F.png) - -结果条数: - -![count](http://typorabypicgo.zhanghm.cc/count.png) - -update更新: - -![update_更新](http://typorabypicgo.zhanghm.cc/update_%E6%9B%B4%E6%96%B0.png) - -delete删除: - -![DELETE_删除](http://typorabypicgo.zhanghm.cc/DELETE_%E5%88%A0%E9%99%A4.png) - - - -练习集合操作 - -并集: - -![union_并集](http://typorabypicgo.zhanghm.cc/union_%E5%B9%B6%E9%9B%86.png) - -交集: - -![join_交集](http://typorabypicgo.zhanghm.cc/join_%E4%BA%A4%E9%9B%86.png) - -差集_left: - -![差集_left_join](http://typorabypicgo.zhanghm.cc/%E5%B7%AE%E9%9B%86_left_join.png) - -差集_right: - -![差集_right_join](http://typorabypicgo.zhanghm.cc/%E5%B7%AE%E9%9B%86_right_join.png) - -补集: - -![补集p](http://typorabypicgo.zhanghm.cc/%E8%A1%A5%E9%9B%86p.png) - +#### 第七周-第3节作业 + +- 练习CRUD操作 + +增-单条插入: + +![insert_one](http://typorabypicgo.zhanghm.cc/insert_one.png) + +增-多条插入 + +![insert_many](http://typorabypicgo.zhanghm.cc/insert_many.png) + +retrieve:获取所有记录 + +![retrieve_all_records](http://typorabypicgo.zhanghm.cc/retrieve_all_records.png) + + + +条件查询: + +![retrieve_by_condition](http://typorabypicgo.zhanghm.cc/retrieve_by_condition.png) + +模糊匹配: + +![retrieve_fuzzy_match](http://typorabypicgo.zhanghm.cc/retrieve_fuzzy_match.png) + +限制返回条数: + +![limit](http://typorabypicgo.zhanghm.cc/limit.png) + +过滤重复值: + +![distinct](http://typorabypicgo.zhanghm.cc/distinct.png) + +排序-升序: + +![order_ASC_升序](http://typorabypicgo.zhanghm.cc/order_ASC_%E5%8D%87%E5%BA%8F.png) + +排序-降序: + +![order_DESC_降序](http://typorabypicgo.zhanghm.cc/order_DESC_%E9%99%8D%E5%BA%8F.png) + +结果条数: + +![count](http://typorabypicgo.zhanghm.cc/count.png) + +update更新: + +![update_更新](http://typorabypicgo.zhanghm.cc/update_%E6%9B%B4%E6%96%B0.png) + +delete删除: + +![DELETE_删除](http://typorabypicgo.zhanghm.cc/DELETE_%E5%88%A0%E9%99%A4.png) + + + +练习集合操作 + +并集: + +![union_并集](http://typorabypicgo.zhanghm.cc/union_%E5%B9%B6%E9%9B%86.png) + +交集: + +![join_交集](http://typorabypicgo.zhanghm.cc/join_%E4%BA%A4%E9%9B%86.png) + +差集_left: + +![差集_left_join](http://typorabypicgo.zhanghm.cc/%E5%B7%AE%E9%9B%86_left_join.png) + +差集_right: + +![差集_right_join](http://typorabypicgo.zhanghm.cc/%E5%B7%AE%E9%9B%86_right_join.png) + +补集: + +![补集p](http://typorabypicgo.zhanghm.cc/%E8%A1%A5%E9%9B%86p.png) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-1.py" index 0659188023ceeb8e886ea3b6b745dcdc4dd9fdde..da6e2aeaaf55fbeb805f8269f0edc5e3a64ed2ac 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-1.py" @@ -1,28 +1,28 @@ -# 完成京东搜索页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) -import requests -from urllib.parse import quote, unquote -def request_jd(keyword): - url = "https://search.jd.com/Search" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" - } - response = requests.get(url=url, params=params, headers=headers, verify=False) - print(response.text) # 获取str类型的响应内容 - # response.content # 获取bytes类型的响应内容 - # response.json() # 获取json格式数据 - f = open(keyword + "-搜索结果.html", "w", encoding="utf-8") - f.write(response.text) - f.close() - - -if __name__ == "__main__": - kw = ["路由器", "电脑", "音箱", "硬盘", "相机", "数据线", "耳机", "智能手环", "显示器", "键盘"] - for i in kw: - request_jd(i) - - - - +# 完成京东搜索页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) +import requests +from urllib.parse import quote, unquote +def request_jd(keyword): + url = "https://search.jd.com/Search" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" + } + response = requests.get(url=url, params=params, headers=headers, verify=False) + print(response.text) # 获取str类型的响应内容 + # response.content # 获取bytes类型的响应内容 + # response.json() # 获取json格式数据 + f = open(keyword + "-搜索结果.html", "w", encoding="utf-8") + f.write(response.text) + f.close() + + +if __name__ == "__main__": + kw = ["路由器", "电脑", "音箱", "硬盘", "相机", "数据线", "耳机", "智能手环", "显示器", "键盘"] + for i in kw: + request_jd(i) + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-2.py" index e9c5324998694ce2babe74851b7e017808b4d888..c3f9cb71d2bb19386563ffc9222cc9ac7b7e798b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-2.py" @@ -1,35 +1,35 @@ -# 完成京东详情页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) -import requests -import re -import time -from urllib.parse import quote, unquote - -def get_id(kw): - url = "https://search.jd.com/Search" - params = { - "keyword": kw - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" - } - response = requests.get(url=url, params=params, headers=headers, verify=False) - - pattern = re.compile('//item.jd.com/([0-9]*?).html') # 定义一个正则表达式,找到搜索结果页面第一个产品id - s = response.text - n = re.search(pattern, s) - id = n.group(1) # 进行匹配,找到id - return id - - -url1 = "https://item.jd.com/" -kw = ["路由器", "电脑", "音箱", "硬盘", "相机", "数据线", "耳机", "智能手环", "显示器", "键盘"] -for i in kw: - url = url1 + get_id(i) + ".html" - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" - } - response = requests.get(url=url, headers=headers) - print(response.text) - f = open(i + "-详情.html", "w", encoding="utf-8") - f.write(response.text) - f.close() +# 完成京东详情页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) +import requests +import re +import time +from urllib.parse import quote, unquote + +def get_id(kw): + url = "https://search.jd.com/Search" + params = { + "keyword": kw + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" + } + response = requests.get(url=url, params=params, headers=headers, verify=False) + + pattern = re.compile('//item.jd.com/([0-9]*?).html') # 定义一个正则表达式,找到搜索结果页面第一个产品id + s = response.text + n = re.search(pattern, s) + id = n.group(1) # 进行匹配,找到id + return id + + +url1 = "https://item.jd.com/" +kw = ["路由器", "电脑", "音箱", "硬盘", "相机", "数据线", "耳机", "智能手环", "显示器", "键盘"] +for i in kw: + url = url1 + get_id(i) + ".html" + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" + } + response = requests.get(url=url, headers=headers) + print(response.text) + f = open(i + "-详情.html", "w", encoding="utf-8") + f.write(response.text) + f.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-3.py" index 6914f7e386fca67e788787f669f7599e0b00d33e..d49f86517689f5761a1a929798eb23edde374ca5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2541\350\212\202\344\275\234\344\270\232-3.py" @@ -1,12 +1,12 @@ -import json - -test_dict = { - "a":1, - "b": ["1", 2, None], - "c": {"d": 1} -} - -json_data = json.dumps(test_dict) -print(type(json_data),json_data) - +import json + +test_dict = { + "a":1, + "b": ["1", 2, None], + "c": {"d": 1} +} + +json_data = json.dumps(test_dict) +print(type(json_data),json_data) + print(json.loads(json_data)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/homework-9.2.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/homework-9.2.1.py" index 558a1bec397977cf981ab3e2413b798f0482ed4f..b8c940534492da08895410953db8ca94106d5bb1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/homework-9.2.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/homework-9.2.1.py" @@ -1,15 +1,15 @@ -from bs4 import BeautifulSoup - - -def jd_search_parse(html): - html = html.replace('\r\n', '').replace('\n', '').replace('\t', '') - soup = BeautifulSoup(html, "lxml") - item = soup.select("li[data-sku='6039832']")[0] - print(item.next_sibling.next_sibling) - - -if __name__ == "__main__": - with open("jd_search.html", "r", encoding="utf-8") as f: - html = f.read() - jd_search_parse(html) - +from bs4 import BeautifulSoup + + +def jd_search_parse(html): + html = html.replace('\r\n', '').replace('\n', '').replace('\t', '') + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='6039832']")[0] + print(item.next_sibling.next_sibling) + + +if __name__ == "__main__": + with open("jd_search.html", "r", encoding="utf-8") as f: + html = f.read() + jd_search_parse(html) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/jd_search.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/jd_search.html" index 6dca40fca0e3b76635b3646c8abc1e612ea38e2e..d654540dfa00c5523afa69df6d682a8dd7b4b237 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/jd_search.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255-\346\255\246\346\230\216-\347\254\254\344\271\235\345\221\250-\347\254\2542\350\212\202\344\275\234\344\270\232/jd_search.html" @@ -135,145 +135,145 @@ SEARCH.base_url="keyword=%E9%BC%A0%E6%A0%87&wq=%E9%BC%A0%E6%A0%87"; - -
                                                                                      -
                                                                                      - - - -
                                                                                      -
                                                                                      -
                                                                                      -
                                                                                      -
                                                                                      - -
                                                                                      -
                                                                                      -
                                                                                        -
                                                                                        - - -
                                                                                        -
                                                                                        -
                                                                                        -
                                                                                        - - - 我的购物车 -
                                                                                        -
                                                                                        -
                                                                                        -
                                                                                        - -
                                                                                        -
                                                                                        -
                                                                                        -
                                                                                        - -
                                                                                        - + +
                                                                                        +
                                                                                        + + + +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + +
                                                                                        +
                                                                                        +
                                                                                          +
                                                                                          + + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + + + 我的购物车 +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + +
                                                                                          +
                                                                                          @@ -6062,252 +6062,252 @@ href="//item.jd.com/4462467.html#comment"
                                                                                          - -
                                                                                          -
                                                                                          -
                                                                                            -
                                                                                          1. - 品类齐全,轻松购物 -
                                                                                          2. -
                                                                                          3. - 多仓直发,极速配送 -
                                                                                          4. -
                                                                                          5. - 正品行货,精致服务 -
                                                                                          6. -
                                                                                          7. - 天天低价,畅选无忧 -
                                                                                          8. -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          购物指南
                                                                                          -
                                                                                          - 购物流程 -
                                                                                          -
                                                                                          - 会员介绍 -
                                                                                          -
                                                                                          - 生活旅行/团购 -
                                                                                          -
                                                                                          - 常见问题 -
                                                                                          -
                                                                                          - 大家电 -
                                                                                          -
                                                                                          - 联系客服 -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          配送方式
                                                                                          -
                                                                                          - 上门自提 -
                                                                                          -
                                                                                          - 211限时达 -
                                                                                          -
                                                                                          - 配送服务查询 -
                                                                                          -
                                                                                          - 配送费收取标准 -
                                                                                          -
                                                                                          - 海外配送 -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          支付方式
                                                                                          -
                                                                                          - 货到付款 -
                                                                                          -
                                                                                          - 在线支付 -
                                                                                          -
                                                                                          - 分期付款 -
                                                                                          -
                                                                                          - 公司转账 -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          售后服务
                                                                                          -
                                                                                          - 售后政策 -
                                                                                          -
                                                                                          - 价格保护 -
                                                                                          -
                                                                                          - 退款说明 -
                                                                                          -
                                                                                          - 返修/退换货 -
                                                                                          -
                                                                                          - 取消订单 -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          特色服务
                                                                                          -
                                                                                          - 夺宝岛 -
                                                                                          -
                                                                                          - DIY装机 -
                                                                                          -
                                                                                          - 延保服务 -
                                                                                          -
                                                                                          - 京东E卡 -
                                                                                          -
                                                                                          - 京东通信 -
                                                                                          -
                                                                                          - 京鱼座智能 -
                                                                                          -
                                                                                          - -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          - - -
                                                                                          - - + 可信网站信用评估 + 网络警察提醒你 + 诚信网站 + 网上有害信息举报专区 + 网络举报APP下载 +

                                                                                          +
                                                                                          + +
                                                                                          + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                          -
                                                                                          - - - -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          -
                                                                                          - -
                                                                                          -
                                                                                          -
                                                                                            -
                                                                                            - - -
                                                                                            -
                                                                                            -
                                                                                            -
                                                                                            - - - 我的购物车 -
                                                                                            -
                                                                                            -
                                                                                            -
                                                                                            - -
                                                                                            -
                                                                                            -
                                                                                            -
                                                                                            - -
                                                                                            - - -
                                                                                            - - -
                                                                                            -
                                                                                            -
                                                                                            -
                                                                                            - -
                                                                                            - > -
                                                                                            - "鼠标" -
                                                                                            -
                                                                                            -
                                                                                            -
                                                                                            - -
                                                                                            - -
                                                                                            - -
                                                                                            -
                                                                                            -
                                                                                            品牌:
                                                                                            -
                                                                                            -
                                                                                              -
                                                                                            • 所有品牌
                                                                                            • -
                                                                                            • A
                                                                                            • -
                                                                                            • B
                                                                                            • -
                                                                                            • C
                                                                                            • -
                                                                                            • D
                                                                                            • -
                                                                                            • E
                                                                                            • -
                                                                                            • F
                                                                                            • -
                                                                                            • G
                                                                                            • -
                                                                                            • H
                                                                                            • -
                                                                                            • I
                                                                                            • -
                                                                                            • J
                                                                                            • -
                                                                                            • K
                                                                                            • -
                                                                                            • L
                                                                                            • -
                                                                                            • M
                                                                                            • -
                                                                                            • N
                                                                                            • -
                                                                                            • O
                                                                                            • -
                                                                                            • P
                                                                                            • -
                                                                                            • Q
                                                                                            • -
                                                                                            • R
                                                                                            • -
                                                                                            • S
                                                                                            • -
                                                                                            • T
                                                                                            • -
                                                                                            • U
                                                                                            • -
                                                                                            • W
                                                                                            • -
                                                                                            • X
                                                                                            • -
                                                                                            • Y
                                                                                            • -
                                                                                            • Z
                                                                                            • -
                                                                                            -
                                                                                            -
                                                                                            - -
                                                                                            -
                                                                                            已选条件:
                                                                                              -
                                                                                              - 确定 - 取消 -
                                                                                              -
                                                                                              -
                                                                                              - 更多 - 多选 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              外设产品:
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              - 确定 - 取消 -
                                                                                              -
                                                                                              -
                                                                                              - 更多 - -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              电脑整机:
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              - 确定 - 取消 -
                                                                                              -
                                                                                              -
                                                                                              - 更多 - -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              连接方式:
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              - 确定 - 取消 -
                                                                                              -
                                                                                              -
                                                                                              - 更多 - 多选 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              适用场景:
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              - 确定 - 取消 -
                                                                                              -
                                                                                              -
                                                                                              - 更多 - 多选 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              高级选项:
                                                                                              - -
                                                                                              - - - - - - - - - - - - - - - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              - -
                                                                                              - - - - - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - - -
                                                                                              -
                                                                                              -
                                                                                              - - 清空 - 确定 -
                                                                                              -
                                                                                              -
                                                                                              - - 1/100 - - < - > -
                                                                                              -
                                                                                              69万+件商品
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              配送至
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              北京
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - - -
                                                                                              -
                                                                                              - - -
                                                                                              - - - -
                                                                                              -
                                                                                              正在加载中,请稍后~~
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - -

                                                                                              商品精选

                                                                                              -
                                                                                              -
                                                                                                -
                                                                                              -
                                                                                              -
                                                                                              -

                                                                                              精品推荐

                                                                                              - -
                                                                                              -
                                                                                              - -
                                                                                              - - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              商品精选
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                                -
                                                                                              1. - 品类齐全,轻松购物 -
                                                                                              2. -
                                                                                              3. - 多仓直发,极速配送 -
                                                                                              4. -
                                                                                              5. - 正品行货,精致服务 -
                                                                                              6. -
                                                                                              7. - 天天低价,畅选无忧 -
                                                                                              8. -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              购物指南
                                                                                              -
                                                                                              - 购物流程 -
                                                                                              -
                                                                                              - 会员介绍 -
                                                                                              -
                                                                                              - 生活旅行/团购 -
                                                                                              -
                                                                                              - 常见问题 -
                                                                                              -
                                                                                              - 大家电 -
                                                                                              -
                                                                                              - 联系客服 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              配送方式
                                                                                              -
                                                                                              - 上门自提 -
                                                                                              -
                                                                                              - 211限时达 -
                                                                                              -
                                                                                              - 配送服务查询 -
                                                                                              -
                                                                                              - 配送费收取标准 -
                                                                                              -
                                                                                              - 海外配送 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              支付方式
                                                                                              -
                                                                                              - 货到付款 -
                                                                                              -
                                                                                              - 在线支付 -
                                                                                              -
                                                                                              - 分期付款 -
                                                                                              -
                                                                                              - 公司转账 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              售后服务
                                                                                              -
                                                                                              - 售后政策 -
                                                                                              -
                                                                                              - 价格保护 -
                                                                                              -
                                                                                              - 退款说明 -
                                                                                              -
                                                                                              - 返修/退换货 -
                                                                                              -
                                                                                              - 取消订单 -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              特色服务
                                                                                              -
                                                                                              - 夺宝岛 -
                                                                                              -
                                                                                              - DIY装机 -
                                                                                              -
                                                                                              - 延保服务 -
                                                                                              -
                                                                                              - 京东E卡 -
                                                                                              -
                                                                                              - 京东通信 -
                                                                                              -
                                                                                              - 京鱼座智能 -
                                                                                              -
                                                                                              - -
                                                                                              -
                                                                                              -
                                                                                              -
                                                                                              - - -
                                                                                              - - - - - + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              +
                                                                                              + + + +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + +
                                                                                              +
                                                                                              +
                                                                                                +
                                                                                                + + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + + + 我的购物车 +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                + + +
                                                                                                + + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                + > +
                                                                                                + "鼠标" +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                + +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                品牌:
                                                                                                +
                                                                                                +
                                                                                                  +
                                                                                                • 所有品牌
                                                                                                • +
                                                                                                • A
                                                                                                • +
                                                                                                • B
                                                                                                • +
                                                                                                • C
                                                                                                • +
                                                                                                • D
                                                                                                • +
                                                                                                • E
                                                                                                • +
                                                                                                • F
                                                                                                • +
                                                                                                • G
                                                                                                • +
                                                                                                • H
                                                                                                • +
                                                                                                • I
                                                                                                • +
                                                                                                • J
                                                                                                • +
                                                                                                • K
                                                                                                • +
                                                                                                • L
                                                                                                • +
                                                                                                • M
                                                                                                • +
                                                                                                • N
                                                                                                • +
                                                                                                • O
                                                                                                • +
                                                                                                • P
                                                                                                • +
                                                                                                • Q
                                                                                                • +
                                                                                                • R
                                                                                                • +
                                                                                                • S
                                                                                                • +
                                                                                                • T
                                                                                                • +
                                                                                                • U
                                                                                                • +
                                                                                                • W
                                                                                                • +
                                                                                                • X
                                                                                                • +
                                                                                                • Y
                                                                                                • +
                                                                                                • Z
                                                                                                • +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                +
                                                                                                已选条件:
                                                                                                  +
                                                                                                  + 确定 + 取消 +
                                                                                                  +
                                                                                                  +
                                                                                                  + 更多 + 多选 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  外设产品:
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  + 确定 + 取消 +
                                                                                                  +
                                                                                                  +
                                                                                                  + 更多 + +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  电脑整机:
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  + 确定 + 取消 +
                                                                                                  +
                                                                                                  +
                                                                                                  + 更多 + +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  连接方式:
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  + 确定 + 取消 +
                                                                                                  +
                                                                                                  +
                                                                                                  + 更多 + 多选 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  适用场景:
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  + 确定 + 取消 +
                                                                                                  +
                                                                                                  +
                                                                                                  + 更多 + 多选 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  高级选项:
                                                                                                  + +
                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  + +
                                                                                                  + + + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + - +
                                                                                                  +
                                                                                                  +
                                                                                                  + + 清空 + 确定 +
                                                                                                  +
                                                                                                  +
                                                                                                  + + 1/100 + + < + > +
                                                                                                  +
                                                                                                  69万+件商品
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  配送至
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  北京
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + +
                                                                                                  +
                                                                                                  + + +
                                                                                                  + + + +
                                                                                                  +
                                                                                                  正在加载中,请稍后~~
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + +

                                                                                                  商品精选

                                                                                                  +
                                                                                                  +
                                                                                                    +
                                                                                                  +
                                                                                                  +
                                                                                                  +

                                                                                                  精品推荐

                                                                                                  + +
                                                                                                  +
                                                                                                  + +
                                                                                                  + + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  商品精选
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                    +
                                                                                                  1. + 品类齐全,轻松购物 +
                                                                                                  2. +
                                                                                                  3. + 多仓直发,极速配送 +
                                                                                                  4. +
                                                                                                  5. + 正品行货,精致服务 +
                                                                                                  6. +
                                                                                                  7. + 天天低价,畅选无忧 +
                                                                                                  8. +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  购物指南
                                                                                                  +
                                                                                                  + 购物流程 +
                                                                                                  +
                                                                                                  + 会员介绍 +
                                                                                                  +
                                                                                                  + 生活旅行/团购 +
                                                                                                  +
                                                                                                  + 常见问题 +
                                                                                                  +
                                                                                                  + 大家电 +
                                                                                                  +
                                                                                                  + 联系客服 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  配送方式
                                                                                                  +
                                                                                                  + 上门自提 +
                                                                                                  +
                                                                                                  + 211限时达 +
                                                                                                  +
                                                                                                  + 配送服务查询 +
                                                                                                  +
                                                                                                  + 配送费收取标准 +
                                                                                                  +
                                                                                                  + 海外配送 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  支付方式
                                                                                                  +
                                                                                                  + 货到付款 +
                                                                                                  +
                                                                                                  + 在线支付 +
                                                                                                  +
                                                                                                  + 分期付款 +
                                                                                                  +
                                                                                                  + 公司转账 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  售后服务
                                                                                                  +
                                                                                                  + 售后政策 +
                                                                                                  +
                                                                                                  + 价格保护 +
                                                                                                  +
                                                                                                  + 退款说明 +
                                                                                                  +
                                                                                                  + 返修/退换货 +
                                                                                                  +
                                                                                                  + 取消订单 +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  特色服务
                                                                                                  +
                                                                                                  + 夺宝岛 +
                                                                                                  +
                                                                                                  + DIY装机 +
                                                                                                  +
                                                                                                  + 延保服务 +
                                                                                                  +
                                                                                                  + 京东E卡 +
                                                                                                  +
                                                                                                  + 京东通信 +
                                                                                                  +
                                                                                                  + 京鱼座智能 +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + +
                                                                                                  + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/search.py" index 3b8df878b480bef2b9298f094f3d999f870f2b7c..a6b17f55571862df3d438fea82ce23529c3779cd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/search.py" @@ -1,34 +1,34 @@ -from bs4 import BeautifulSoup -import json - -def parse_jd_item(html): - result = [] - - soup = BeautifulSoup(html, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - try: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].a.attrs['title'] if shop[0].text.strip() else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' - - result.append((sku_id, img, price, title, shop, icons)) - except Exception as e: - print(e.args) - return result - - -if __name__ == "__main__": - with open(r"G:\chihai\chihai_2\practice\jd_crawler\test\search.html", "r", encoding="utf-8") as f: - html = f.read() - result = parse_jd_item(html) +from bs4 import BeautifulSoup +import json + +def parse_jd_item(html): + result = [] + + soup = BeautifulSoup(html, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + try: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select("i")]) if icons else '[]' + + result.append((sku_id, img, price, title, shop, icons)) + except Exception as e: + print(e.args) + return result + + +if __name__ == "__main__": + with open(r"G:\chihai\chihai_2\practice\jd_crawler\test\search.html", "r", encoding="utf-8") as f: + html = f.read() + result = parse_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/settings.py" index 8cdb3acb6825c49d91b89f344ded731a03880ac9..3941397644263b6ae7dbbdc5253f444233af19b6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/4\347\217\255/4\347\217\255_\346\255\246\346\230\216/4\347\217\255_\346\255\246\346\230\216_\347\254\254\344\271\235\345\221\250_\347\254\2543\350\212\202\344\275\234\344\270\232/settings.py" @@ -1,12 +1,12 @@ -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36", - "upgrade-insecure-requests": "1" -} - - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "my2580my", - "db": "tunan_class" +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36", + "upgrade-insecure-requests": "1" +} + + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "my2580my", + "db": "tunan_class" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232 12.14 - 12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232 12.14 - 12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" index a08d23e320148b4df23355949502255a5f57b291..098c24b40d7b747f6d80514176c19d75f7da5457 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232 12.14 - 12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232 12.14 - 12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" @@ -1,4 +1,4 @@ -1.四大数据结构中可变的:list,dict, set; - 不可变的:tuple. -2.四大数据结构中有序的:list, tuple; +1.四大数据结构中可变的:list,dict, set; + 不可变的:tuple. +2.四大数据结构中有序的:list, tuple; 无序的:dict, set. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\2321.25-1.31/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\2321.25-1.31/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 9b84d7578bd1b768e13f0e1f93909a2fd48311b6..0fea17a097105c48799d57ea79b183077b00eada 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\2321.25-1.31/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\203\345\221\250\344\275\234\344\270\2321.25-1.31/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,24 +1,24 @@ -# 1.什么是关系型数据表,什么是非关系型数据表,区别和应用场景 -# 关系型数据库 -# 创建在关系模型基础上的数据库,用来存储和管理结构化的数据 -# 特点: -# 原子性:指事务的操作是不可分割的,要么完成要么不完成,不存在其他的中间态 -# 一致性:事务A和事务B同时运行,无论谁先结束,数据库都会到达一致 -# 隔离性:解决多个事务同时对数据进行读写和修改的能力 -# 持久性:当某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够被持久化地保存下来 -# 适用场景: -# 考虑到事务和日志 -# ·对数据完整性有要求 -# ·存储的数据结构化完整 -# ·单个数据库服务实例可以满足需求 -# ·读表操作远远大于写表操作 -# 非关系型数据库(Nosql) -# 创建在Nosql系统存储(键对值)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 - - -# 2.什么是事务,事务的特点 -# 事务是作为一个逻辑单元执行的一系列操作,要么一起成功,要么一起失败。特点同上。 - - -# 3.完成Mysql服务端和Navicat的安装 -# 4.完成数据库和数据表的基础操作 +# 1.什么是关系型数据表,什么是非关系型数据表,区别和应用场景 +# 关系型数据库 +# 创建在关系模型基础上的数据库,用来存储和管理结构化的数据 +# 特点: +# 原子性:指事务的操作是不可分割的,要么完成要么不完成,不存在其他的中间态 +# 一致性:事务A和事务B同时运行,无论谁先结束,数据库都会到达一致 +# 隔离性:解决多个事务同时对数据进行读写和修改的能力 +# 持久性:当某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能够被持久化地保存下来 +# 适用场景: +# 考虑到事务和日志 +# ·对数据完整性有要求 +# ·存储的数据结构化完整 +# ·单个数据库服务实例可以满足需求 +# ·读表操作远远大于写表操作 +# 非关系型数据库(Nosql) +# 创建在Nosql系统存储(键对值)基础上的数据库,既可以存储结构化的数据,也可以存储非结构化的数据 + + +# 2.什么是事务,事务的特点 +# 事务是作为一个逻辑单元执行的一系列操作,要么一起成功,要么一起失败。特点同上。 + + +# 3.完成Mysql服务端和Navicat的安装 +# 4.完成数据库和数据表的基础操作 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 61ce440c8548e1f2ac6e4c5d8bd6e22d8dabb954..7ccfb8feb698de0c050db50960569902edb47dbf 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,62 +1,62 @@ -# 第一题 -# for 循环的简单计数 -lst = [1, 2, 3, 4, 5] -for e in lst: - print(e) -# 获取索引值和值 -for x, e in enumerate(lst): - print(f"index:{x}, value:{e}") - -# while 的简单计数 -a = 0 -while True: - if a == 100: - break - print(a) - a += 1 - - -# 第二题 -# for语句实现斐波那契函数(100以内) -x = 0 -y = 1 -lst_2 = [x, y] -for n in lst_2: - n = x + y - x = y - y = n - lst_2.append(n) - if n >= 100: - lst_2.pop() -print(lst_2) - -# while语句实现斐波那契函数(100以内) -p = 0 -q = 1 -i = 0 -lst_3 = [p, q] -while True: - if i >= 100: - break - i = p + q - p = q - q = i - lst_3.append(i) -lst_3.pop() -print(lst_3) - - -# 第三题 抛出自定义异常 -class ParamsError(Exception): - pass - -def div(c, b): - try: - return c / b - except ZeroDivisionError: - raise ParamsError("分母不可为0") - finally: - print("function div end") - -div(1, 0) - +# 第一题 +# for 循环的简单计数 +lst = [1, 2, 3, 4, 5] +for e in lst: + print(e) +# 获取索引值和值 +for x, e in enumerate(lst): + print(f"index:{x}, value:{e}") + +# while 的简单计数 +a = 0 +while True: + if a == 100: + break + print(a) + a += 1 + + +# 第二题 +# for语句实现斐波那契函数(100以内) +x = 0 +y = 1 +lst_2 = [x, y] +for n in lst_2: + n = x + y + x = y + y = n + lst_2.append(n) + if n >= 100: + lst_2.pop() +print(lst_2) + +# while语句实现斐波那契函数(100以内) +p = 0 +q = 1 +i = 0 +lst_3 = [p, q] +while True: + if i >= 100: + break + i = p + q + p = q + q = i + lst_3.append(i) +lst_3.pop() +print(lst_3) + + +# 第三题 抛出自定义异常 +class ParamsError(Exception): + pass + +def div(c, b): + try: + return c / b + except ZeroDivisionError: + raise ParamsError("分母不可为0") + finally: + print("function div end") + +div(1, 0) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 5a66e99ca21cd42ec28eff4540f168d3addfef05..9b5a0fc0989b3113223545604fbb020dc03b2c51 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,42 +1,42 @@ -# 默写一个装饰器,用来输出函数的执行时间 -import time -def foo(a, b): - count = 1 - while True: - if count > (a + b) ** 2: - break - count += 1 - -def clock_it(func, a, b): - start_time = time.time() - result = func(a, b) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - -result = clock_it(foo, 99, 124) -print(result) - - -# 使用装饰器来为斐波那契函数添加缓存 -def cache_deco(func): - def wrapper(n, *args, **kwargs): - result = func(n, *args, **kwargs) - return result - return wrapper - - -@cache_deco -def fibo(n): - if n == 0: - return n - elif n == 1: - return n - else: - return fibo(n - 2) + fibo(n - 1) -print(fibo(12)) - - - - - +# 默写一个装饰器,用来输出函数的执行时间 +import time +def foo(a, b): + count = 1 + while True: + if count > (a + b) ** 2: + break + count += 1 + +def clock_it(func, a, b): + start_time = time.time() + result = func(a, b) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + +result = clock_it(foo, 99, 124) +print(result) + + +# 使用装饰器来为斐波那契函数添加缓存 +def cache_deco(func): + def wrapper(n, *args, **kwargs): + result = func(n, *args, **kwargs) + return result + return wrapper + + +@cache_deco +def fibo(n): + if n == 0: + return n + elif n == 1: + return n + else: + return fibo(n - 2) + fibo(n - 1) +print(fibo(12)) + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 36fff69e749394521feb842c54551b5e0b529baa..1302f8f5f2f8854737dfcc8838d8024434af6b9f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\23212.28-2021.1.3/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,37 +1,37 @@ -# 给定一个列表根据grade来排序 -from pprint import pprint -classes = [ - {"name": "N_1", "age": 21, "grade": "A"}, - {"name": "N_5", "age": 27, "grade": "A"}, - {"name": "N_4", "age": 19, "grade": "C"}, - {"name": "N_2", "age": 21, "grade": "D"}, - {"name": "N_3", "age": 22, "grade": "A"}, - {"name": "N_6", "age": 24, "grade": "B"}, -] -classes.sort(key=lambda x: x["grade"]) -pprint(classes) - - -# 通过filter语句筛选出a的同学 -f = filter(lambda x: True if x["grade"] == "A" else False, classes) -pprint(list(f)) - - -# 通过map函数将上述同学age加1 -def my_function_1(a): - a["age"] += 1 - return a -m = map(my_function_1, classes) -pprint(list(m)) - - -# 使用递归重构斐波那契函数 -def feibo(n): - if n == 0: - return n - elif n == 1: - return n - else: - return feibo(n - 1) + feibo(n - 2) -for i in range(12): +# 给定一个列表根据grade来排序 +from pprint import pprint +classes = [ + {"name": "N_1", "age": 21, "grade": "A"}, + {"name": "N_5", "age": 27, "grade": "A"}, + {"name": "N_4", "age": 19, "grade": "C"}, + {"name": "N_2", "age": 21, "grade": "D"}, + {"name": "N_3", "age": 22, "grade": "A"}, + {"name": "N_6", "age": 24, "grade": "B"}, +] +classes.sort(key=lambda x: x["grade"]) +pprint(classes) + + +# 通过filter语句筛选出a的同学 +f = filter(lambda x: True if x["grade"] == "A" else False, classes) +pprint(list(f)) + + +# 通过map函数将上述同学age加1 +def my_function_1(a): + a["age"] += 1 + return a +m = map(my_function_1, classes) +pprint(list(m)) + + +# 使用递归重构斐波那契函数 +def feibo(n): + if n == 0: + return n + elif n == 1: + return n + else: + return feibo(n - 1) + feibo(n - 2) +for i in range(12): print(feibo(i)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/main.py" index 8e9892525a3692e00db51e0b5bb9f991b67aa6ff..ec2a61aca9f6dcdec29f1046ed846de4f738d987 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/main.py" @@ -1,55 +1,55 @@ -#定义加法运算 -def add(a, b): - result = a + b - return result -#示例 -result = add(2, 3) -print(result) - -#定义减法运算 -def sub(a, b): - result = a - b - return result -#示例 -result =sub(2, 3) -print(result) - -#定义乘法运算 -def mul(a, b): - result = a * b - return result -#示例 -result = mul(2, 3) -print(result) - -#定义除法运算 -def div(a, b): - result = a / b - return result -#示例 -result = div(5, 3) -print(result) - -#定义整除运算 -def div_z(a, b): - result = a // b - return result -#示例 -result = div_z(5, 3) -print(result) - -#定义取余运算 -def div_y(a, b): - result = a % b - return result -#示例 -result = div_y(5, 3) -print(result) - -#定义开方运算 -def kf(a): - result = a ** (1/2) - return result -#示例 -result = kf(9) -print(result) +#定义加法运算 +def add(a, b): + result = a + b + return result +#示例 +result = add(2, 3) +print(result) + +#定义减法运算 +def sub(a, b): + result = a - b + return result +#示例 +result =sub(2, 3) +print(result) + +#定义乘法运算 +def mul(a, b): + result = a * b + return result +#示例 +result = mul(2, 3) +print(result) + +#定义除法运算 +def div(a, b): + result = a / b + return result +#示例 +result = div(5, 3) +print(result) + +#定义整除运算 +def div_z(a, b): + result = a // b + return result +#示例 +result = div_z(5, 3) +print(result) + +#定义取余运算 +def div_y(a, b): + result = a % b + return result +#示例 +result = div_y(5, 3) +print(result) + +#定义开方运算 +def kf(a): + result = a ** (1/2) + return result +#示例 +result = kf(9) +print(result) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" index 915a91e2a0551e18d0c9158a8bdff5fa8ef83dc8..2e0887ef463169511536435f6b8b1509b5fe3457 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232/main.py" @@ -1,182 +1,182 @@ -# list -# 创建,添加 -a = [] -a.append(1) -print(a) -# 结果为:[1] - -a += ["b"] -print(a) -# 结果为:[1, 'b'] - -# 按索引插入 -l = [0, 1, 2, 4] -l.insert(3, 3) -print(l) -# 结果为:[0, 1, 2, 3, 4] - -# 按索引查询 -print(a[1]) -# 结果为:b - -# 切片 -print(l[1:3]) -# 结果为:[1, 2] - -# 列表最后一个 -print(l[-1]) -# 结果为:4 - -# 切片按步长取值 -l_2 = list(range(100)) -print(l_2[0:20:2]) -# 结果为:[0, 2, 4, 6, 8, 10, 12, 14, 16, 18] - -# 检索 -new_l = list("hello, world") -print(new_l.index("r")) -# 结果为:9 - -# 索引赋值 -new_l[9] = "o" -print(new_l) -# 结果为:['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'o', 'l', 'd'] - -# 切片赋值 -new_l[0:5] = "hi" -print(new_l) -# 结果为:['h', 'i', ',', ' ', 'w', 'o', 'o', 'l', 'd'] - -# 末尾删除元素并返回元素 -print(new_l.pop()) -# 结果为:d -print(new_l) -# 结果为:['h', 'i', ',', ' ', 'w', 'o', 'o', 'l'] - -# 清除列表元素 -l.clear() -print(l) -# 结果为:[] - -# 排序 -l = [1, 5, 4, 0, 6] -l.sort() -print(l) -# 结果为:[0, 1, 4, 5, 6] - -# 倒序 -l.reverse() -print(l) -# 结果为:[6, 5, 4, 1, 0] - - - -# tuple -# 按索引查询值 -t = (2, 4, 0, 7) -print(t[3]) -# 结果为:7 - -# 按值查询索引 -print(t.index(0)) -# 结果为:2 - -# 切片 -print(t[0:2]) -# 结果为:(2, 4) - - - -# dict -# 键対值赋值 -d = {"a": 1, "b": 2, "e": 5, "c":3} -d["d"] = 4 -print(d) -# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4} - -# 合并字典 -d_2 = {"h": 8} -d.update(d_2) -print(d) -# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8} - -# 没有key则加入新元素 -d.setdefault("g", 7) -print(d) -# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} -# 有key则返回key值 -d.setdefault("a", 5) -print(d) -# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} - -# 键对值访问 -print(d["c"]) -# 结果为:3 -print(d.get("b")) -# 结果为:2 - -# 返回所有key -print(d.keys()) -# 结果为:dict_keys(['a', 'b', 'e', 'c', 'd', 'h', 'g']) - -# 返回所有value -print(d.values()) -# 结果为:dict_values([1, 2, 5, 3, 4, 8, 7]) - -# 返回所有键对值 -print(d.items()) -# 结果为:dict_items([('a', 1), ('b', 2), ('e', 5), ('c', 3), ('d', 4), ('h', 8), ('g', 7)]) - -# 键对值赋值 -d["a"] = 100 -print(d) -# 结果为:{'a': 100, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} -d.update({"b": 200, "c": 300}) -print(d) -# 结果为:{'a': 100, 'b': 200, 'e': 5, 'c': 300, 'd': 4, 'h': 8, 'g': 7} - -# 删除当前键对值 -d.pop("g") -print(d) -# 结果为:{'a': 100, 'b': 200, 'e': 5, 'c': 300, 'd': 4, 'h': 8} -# 返回一个item -print(d.popitem()) -# 结果为:('h', 8) - -# 清空字典 -d.clear() -print(d) -# 结果为:{} - - - -# set -s = set() -# 添加 -s.add("a") -print(s) -# 结果为:{'a'} - -# 判断 -print("a" in s) -# 结果为:True - -# union合并 -s_2 = {"c", "d"} -new_s = s.union(s_2) -print(new_s) -# 结果为:{'c', 'a', 'd'} - -# 移除 -new_s.remove("a") -print(new_s) -# 结果为:{'c', 'd'} -new_s.discard("f") -print(new_s) -# 结果为:{'d', 'c'} - -# 无序删除并返回 -new_s.pop() -print(new_s) -# 结果为:{'d'} - +# list +# 创建,添加 +a = [] +a.append(1) +print(a) +# 结果为:[1] + +a += ["b"] +print(a) +# 结果为:[1, 'b'] + +# 按索引插入 +l = [0, 1, 2, 4] +l.insert(3, 3) +print(l) +# 结果为:[0, 1, 2, 3, 4] + +# 按索引查询 +print(a[1]) +# 结果为:b + +# 切片 +print(l[1:3]) +# 结果为:[1, 2] + +# 列表最后一个 +print(l[-1]) +# 结果为:4 + +# 切片按步长取值 +l_2 = list(range(100)) +print(l_2[0:20:2]) +# 结果为:[0, 2, 4, 6, 8, 10, 12, 14, 16, 18] + +# 检索 +new_l = list("hello, world") +print(new_l.index("r")) +# 结果为:9 + +# 索引赋值 +new_l[9] = "o" +print(new_l) +# 结果为:['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'o', 'l', 'd'] + +# 切片赋值 +new_l[0:5] = "hi" +print(new_l) +# 结果为:['h', 'i', ',', ' ', 'w', 'o', 'o', 'l', 'd'] + +# 末尾删除元素并返回元素 +print(new_l.pop()) +# 结果为:d +print(new_l) +# 结果为:['h', 'i', ',', ' ', 'w', 'o', 'o', 'l'] + +# 清除列表元素 +l.clear() +print(l) +# 结果为:[] + +# 排序 +l = [1, 5, 4, 0, 6] +l.sort() +print(l) +# 结果为:[0, 1, 4, 5, 6] + +# 倒序 +l.reverse() +print(l) +# 结果为:[6, 5, 4, 1, 0] + + + +# tuple +# 按索引查询值 +t = (2, 4, 0, 7) +print(t[3]) +# 结果为:7 + +# 按值查询索引 +print(t.index(0)) +# 结果为:2 + +# 切片 +print(t[0:2]) +# 结果为:(2, 4) + + + +# dict +# 键対值赋值 +d = {"a": 1, "b": 2, "e": 5, "c":3} +d["d"] = 4 +print(d) +# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4} + +# 合并字典 +d_2 = {"h": 8} +d.update(d_2) +print(d) +# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8} + +# 没有key则加入新元素 +d.setdefault("g", 7) +print(d) +# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} +# 有key则返回key值 +d.setdefault("a", 5) +print(d) +# 结果为:{'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} + +# 键对值访问 +print(d["c"]) +# 结果为:3 +print(d.get("b")) +# 结果为:2 + +# 返回所有key +print(d.keys()) +# 结果为:dict_keys(['a', 'b', 'e', 'c', 'd', 'h', 'g']) + +# 返回所有value +print(d.values()) +# 结果为:dict_values([1, 2, 5, 3, 4, 8, 7]) + +# 返回所有键对值 +print(d.items()) +# 结果为:dict_items([('a', 1), ('b', 2), ('e', 5), ('c', 3), ('d', 4), ('h', 8), ('g', 7)]) + +# 键对值赋值 +d["a"] = 100 +print(d) +# 结果为:{'a': 100, 'b': 2, 'e': 5, 'c': 3, 'd': 4, 'h': 8, 'g': 7} +d.update({"b": 200, "c": 300}) +print(d) +# 结果为:{'a': 100, 'b': 200, 'e': 5, 'c': 300, 'd': 4, 'h': 8, 'g': 7} + +# 删除当前键对值 +d.pop("g") +print(d) +# 结果为:{'a': 100, 'b': 200, 'e': 5, 'c': 300, 'd': 4, 'h': 8} +# 返回一个item +print(d.popitem()) +# 结果为:('h', 8) + +# 清空字典 +d.clear() +print(d) +# 结果为:{} + + + +# set +s = set() +# 添加 +s.add("a") +print(s) +# 结果为:{'a'} + +# 判断 +print("a" in s) +# 结果为:True + +# union合并 +s_2 = {"c", "d"} +new_s = s.union(s_2) +print(new_s) +# 结果为:{'c', 'a', 'd'} + +# 移除 +new_s.remove("a") +print(new_s) +# 结果为:{'c', 'd'} +new_s.discard("f") +print(new_s) +# 结果为:{'d', 'c'} + +# 无序删除并返回 +new_s.pop() +print(new_s) +# 结果为:{'d'} + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/main.py" index 9518341f9e507d7722abc60206bd5b8150f5b570..0fe84291de6ecac9ad9b3633274c705cbbb6e00a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/main.py" @@ -1,78 +1,78 @@ -# 字符串编码 -a = '字符串编码'.encode('utf-8') -print(a) -# 打印结果为:b'\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2\xe7\xbc\x96\xe7\xa0\x81' - -# 字符串解码 -b = a.decode('utf') -print(b) -# 打印结果为:字符串编码 - - -# 字符串的crud -# Create(创建) -c = 'meng' -c += ' chu' -print(c) -# 打印结果为:meng chu - -# Retrieve(检索) -print(c[1]) -# 打印结果为:e - -print(c.find('e')) -print(c.index('e')) -# 打印结果为:1 - -date = "2020-12-26" -print(date.startswith("2020")) -print(date.endswith("26")) -# 打印结果为:True - -# Update(更新) -print(c.replace("chu", "xiang")) -# 打印结果为:meng xiang -d = c.split(",") -print(d) -# 打印结果为:['meng chu'] -print(",".join(d)) -# 打印结果为:meng chu - -# DELETE(删除) -q = " study, python " -print(q.strip()) -# 打印结果为:study, python - - - -# 将content内容保存至本地 -output = open("output.txt", "w", encoding="utf-8") -content = "hello, world" -output.write(content) -output.close() - -input = open("output.txt", "r", encoding="utf-8") -content = input.read() -print(content) - -output = open("output.txt", "a", encoding="utf-8") -content = "\nhello, python" -output.write(content) -output.close() - - -# 字符串格式化输出 -m = "ping" -n = "pong" -print("play pingpong: {}, {}".format(m, n)) -print("play pingpong: {0}, {1}, {0}, {1}".format(m, n)) -print("play pingpong: {m}, {n}, {m}, {n}".format(m = "ping", n = "pong")) -print(f"play pingpong: {m}, {n}") - -print("{:.2f}".format(3.1415926)) - -print("play pingpong: %s %s"%("ping", "pong")) - - - - +# 字符串编码 +a = '字符串编码'.encode('utf-8') +print(a) +# 打印结果为:b'\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2\xe7\xbc\x96\xe7\xa0\x81' + +# 字符串解码 +b = a.decode('utf') +print(b) +# 打印结果为:字符串编码 + + +# 字符串的crud +# Create(创建) +c = 'meng' +c += ' chu' +print(c) +# 打印结果为:meng chu + +# Retrieve(检索) +print(c[1]) +# 打印结果为:e + +print(c.find('e')) +print(c.index('e')) +# 打印结果为:1 + +date = "2020-12-26" +print(date.startswith("2020")) +print(date.endswith("26")) +# 打印结果为:True + +# Update(更新) +print(c.replace("chu", "xiang")) +# 打印结果为:meng xiang +d = c.split(",") +print(d) +# 打印结果为:['meng chu'] +print(",".join(d)) +# 打印结果为:meng chu + +# DELETE(删除) +q = " study, python " +print(q.strip()) +# 打印结果为:study, python + + + +# 将content内容保存至本地 +output = open("output.txt", "w", encoding="utf-8") +content = "hello, world" +output.write(content) +output.close() + +input = open("output.txt", "r", encoding="utf-8") +content = input.read() +print(content) + +output = open("output.txt", "a", encoding="utf-8") +content = "\nhello, python" +output.write(content) +output.close() + + +# 字符串格式化输出 +m = "ping" +n = "pong" +print("play pingpong: {}, {}".format(m, n)) +print("play pingpong: {0}, {1}, {0}, {1}".format(m, n)) +print("play pingpong: {m}, {n}, {m}, {n}".format(m = "ping", n = "pong")) +print(f"play pingpong: {m}, {n}") + +print("{:.2f}".format(3.1415926)) + +print("play pingpong: %s %s"%("ping", "pong")) + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/output.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/output.txt" index 0d42f80175c04be97aad9741bb529a07991a26ac..7762baba8051290c18aedcfbccb284078d81cfc6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/output.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232/output.txt" @@ -1,2 +1,2 @@ -hello, world +hello, world hello, python \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 348d10f4e01a83f3fdba0dae1fe865eea08f9fdc..8e682d70eb1182394ef88eedddb194a0db4fcb9e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,34 +1,34 @@ -import requests -from threading import Thread -# from multiprocessing import process - -# request请求lol官网 -def request_lol(index): - url = "https://lol.qq.com/act/a20210108lplspring/index.shtml?e_code=507042" - # body = "" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") - - -if __name__ == "__main__": -# 实现一个多线程 - thread_array = [] - for i in range(10): - t = Thread(target=request_lol, args=(i, )) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - print("done!") - -# 将多线程改为多进程 -# process_array = [] -# for i in range(10): -# p = process(target=request_lol()) -# process_array.append(p) -# p.start() -# for p in process_array: -# p.join() +import requests +from threading import Thread +# from multiprocessing import process + +# request请求lol官网 +def request_lol(index): + url = "https://lol.qq.com/act/a20210108lplspring/index.shtml?e_code=507042" + # body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") + + +if __name__ == "__main__": +# 实现一个多线程 + thread_array = [] + for i in range(10): + t = Thread(target=request_lol, args=(i, )) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print("done!") + +# 将多线程改为多进程 +# process_array = [] +# for i in range(10): +# p = process(target=request_lol()) +# process_array.append(p) +# p.start() +# for p in process_array: +# p.join() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index eb015aa16b1a64c91dc8e1c23d9c99030db262c0..f58df9ce7949da66e9b5b402bd2810d59e588eea 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,51 +1,51 @@ -import asyncio -# 1.什么是迭代器,什么是生成器,两者的区别 -# 迭代器可以用来表示一个数据流,提供了数据的惰性返回功能;生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上提供了额外的功能, 实现了程序的暂停。 -# 区别:同样提供了惰性返回的功能,迭代器侧重于提供数据的惰性返回功能,生成器侧重于指令的惰性返回功能 -# 2.协程的实现原理 -# 与生成器原理相同,但又提供了传递值的功能 -# 3.asyncio实现原理 -# 自行维护了一个事件队列,然后循环访问事件来完成异步的消息维护。 -# 4.用协程实现一个计算平均数的函数 -def coro_aver(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -my_aver = coro_aver() -print(next(my_aver)) -print(my_aver.send(2)) -print(my_aver.send(3)) -# 5.编写一个asyncio异步程序 -class Zhuangtai: - status_code = "饱了" - - -async def cat_fish(index): - print(f"小猫吃的第几条鱼: {index}") - response = Zhuangtai() - await asyncio.sleep(1) - print(f"小猫吃的第几条鱼:{index}, 吃的怎么样了:{response.status_code}") - return response.status_code - -loop = asyncio.get_event_loop() - -task_array = [] -for i in range(5): - task_array.append(cat_fish(i)) - -loop.run_until_complete(asyncio.wait(task_array)) - -loop.close() - - - - - - +import asyncio +# 1.什么是迭代器,什么是生成器,两者的区别 +# 迭代器可以用来表示一个数据流,提供了数据的惰性返回功能;生成器是一种特殊的迭代器,在迭代器惰性返回数据的基础上提供了额外的功能, 实现了程序的暂停。 +# 区别:同样提供了惰性返回的功能,迭代器侧重于提供数据的惰性返回功能,生成器侧重于指令的惰性返回功能 +# 2.协程的实现原理 +# 与生成器原理相同,但又提供了传递值的功能 +# 3.asyncio实现原理 +# 自行维护了一个事件队列,然后循环访问事件来完成异步的消息维护。 +# 4.用协程实现一个计算平均数的函数 +def coro_aver(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +my_aver = coro_aver() +print(next(my_aver)) +print(my_aver.send(2)) +print(my_aver.send(3)) +# 5.编写一个asyncio异步程序 +class Zhuangtai: + status_code = "饱了" + + +async def cat_fish(index): + print(f"小猫吃的第几条鱼: {index}") + response = Zhuangtai() + await asyncio.sleep(1) + print(f"小猫吃的第几条鱼:{index}, 吃的怎么样了:{response.status_code}") + return response.status_code + +loop = asyncio.get_event_loop() + +task_array = [] +for i in range(5): + task_array.append(cat_fish(i)) + +loop.run_until_complete(asyncio.wait(task_array)) + +loop.close() + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index b96139c49fbd63fe914f21fefd9eee94fe4ab885..95514e9272b5d9f1294e01ef374fcfbdcfc295f7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 1.11-1.17/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,56 +1,56 @@ -# 多进程锁, 多进程通过Queue来实现进程通信 -import time -from threading import Thread, Lock -from multiprocessing import Process, Lock - -def save_to_file(index, lock): - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - - -# def save_to_queue(index, my_queue): -# my_queue.put(index) - - -if __name__ == "__main__": - process_array = [] - lock = Lock() -# my_queue = Queue() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - # p = Process(target=save_to_queue, args=(i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - # print("done!") - - # while True: - # print(my_queue.get) - - - -# 多线程锁 -zero = 0 -lock = Lock() - -def foo(): - global zero - for i in range(10**6): - with lock: - zero += 1 - zero -= 1 - -if __name__ == "__main__": - process_array = [] - for i in range(2): - p = Thread(target=foo) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - print(zero) - - +# 多进程锁, 多进程通过Queue来实现进程通信 +import time +from threading import Thread, Lock +from multiprocessing import Process, Lock + +def save_to_file(index, lock): + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + + +# def save_to_queue(index, my_queue): +# my_queue.put(index) + + +if __name__ == "__main__": + process_array = [] + lock = Lock() +# my_queue = Queue() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + # p = Process(target=save_to_queue, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + # print("done!") + + # while True: + # print(my_queue.get) + + + +# 多线程锁 +zero = 0 +lock = Lock() + +def foo(): + global zero + for i in range(10**6): + with lock: + zero += 1 + zero -= 1 + +if __name__ == "__main__": + process_array = [] + for i in range(2): + p = Thread(target=foo) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + print(zero) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 91d31bd7172f990fdbce5fb16bfde70ba0869e91..5337299b09a6e251a5c82a1d1085929ae889ac75 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,34 +1,34 @@ -# 讲清楚浏览器地址栏敲下url发生了什么 -# 输入url: -# 协议://域名[:端口]/路径 -# DNS解析: -# 域名->DNS服务器->返回真实的IP地址->通过IP地址访问服务器 -# 客户端与服务器建立连接: -# 客户端和服务端要互相确认身份,建立连接通道后再发送数据 -# 客户端正式向服务端发送请求 -# 服务端处理请求并返回结果 -# 浏览器接收到响应后,做响应的渲染 - - - - -# 五层协议那五层,举例说明 -# 应用层:为进程(客户端应用)和进程(服务器应用)之间提供服务 -# HTTP/HTTPS(超文本传输协议); -# DNS(域名系统); -# FTP(文件传输协议); -# SMTP(邮箱传输协议); - -# 传输层:负责向两个主机应用进程的通信提供服务 -# TCP(传输控制协议) -# UDP(用户数据协议) - -# 网络层:决定了数据的转寄和路径选择,封装和分组运输层产生的报文段/用户数据段 -# IP协议 - -# 数据链路层:负责两台主机之间的数据传输,向网络层提供数据传输服务 -# 数据链路层的作用:比特流在传输媒介上传输肯定有误差,数据链路层的作用就是检查和纠错 - -# 物理层:物理层在局部局域网上传送数据帧,在设备节点传输比特流 -# 物理层才是真正传输数据的,数据链路层是用来检查数据完整性的. - +# 讲清楚浏览器地址栏敲下url发生了什么 +# 输入url: +# 协议://域名[:端口]/路径 +# DNS解析: +# 域名->DNS服务器->返回真实的IP地址->通过IP地址访问服务器 +# 客户端与服务器建立连接: +# 客户端和服务端要互相确认身份,建立连接通道后再发送数据 +# 客户端正式向服务端发送请求 +# 服务端处理请求并返回结果 +# 浏览器接收到响应后,做响应的渲染 + + + + +# 五层协议那五层,举例说明 +# 应用层:为进程(客户端应用)和进程(服务器应用)之间提供服务 +# HTTP/HTTPS(超文本传输协议); +# DNS(域名系统); +# FTP(文件传输协议); +# SMTP(邮箱传输协议); + +# 传输层:负责向两个主机应用进程的通信提供服务 +# TCP(传输控制协议) +# UDP(用户数据协议) + +# 网络层:决定了数据的转寄和路径选择,封装和分组运输层产生的报文段/用户数据段 +# IP协议 + +# 数据链路层:负责两台主机之间的数据传输,向网络层提供数据传输服务 +# 数据链路层的作用:比特流在传输媒介上传输肯定有误差,数据链路层的作用就是检查和纠错 + +# 物理层:物理层在局部局域网上传送数据帧,在设备节点传输比特流 +# 物理层才是真正传输数据的,数据链路层是用来检查数据完整性的. + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 3bc2fb6dfa4542cdba5e7e3f85305514589b4ddb..9fc0aa96cbfa0d63dc69990a9fd21f3889b78817 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,34 +1,34 @@ -# web端抓包 -信任证书 - Rules->Options->HTTPS - -勾选Decrypt HTTPS traffic - -右上角点击Actions - - - -# APP抓包 -一.打开远程终端连接 - Rules->Options->Connections->Allow remote computers to connnect -二.把手机/模拟器的代理指向fiddler - -wifi调出设置时长按 - -查看当前fiddler所在pc本地局域网ip - -ipconfig - -在代理项中填写ip地址和fiddler端口,默认是8888 -三.信任证书 -四.APP有一定的反爬措施,第一件事就是修改请求协议 - 双向验证 - 需要客户端也带上证书 -五.解决请求协议上的反爬措施 - 安装VirtualXposed 0.18.2 JustTrustMe - - - -# PostMan简单使用 - Get - Post - form_data - 参数表单 - x-www-form-urlencode - 如果headers中content-type为x-www-form-urlencode,那么我们需要在当前选项下填写参数 - row - 请求的真实body内容 +# web端抓包 +信任证书 + Rules->Options->HTTPS + -勾选Decrypt HTTPS traffic + -右上角点击Actions + + + +# APP抓包 +一.打开远程终端连接 + Rules->Options->Connections->Allow remote computers to connnect +二.把手机/模拟器的代理指向fiddler + -wifi调出设置时长按 + -查看当前fiddler所在pc本地局域网ip + -ipconfig + -在代理项中填写ip地址和fiddler端口,默认是8888 +三.信任证书 +四.APP有一定的反爬措施,第一件事就是修改请求协议 + 双向验证 + 需要客户端也带上证书 +五.解决请求协议上的反爬措施 + 安装VirtualXposed 0.18.2 JustTrustMe + + + +# PostMan简单使用 + Get + Post + form_data + 参数表单 + x-www-form-urlencode + 如果headers中content-type为x-www-form-urlencode,那么我们需要在当前选项下填写参数 + row + 请求的真实body内容 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 8d5fe9c7c26c8f7c830561f37b6bb9f803eecfb1..262e49b09e8d8eca46876bdbfd617e3b721ce851 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\205\255\345\221\250\344\275\234\344\270\2321.18-1.24/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,21 +1,21 @@ -# 讲述TCP/IP三次握手 -# 一.客户端向服务端发送带有SYN(同步序列编号)标识的数据包···············服务端确认了客户端的发送能力正常 -# 二.服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包·············服务端确认了自己的接收能力正常 -# 三.客户端向服务端返回带有ACK标识的数据包···························服务端确认了自己发送能力,客户端接受正常 - - -# 讲述TCP/IP四次挥手 -# 一.客户端向服务端发送了一个FIN(finish)的数据包·····················关闭客户端到服务端的连接通道 -# 二.服务端收到FIN后,返回了ACK数据包·······························服务端已经知道了客户端到服务端的连接通道已经关闭 -# 三.服务端发送FIN数据包至客户端,关闭与客户端的连接···················目的是关闭服务端到客户端的连接通道 -# 四.客户端返回ACK数据包确认·······································通知服务端客户端已经知道了服务端到客户端的连接通道已经关闭 - - -# 讲述HTTPS加密的过程 -# 客户端向服务端发送通信请求 -# 服务端返回给客户端证书和密钥 -# 客户端通过CA中心验证证书的真实性 -# 客户端完成认证后,使用公钥对发生的数据进行加密,发送给服务端 -# 服务端收到加密的请求数据后,使用私钥进行解密 -# 服务端和客户端使用对称加密进行通信 - +# 讲述TCP/IP三次握手 +# 一.客户端向服务端发送带有SYN(同步序列编号)标识的数据包···············服务端确认了客户端的发送能力正常 +# 二.服务端向客户端发送了带有SYN-ACK(确认字符)标识的数据包·············服务端确认了自己的接收能力正常 +# 三.客户端向服务端返回带有ACK标识的数据包···························服务端确认了自己发送能力,客户端接受正常 + + +# 讲述TCP/IP四次挥手 +# 一.客户端向服务端发送了一个FIN(finish)的数据包·····················关闭客户端到服务端的连接通道 +# 二.服务端收到FIN后,返回了ACK数据包·······························服务端已经知道了客户端到服务端的连接通道已经关闭 +# 三.服务端发送FIN数据包至客户端,关闭与客户端的连接···················目的是关闭服务端到客户端的连接通道 +# 四.客户端返回ACK数据包确认·······································通知服务端客户端已经知道了服务端到客户端的连接通道已经关闭 + + +# 讲述HTTPS加密的过程 +# 客户端向服务端发送通信请求 +# 服务端返回给客户端证书和密钥 +# 客户端通过CA中心验证证书的真实性 +# 客户端完成认证后,使用公钥对发生的数据进行加密,发送给服务端 +# 服务端收到加密的请求数据后,使用私钥进行解密 +# 服务端和客户端使用对称加密进行通信 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index e71d2527eb7e3eccd34c1e4b36965d9c2ed99ca7..e3d02713c53a85a73c306b078815f399d4c7583b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,30 +1,30 @@ -# 通过datetime模块完成时间戳,datetime.datetime对象,格式化字符串三者之间的转换 -import datetime -# datetime.datetime->str -now = datetime.datetime.now(tz=None) -print(now.strftime("%Y-%m-%d %H:%M:%S")) - -# str->datetime.datetime -new = "2021-01-01 22:22:22" -print(datetime.datetime.strptime(new, "%Y-%m-%d %H:%M:%S")) - -# datetime.datetime->timestamp -print(now.timestamp()) - -# timestamp->datetime.datetime -ts = now.timestamp() -print(datetime.datetime.fromtimestamp(ts, tz=None)) - - - - -# 封装一个函数get_date(day_delta),如果传入的是-1,输出就是字符串日期2020-01-02 -from datetime import datetime -from datetime import timedelta -def get_date(x): - ys = now + timedelta(days=x) - print(ys) - return ys - -get_date(-1) - +# 通过datetime模块完成时间戳,datetime.datetime对象,格式化字符串三者之间的转换 +import datetime +# datetime.datetime->str +now = datetime.datetime.now(tz=None) +print(now.strftime("%Y-%m-%d %H:%M:%S")) + +# str->datetime.datetime +new = "2021-01-01 22:22:22" +print(datetime.datetime.strptime(new, "%Y-%m-%d %H:%M:%S")) + +# datetime.datetime->timestamp +print(now.timestamp()) + +# timestamp->datetime.datetime +ts = now.timestamp() +print(datetime.datetime.fromtimestamp(ts, tz=None)) + + + + +# 封装一个函数get_date(day_delta),如果传入的是-1,输出就是字符串日期2020-01-02 +from datetime import datetime +from datetime import timedelta +def get_date(x): + ys = now + timedelta(days=x) + print(ys) + return ys + +get_date(-1) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index 63c6fe13255abc82db400422f11a138b06b47cec..7fd65337017a88906f03ca69047d829a12f3ab7e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,61 +1,61 @@ -# 将之前封装的MyMath类中的实例方法改为静态方法 -class MyMath: - - @staticmethod - def add(a, b): - return a + b - - @staticmethod - def sub(a, b): - return a - b - - @staticmethod - def mul(a, b): - return a * b - - @staticmethod - def div(a, b): - return a / b - - @staticmethod - def pow(a, b): - return a ** b - - @staticmethod - def squ(a): - return a ** 0.5 - - -# 为上节课自定义类添加以下功能: -# 添加类属性 -# 添加类私有属性 -# 添加类方法或者类的私有属性 -# 在__init__方法中初始化私有属性 -# 在__init__方法中绑定私有实例属性 -# 在自定义类中实现__str__自定义输出格式 -class Ball: - circular = True - __status = "2" - def __init__(self, sort, year): - self.sort = sort - self.year = year - - - @classmethod - def __new__(cls, *args, **kwargs): - print("The Ball is so new.") - return super().__new__(cls) - - @classmethod - def get_status(cls): - return cls.__status - - def __str__(self): - return print(f"The Ball is {self.sort}, buy for {self.year} years.") - - -my_ball = Ball('football', 0.5) -print(f"我买了一个{my_ball.sort}.") -print(f"这个足球买了{my_ball.year}年了.") -print(my_ball.get_status()) - +# 将之前封装的MyMath类中的实例方法改为静态方法 +class MyMath: + + @staticmethod + def add(a, b): + return a + b + + @staticmethod + def sub(a, b): + return a - b + + @staticmethod + def mul(a, b): + return a * b + + @staticmethod + def div(a, b): + return a / b + + @staticmethod + def pow(a, b): + return a ** b + + @staticmethod + def squ(a): + return a ** 0.5 + + +# 为上节课自定义类添加以下功能: +# 添加类属性 +# 添加类私有属性 +# 添加类方法或者类的私有属性 +# 在__init__方法中初始化私有属性 +# 在__init__方法中绑定私有实例属性 +# 在自定义类中实现__str__自定义输出格式 +class Ball: + circular = True + __status = "2" + def __init__(self, sort, year): + self.sort = sort + self.year = year + + + @classmethod + def __new__(cls, *args, **kwargs): + print("The Ball is so new.") + return super().__new__(cls) + + @classmethod + def get_status(cls): + return cls.__status + + def __str__(self): + return print(f"The Ball is {self.sort}, buy for {self.year} years.") + + +my_ball = Ball('football', 0.5) +print(f"我买了一个{my_ball.sort}.") +print(f"这个足球买了{my_ball.year}年了.") +print(my_ball.get_status()) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" index c21c656fd50010145d6d9f17f91e82f8aabe682f..df0b1905e3e290df725ecd334259ba3c1237d727 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_A-\346\242\246\345\210\235/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\2321.4-1.10/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/main.py" @@ -1,61 +1,61 @@ -# 用类封装一个mymath类,实现加减乘除幂开方 -class MyMath: - def add(self, a, b): - return a + b - - def sub(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - return a / b - - def pow(self, a, b): - return a ** b - - def squ(self, a): - return a ** 0.5 -a = MyMath() -a.add(2, 3) -print(a) - - -# 创建一个类,创建多个实例 -class Ball: - def __init__(self, sort, year): - self.sort = sort - self.year = year - - def bounce(self): - print(f"{self.sort} is bouncing.") - - def roll(self): - print(f"{self.sort} rolled.") -# 实例 -my_ball = Ball('football', 0.5) -print(f"我买了一个{my_ball.sort}.") -print(f"这个足球买了{my_ball.year}年了.") - -my_ball.bounce() -my_ball.roll() - - -your_ball = Ball('basketball', 1) -print(f'你的{your_ball.sort}质量真好.') -print(f'都买了{your_ball.year}年了,还这么新.') - - - -# 创建子类 -class FootBall(Ball): - def __init__(self, sort, year): - super(FootBall, self).__init__(sort, year) - self.size = 20 - - def chicun(self): - print(f'我新买的球的尺寸是{self.size}。') - -my_newball = FootBall('football', 0) +# 用类封装一个mymath类,实现加减乘除幂开方 +class MyMath: + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + return a / b + + def pow(self, a, b): + return a ** b + + def squ(self, a): + return a ** 0.5 +a = MyMath() +a.add(2, 3) +print(a) + + +# 创建一个类,创建多个实例 +class Ball: + def __init__(self, sort, year): + self.sort = sort + self.year = year + + def bounce(self): + print(f"{self.sort} is bouncing.") + + def roll(self): + print(f"{self.sort} rolled.") +# 实例 +my_ball = Ball('football', 0.5) +print(f"我买了一个{my_ball.sort}.") +print(f"这个足球买了{my_ball.year}年了.") + +my_ball.bounce() +my_ball.roll() + + +your_ball = Ball('basketball', 1) +print(f'你的{your_ball.sort}质量真好.') +print(f'都买了{your_ball.year}年了,还这么新.') + + + +# 创建子类 +class FootBall(Ball): + def __init__(self, sort, year): + super(FootBall, self).__init__(sort, year) + self.size = 20 + + def chicun(self): + print(f'我新买的球的尺寸是{self.size}。') + +my_newball = FootBall('football', 0) my_newball.chicun() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\350\257\276\347\254\224\350\256\260-Carmen.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\350\257\276\347\254\224\350\256\260-Carmen.md" index 4ee11c9aae026438de322aadb52b75bc2044b33d..40fec7a799db62bc734b47fd5a00ec4419536096 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\350\257\276\347\254\224\350\256\260-Carmen.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\212\202\350\257\276\347\254\224\350\256\260-Carmen.md" @@ -1,41 +1,41 @@ -# 第一节课笔记-Carmen - -- ## 学习习惯 - -- ### typora:md文档编辑器 - -- - 创建标题 (Ctrl + 数字) - -- - 创建目录列表结构 (减号 + 空格) - -- - 创建代码块 (Ctrl+shift+k) - -- ### 科学搜索习惯 - -- - 官方文档或GitHub库 - -- - Stackoverflow (error描述,排错;https://stackoverflow.com/) - -- - 知乎 简书 - -- ## 编程语言的基本概述 -- ### 编程语言的基本概述 - -- - 把代码翻译为机器码的翻译就是编译器,在python中也可以叫python解释器 - -- - 编程语言python是我们与解释器之间的翻译 - -- - 解释器是python与计算机之间的翻译 -- ### 编程语言分类 - - C - - C ++ - - Java - - Python - - JavaScript - 编译型语言 解释性语言 和混合型语言 - 动态语言和静态语言 - 强类型语言和弱类型语言 -- ## Python环境搭建 -安装时牢记目录 -IDE 安装(pycharm) - +# 第一节课笔记-Carmen + +- ## 学习习惯 + +- ### typora:md文档编辑器 + +- - 创建标题 (Ctrl + 数字) + +- - 创建目录列表结构 (减号 + 空格) + +- - 创建代码块 (Ctrl+shift+k) + +- ### 科学搜索习惯 + +- - 官方文档或GitHub库 + +- - Stackoverflow (error描述,排错;https://stackoverflow.com/) + +- - 知乎 简书 + +- ## 编程语言的基本概述 +- ### 编程语言的基本概述 + +- - 把代码翻译为机器码的翻译就是编译器,在python中也可以叫python解释器 + +- - 编程语言python是我们与解释器之间的翻译 + +- - 解释器是python与计算机之间的翻译 +- ### 编程语言分类 + - C + - C ++ + - Java + - Python + - JavaScript + 编译型语言 解释性语言 和混合型语言 + 动态语言和静态语言 + 强类型语言和弱类型语言 +- ## Python环境搭建 +安装时牢记目录 +IDE 安装(pycharm) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\257\276\345\220\216\344\275\234\344\270\2323.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\257\276\345\220\216\344\275\234\344\270\2323.py" index 2c64dcafb332c8de675d2ab561b8f03835eeffbe..63ecf3b36d755d8e43dd8fbbc70295f3a44353d6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\257\276\345\220\216\344\275\234\344\270\2323.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\257\276\345\220\216\344\275\234\344\270\2323.py" @@ -1,39 +1,39 @@ - -#整数 -print(type(1)) -#浮点数 -print(type(1.5)) -#字符串 -print(type('hello')) -#布尔值 -print(type(True)) -#二进制 -print(type(b'apple')) -# None -print(type(None)) - -#列表 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none -a=[1,1.5,'hello',True,b'apple',None] -print(a) -print(type(a)) -print(len(a)) - -#元组 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none -b=(1,1.5,'hello',True,b'apple',None) -print(b) -print(type(b)) -print(len(b)) - -#集合 包含5大数据类型 整数、浮点数、字符串、布尔值、二进制 不包含None -c={1,1.5,'hello',True,b'apple',None} -print(c) -print(type(c)) -print(len(c)) - -#字典 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none -c={"A":1,"B":1.5,"C":'hello',"D":True,"E":b'apple',"F":None} -print(c) -print(type(c)) -print(len(c)) - + +#整数 +print(type(1)) +#浮点数 +print(type(1.5)) +#字符串 +print(type('hello')) +#布尔值 +print(type(True)) +#二进制 +print(type(b'apple')) +# None +print(type(None)) + +#列表 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none +a=[1,1.5,'hello',True,b'apple',None] +print(a) +print(type(a)) +print(len(a)) + +#元组 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none +b=(1,1.5,'hello',True,b'apple',None) +print(b) +print(type(b)) +print(len(b)) + +#集合 包含5大数据类型 整数、浮点数、字符串、布尔值、二进制 不包含None +c={1,1.5,'hello',True,b'apple',None} +print(c) +print(type(c)) +print(len(c)) + +#字典 包含6大数据类型 整数、浮点数、字符串、布尔值、二进制、none +c={"A":1,"B":1.5,"C":'hello',"D":True,"E":b'apple',"F":None} +print(c) +print(type(c)) +print(len(c)) + # 因此集合不能包含None \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/for\345\222\214while\345\276\252\347\216\257.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/for\345\222\214while\345\276\252\347\216\257.py" index 103cdaa3777b12acee3bc1ee03a7ef4b637aacb9..ef6ba71cf370924ce240c488ae8bd01638504020 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/for\345\222\214while\345\276\252\347\216\257.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/for\345\222\214while\345\276\252\347\216\257.py" @@ -1,22 +1,22 @@ -# 1.用while循环计算1-100的累计和 -count=0 -result=0 -while count<101: - result=result+count - count+=1 -print(result) - -# 2.用while方法依次打印1-100 -i=0 -while i<100: - i+=1 - print(i) -# 3.用for循环计算1-100的累计和 -result=0 -for i in range(1,101): - result+=i -print(result) - -# 4.用for循环依次打印1-100 -for i in range(1,101): +# 1.用while循环计算1-100的累计和 +count=0 +result=0 +while count<101: + result=result+count + count+=1 +print(result) + +# 2.用while方法依次打印1-100 +i=0 +while i<100: + i+=1 + print(i) +# 3.用for循环计算1-100的累计和 +result=0 +for i in range(1,101): + result+=i +print(result) + +# 4.用for循环依次打印1-100 +for i in range(1,101): print(i) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\274\202\345\270\270\347\261\273\345\236\213\347\232\204\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\274\202\345\270\270\347\261\273\345\236\213\347\232\204\347\273\203\344\271\240.py" index 8d8ba18cb6b08d77f0a4a90de517ade109d6346f..dd78cb0bd99615fa1de99e2faf2cd09e1906def3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\274\202\345\270\270\347\261\273\345\236\213\347\232\204\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\274\202\345\270\270\347\261\273\345\236\213\347\232\204\347\273\203\344\271\240.py" @@ -1,23 +1,23 @@ -# 1.try expect简单写法 -try: - print(2/0) -except: - print('有错误') -# 2.有异常类型的try写法 -try: - print(2/0) -except(ZeroDivisionError) as result: - print('错误提示:分母不能为0') - print(result) #可以输输出具体错误的描述 division by zero - - -# 3.没有异常时执行 -try: - print(0/2) -except(ZeroDivisionError) as result: - print('错误提示:分母不能为0') - print(result) #可以输输出具体错误的描述 division by zero -else: - print('没有错误哦') - +# 1.try expect简单写法 +try: + print(2/0) +except: + print('有错误') +# 2.有异常类型的try写法 +try: + print(2/0) +except(ZeroDivisionError) as result: + print('错误提示:分母不能为0') + print(result) #可以输输出具体错误的描述 division by zero + + +# 3.没有异常时执行 +try: + print(0/2) +except(ZeroDivisionError) as result: + print('错误提示:分母不能为0') + print(result) #可以输输出具体错误的描述 division by zero +else: + print('没有错误哦') + # 4.异常的finally \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227-\345\276\252\347\216\257\346\263\225.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227-\345\276\252\347\216\257\346\263\225.py" index 1506cf654323f8fab7ece291acff624306e3310b..378030ab591bfa8170d4c93b395f7d0bc1f9694f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227-\345\276\252\347\216\257\346\263\225.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227-\345\276\252\347\216\257\346\263\225.py" @@ -1,20 +1,20 @@ -# while 循环 -# 三个变量 a b c,c=a+b -a=1 -b=1 -c=0 -i=0 -print(a,end=" ") -print(b,end=" ") -# while i<10: #假设循环10次这个过程 -# c = a + b -# a=b -# b=c -# i+=1 -# print(c,end=" ") - -# for 循环 -for i in range(10): - a,b=a+b,a - print(a,end=" ") - +# while 循环 +# 三个变量 a b c,c=a+b +a=1 +b=1 +c=0 +i=0 +print(a,end=" ") +print(b,end=" ") +# while i<10: #假设循环10次这个过程 +# c = a + b +# a=b +# b=c +# i+=1 +# print(c,end=" ") + +# for 循环 +for i in range(10): + a,b=a+b,a + print(a,end=" ") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\275\234\347\224\250\345\237\237\347\273\203\344\271\240.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\275\234\347\224\250\345\237\237\347\273\203\344\271\240.py" index 3ee36386af354020315f00338b62f78f95a02444..bc5c6bbb2bfbabfcdffbf6794ebfe34fbec9e56c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\275\234\347\224\250\345\237\237\347\273\203\344\271\240.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\275\234\347\224\250\345\237\237\347\273\203\344\271\240.py" @@ -1,18 +1,18 @@ -def testA(): - a = 100 # a是一个局部变量 - - print(a) - - -testA() # 100 -# print(a) 如果运行次句会出错,因为a是 testA函数内的局部变量 -# -------------------------------------------------------------------------------------------------------- -b=100 -def testB(): - global b - b = 200 # b是一个局部变量 - print(b) # 200 - - -testB() #200 +def testA(): + a = 100 # a是一个局部变量 + + print(a) + + +testA() # 100 +# print(a) 如果运行次句会出错,因为a是 testA函数内的局部变量 +# -------------------------------------------------------------------------------------------------------- +b=100 +def testB(): + global b + b = 200 # b是一个局部变量 + print(b) # 200 + + +testB() #200 print(b) #因为函数内的b变量被global后,变成全局变量,值为200, \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\243\205\351\245\260\345\231\250\350\256\241\347\256\227\346\237\220\344\270\252\345\207\275\346\225\260\346\211\247\350\241\214\347\232\204\346\227\266\351\227\264.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\243\205\351\245\260\345\231\250\350\256\241\347\256\227\346\237\220\344\270\252\345\207\275\346\225\260\346\211\247\350\241\214\347\232\204\346\227\266\351\227\264.py" index 67fb403652c3770627c42bb4f9ae84f019c317f2..3c72dbb665368b7b73cc0b1560cb2a5fcf28f924 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\243\205\351\245\260\345\231\250\350\256\241\347\256\227\346\237\220\344\270\252\345\207\275\346\225\260\346\211\247\350\241\214\347\232\204\346\227\266\351\227\264.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\350\243\205\351\245\260\345\231\250\350\256\241\347\256\227\346\237\220\344\270\252\345\207\275\346\225\260\346\211\247\350\241\214\347\232\204\346\227\266\351\227\264.py" @@ -1,19 +1,19 @@ -import time -def clock_deco(func): - def wrap(*args): - start_time = time.time() - result = func(*args) - end_time = time.time() - print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") - return result - return wrap - -@clock_deco -def foo(a, b): - num = 0 - while True: - if num >= a ** b: - break - num += 1 - +import time +def clock_deco(func): + def wrap(*args): + start_time = time.time() + result = func(*args) + end_time = time.time() + print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") + return result + return wrap + +@clock_deco +def foo(a, b): + num = 0 + while True: + if num >= a ** b: + break + num += 1 + foo(4,12) # foo 执行时长为:11.53s \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227--\351\200\222\345\275\222\346\263\225.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227--\351\200\222\345\275\222\346\263\225.py" index fd1b90686640569cb38e8fda2d654dbba5cf2f68..1255f5fb31da084c3e27f3bad8b9b530b1532022 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227--\351\200\222\345\275\222\346\263\225.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227--\351\200\222\345\275\222\346\263\225.py" @@ -1,11 +1,11 @@ -def fei(n): - if (n < 2): - return 1 - else: - return fei(n - 1) + fei(n - 2) - - -for i in range(10): - print(fei(i)) - - +def fei(n): + if (n < 2): + return 1 + else: + return fei(n - 1) + fei(n - 2) + + +for i in range(10): + print(fei(i)) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\255\233\351\200\211gradeA\346\225\260\346\215\256\345\217\212age\345\212\2401.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\255\233\351\200\211gradeA\346\225\260\346\215\256\345\217\212age\345\212\2401.py" index 45b849e1e3de2c4ed6ee70db000c6a83c3979f12..b8a8c4d866af7f5c2a6e45c1c75276db672e87ae 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\255\233\351\200\211gradeA\346\225\260\346\215\256\345\217\212age\345\212\2401.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\270\211\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\255\233\351\200\211gradeA\346\225\260\346\215\256\345\217\212age\345\212\2401.py" @@ -1,22 +1,22 @@ -# 筛选出成绩为A的同学 -classes=[ - {"name":"qaz","age":15,"grade":"A"}, - {"name":"wsx","age":16,"grade":"B"}, - {"name":"edc","age":17,"grade":"A"}, - {"name":"rfv","age":18,"grade":"C"}, - {"name":"tgb","age":19,"grade":"D"}, - {"name":"yhn","age":20,"grade":"B"}, - {"name":"ujm","age":21,"grade":"A"}, -] - -F=filter(lambda X:True if X['grade']=="A" else False,classes) -grade_A=list(F) -print(grade_A) -# 使用map函数使得 grade_A中每个人的age加1 -def func(x): - x["age"]+=1 - return x - -result = map(func, grade_A) -print(list(result)) - +# 筛选出成绩为A的同学 +classes=[ + {"name":"qaz","age":15,"grade":"A"}, + {"name":"wsx","age":16,"grade":"B"}, + {"name":"edc","age":17,"grade":"A"}, + {"name":"rfv","age":18,"grade":"C"}, + {"name":"tgb","age":19,"grade":"D"}, + {"name":"yhn","age":20,"grade":"B"}, + {"name":"ujm","age":21,"grade":"A"}, +] + +F=filter(lambda X:True if X['grade']=="A" else False,classes) +grade_A=list(F) +print(grade_A) +# 使用map函数使得 grade_A中每个人的age加1 +def func(x): + x["age"]+=1 + return x + +result = map(func, grade_A) +print(list(result)) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\345\233\233\350\212\202\350\257\276\350\277\220\347\256\227\347\254\246.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\345\233\233\350\212\202\350\257\276\350\277\220\347\256\227\347\254\246.py" index 89fb27834b3514b54b2551959292f937cadae077..0ee72b0e40a9b941fcaa4e2e486a0b43c313e66b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\345\233\233\350\212\202\350\257\276\350\277\220\347\256\227\347\254\246.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\345\233\233\350\212\202\350\257\276\350\277\220\347\256\227\347\254\246.py" @@ -1,62 +1,62 @@ -# 加法 -def add(a, b): - return a + b - - -print(add(3, 4)) - - -# 减法 -def minus(a, b): - return a - b - - -print(minus(9, 4)) - - -# 乘法 -def product(c, d): - return c * d - - -print(product(9, 4)) - - -# 除法 -def division(a, b): - return a / b - - -print(division(12, 4)) - - -# 整除 -def zhengchu(a, b): - return a // b - - -print(zhengchu(12, 5)) - - -# 取余 -def mod(a, b): - return a % b - - -print(zhengchu(15, 4)) - - -# 指数 -def index(a, b): - return a ** b - - -print(index(2, 4)) - - -# 开方跟 -def sqrt(a, b): - return a ** (1 / b) - - -print(sqrt(16, 2)) +# 加法 +def add(a, b): + return a + b + + +print(add(3, 4)) + + +# 减法 +def minus(a, b): + return a - b + + +print(minus(9, 4)) + + +# 乘法 +def product(c, d): + return c * d + + +print(product(9, 4)) + + +# 除法 +def division(a, b): + return a / b + + +print(division(12, 4)) + + +# 整除 +def zhengchu(a, b): + return a // b + + +print(zhengchu(12, 5)) + + +# 取余 +def mod(a, b): + return a % b + + +print(zhengchu(15, 4)) + + +# 指数 +def index(a, b): + return a ** b + + +print(index(2, 4)) + + +# 开方跟 +def sqrt(a, b): + return a ** (1 / b) + + +print(sqrt(16, 2)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\205\203\347\273\204\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\205\203\347\273\204\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" index 955d8357d8ed7c301b90e2d806b7bb933f46804c..bcfaa432cb3096993ba86c540b6e86b3fa13c5c0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\205\203\347\273\204\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\205\203\347\273\204\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" @@ -1,15 +1,15 @@ -# 元组数据不支持修改,只支持查找 -# 查找之下标 -tuple1 = ('aa', 'bb', 'cc', 'bb') -print(tuple1[1]) - -# 查找之index -print(tuple1.index('bb')) - -# len() 统计元组的长度 -print(len(tuple1)) - -# count 计算某个元素在元组中出现的次数 -tuple1 = ('aa', 'bb', 'cc', 'bb','cc') -print(tuple1.count('cc')) - +# 元组数据不支持修改,只支持查找 +# 查找之下标 +tuple1 = ('aa', 'bb', 'cc', 'bb') +print(tuple1[1]) + +# 查找之index +print(tuple1.index('bb')) + +# len() 统计元组的长度 +print(len(tuple1)) + +# count 计算某个元素在元组中出现的次数 +tuple1 = ('aa', 'bb', 'cc', 'bb','cc') +print(tuple1.count('cc')) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\227\350\241\250\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\227\350\241\250\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" index 1688a8ea7a0f4eeb0f477f5cadaad383ee5f417c..3588c744c4588cc966b6c31dbe2bab975f38633e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\227\350\241\250\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\227\350\241\250\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" @@ -1,82 +1,82 @@ -# 查找之下标 -l1=['xiaozhang', 'xiaoxiao', 'xiaoming', 'xiaolv', 'xiaohei'] -print(l1[0]) -print(l1[1]) - -# 查找之index -l2=['xiaozhang', 'xiaoxiao', 'xiaoming', 'xiaolv', 'xiaohei'] -print(l2.index('xiaoxiao')) - -# 增加 -# append -list1=[] -list1.append('a') -print(list1) -list1.append(['b','c','d']) -print(list1) #如果追加的是一个序列,会追加整个序列到列表 - -#extend -list2=['aa','bb','cc'] -list2.extend(['dd','ee']) #如果追加的是一个序列,则将该序列的每一个元素单独加进列表中 -print(list2) -list2.extend('xiaoming') -print(list2) - -# insert 指定位置新增数据 -list3=['xiaoming','xiaohong','xiaolv'] -list3.insert(list3.index('xiaohong')+1,'xiaozhang') -print(list3) - -# 删除 -# del/claer 删除/清除 del是直接删除整个列表,del后再运行会报错, clear是清除列表的内容,返回清除内容后的列表 -list4=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv'] -# del list4 -del list4[3] -print(list4) -list4.clear() -print(list4) - -# remove -list5=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] -list5.remove('xiaohei') -print(list5) - -# pop 删除指定下标的数据(默认为最后一个),并返回该数据 -list6=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] -delname=list6.pop(2) -print(delname) -print(list6) - -# 修改/更改 -# 修改列表的某个值 -list7=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] -list7[1]='xiaoxiao' -print(list7) - -list8=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] ##这里还点懵 明天记得查资料!! -list8[0:2]='aaaaa' -print(list8) - -list8[0:2]='bbb' -print(list8) - -#reverse -list9=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] -list9.reverse() -print(list9) - -# sort -list10=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] -list10.sort(key=None, reverse=True) #reverse = True为降序,reverse = False是升序 -print(list10) - -# 计数/长度/复制 -# count -ll=['a', 'a', 'a', 'a', 'a', 'xiaozhang', 'xiaolv', 'xiaohei'] -print(ll.count('a')) -# len -print(len(ll)) -# copy 复制的是一个新的列表.内存地址不一致 -print(ll.copy()) -print(id(ll)) -print(id(ll.copy)) +# 查找之下标 +l1=['xiaozhang', 'xiaoxiao', 'xiaoming', 'xiaolv', 'xiaohei'] +print(l1[0]) +print(l1[1]) + +# 查找之index +l2=['xiaozhang', 'xiaoxiao', 'xiaoming', 'xiaolv', 'xiaohei'] +print(l2.index('xiaoxiao')) + +# 增加 +# append +list1=[] +list1.append('a') +print(list1) +list1.append(['b','c','d']) +print(list1) #如果追加的是一个序列,会追加整个序列到列表 + +#extend +list2=['aa','bb','cc'] +list2.extend(['dd','ee']) #如果追加的是一个序列,则将该序列的每一个元素单独加进列表中 +print(list2) +list2.extend('xiaoming') +print(list2) + +# insert 指定位置新增数据 +list3=['xiaoming','xiaohong','xiaolv'] +list3.insert(list3.index('xiaohong')+1,'xiaozhang') +print(list3) + +# 删除 +# del/claer 删除/清除 del是直接删除整个列表,del后再运行会报错, clear是清除列表的内容,返回清除内容后的列表 +list4=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv'] +# del list4 +del list4[3] +print(list4) +list4.clear() +print(list4) + +# remove +list5=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] +list5.remove('xiaohei') +print(list5) + +# pop 删除指定下标的数据(默认为最后一个),并返回该数据 +list6=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] +delname=list6.pop(2) +print(delname) +print(list6) + +# 修改/更改 +# 修改列表的某个值 +list7=['xiaoming', 'xiaohong', 'xiaozhang', 'xiaolv','xiaohei'] +list7[1]='xiaoxiao' +print(list7) + +list8=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] ##这里还点懵 明天记得查资料!! +list8[0:2]='aaaaa' +print(list8) + +list8[0:2]='bbb' +print(list8) + +#reverse +list9=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] +list9.reverse() +print(list9) + +# sort +list10=['xiaoming', 'xiaoxiao', 'xiaozhang', 'xiaolv', 'xiaohei'] +list10.sort(key=None, reverse=True) #reverse = True为降序,reverse = False是升序 +print(list10) + +# 计数/长度/复制 +# count +ll=['a', 'a', 'a', 'a', 'a', 'xiaozhang', 'xiaolv', 'xiaohei'] +print(ll.count('a')) +# len +print(len(ll)) +# copy 复制的是一个新的列表.内存地址不一致 +print(ll.copy()) +print(id(ll)) +print(id(ll.copy)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\345\205\270\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\345\205\270\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" index 81ba36476d0c23f0738f20f210e3ceb895cea634..c0e8c3bde31e88edc61e8c5351bed790a92421ac 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\345\205\270\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\345\205\270\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" @@ -1,40 +1,40 @@ -# 新建和新增 -# 字典的新增 键值对方式:字典序列[key] = 值; 如无key则新增,如有则修改value -d1={} -d1['name']='xiaochen' -d1['age']=20 -d1['gender']='男' -print(d1) - -# update 使用一个字典所包含的键值对来更新一个现有的字典 -newdict={'name': 'xiaoming', 'age': 25, 'gender': '男','id':'001'} -d1.update(newdict) -print(d1) - -# 删除方法 -#1.删除元素 del -del d1['gender'] -print(d1) - -# 2.清空字典 clear -d1.clear() -print(d1) -#pop 删除某个键值对 ,并返回值 -d2={'name': 'xiaochen', 'age': 20, 'gender': '男'} -delkey=d2.pop('age') -print(delkey) -print(d2) - -# 字典的查找方法 -# 1.key值查找 -d3={'name': 'xiaoming', 'age': 25, 'gender': '男', 'id': '001'} -print(d3['name']) -# 2.get 查找 -print(d3.get('name')) -print(d3.get('weigh','无此key')) # get方法的第二参数:如果查找的key不存在,则返回第二参数,如不填写第二参数,返回none -# 3.key -print(d3.keys()) -# 4.value -print(d3.values()) -# 5.items +# 新建和新增 +# 字典的新增 键值对方式:字典序列[key] = 值; 如无key则新增,如有则修改value +d1={} +d1['name']='xiaochen' +d1['age']=20 +d1['gender']='男' +print(d1) + +# update 使用一个字典所包含的键值对来更新一个现有的字典 +newdict={'name': 'xiaoming', 'age': 25, 'gender': '男','id':'001'} +d1.update(newdict) +print(d1) + +# 删除方法 +#1.删除元素 del +del d1['gender'] +print(d1) + +# 2.清空字典 clear +d1.clear() +print(d1) +#pop 删除某个键值对 ,并返回值 +d2={'name': 'xiaochen', 'age': 20, 'gender': '男'} +delkey=d2.pop('age') +print(delkey) +print(d2) + +# 字典的查找方法 +# 1.key值查找 +d3={'name': 'xiaoming', 'age': 25, 'gender': '男', 'id': '001'} +print(d3['name']) +# 2.get 查找 +print(d3.get('name')) +print(d3.get('weigh','无此key')) # get方法的第二参数:如果查找的key不存在,则返回第二参数,如不填写第二参数,返回none +# 3.key +print(d3.keys()) +# 4.value +print(d3.values()) +# 5.items print(d3.items()) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\351\233\206\345\220\210\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\351\233\206\345\220\210\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" index 3c102913fb3f81494236372ae67c8a94e1c8c9b0..5aa3f7225b72252f1802576c82e9a167cff5bf80 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\351\233\206\345\220\210\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\351\233\206\345\220\210\347\232\204\345\242\236\345\210\240\346\237\245\346\224\271.py" @@ -1,35 +1,35 @@ -# 集合的创建和新增 -# 创建 -s1={'a','b','c','d','b'} -print(s1)# 集合有去重功能 -print(len(s1)) #只有4个元素 - -#通过 set()方法创建 -str1='ABCD' -print(set(str1)) - -# 新增 add,update -# add方法 -s1.add('f') -print(s1) -# update方法 update方法追加的必须是序列 -s1.update('EFGH') -s1.update({100}) -s1.update([1,2,3,4]) -print(s1) - -# 删除方法 remove,discard,pop -# remove 删除集合中的指定数据,如果数据不存在则报错 -s2={'B', 'A', 'C', 'D'} -# s2.remove('F') -# discard方法 删除集合中的指定数据,如果数据不存在也不会报错 -s2.discard('F') - -# pop方法:随机删除一个数据,并返回该数据 是随机哦!!! -s2={'B', 'A', 'C', 'D'} -print(s2.pop()) - -# 查找数据 集合无序,不支持下标查找。只能用in判断某个元素是否存在 -s2={'B', 'A', 'C', 'D'} -print( 'B' in s2) -print('H'not in s2) +# 集合的创建和新增 +# 创建 +s1={'a','b','c','d','b'} +print(s1)# 集合有去重功能 +print(len(s1)) #只有4个元素 + +#通过 set()方法创建 +str1='ABCD' +print(set(str1)) + +# 新增 add,update +# add方法 +s1.add('f') +print(s1) +# update方法 update方法追加的必须是序列 +s1.update('EFGH') +s1.update({100}) +s1.update([1,2,3,4]) +print(s1) + +# 删除方法 remove,discard,pop +# remove 删除集合中的指定数据,如果数据不存在则报错 +s2={'B', 'A', 'C', 'D'} +# s2.remove('F') +# discard方法 删除集合中的指定数据,如果数据不存在也不会报错 +s2.discard('F') + +# pop方法:随机删除一个数据,并返回该数据 是随机哦!!! +s2={'B', 'A', 'C', 'D'} +print(s2.pop()) + +# 查找数据 集合无序,不支持下标查找。只能用in判断某个元素是否存在 +s2={'B', 'A', 'C', 'D'} +print( 'B' in s2) +print('H'not in s2) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/doc20201225.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/doc20201225.txt" index 6e9f961912ba6e7d2512956dbfe5a585d61929ca..f9f231433e43f31411778395375aa05f88b49ccb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/doc20201225.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/doc20201225.txt" @@ -1,14 +1,14 @@ -# 方法1: -hello='hello' -name='apple' -age=18 -weigh=52.5 -print(f'{hello},{name},welcome!') - -# 方法2: -print('%s,%s,welcome!'%(hello,name)) -print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) - -#方法3 -f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) +# 方法1: +hello='hello' +name='apple' +age=18 +weigh=52.5 +print(f'{hello},{name},welcome!') + +# 方法2: +print('%s,%s,welcome!'%(hello,name)) +print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) + +#方法3 +f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) print(f) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204CURD\346\223\215\344\275\234.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204CURD\346\223\215\344\275\234.py" index f78cfc35f60bd6c88b07e66b528b9d5853720c20..a8333e3716dec14a60588acb5580ab45bc8911dc 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204CURD\346\223\215\344\275\234.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204CURD\346\223\215\344\275\234.py" @@ -1,72 +1,72 @@ -# 字符串常用操作:创建/查找/修改/判断 -# 一.创建 -# 1.单引号/双引号 -a = 'hello python' -b = "hello world" - -# 2.三引号 支持换行输入 -c = """hello - python""" -print(a) -print(b) -print(c) - -# 3.通过str()转换创建 -d = str(2) -print(type(d)) - -# 二.查找 -# 1.find方法 -a = 'hello python and learn python and have fun' -print(a.find('and')) -print(a.find('and',15,42))# 可以放查找的起始位置和结束位置,如不放则默认在全部范围内查找 -print(a.find('ands')) # find找不到会返回-1 - -# 2.index方法 -print(a.index('and')) -print(a.index('and',15,42))# 可以放查找的起始位置和结束位置,如不放则默认在全部范围内查找 -#print(a.index('ands'))#!!index 如果找不到会报错 - -# 3.rfind/rindex方法 :与find/index 方法一样,方向改成从右查找 -print(a.rindex('fun')) -print(a.rfind('fun')) - -# 4.count方法: 字符串序列.count(子串, 开始位置下标, 结束位置下标) -print(a.count('python')) - -# 三.修改 -# 1.replace方法 :字符串序列.replace(旧子串, 新子串, 替换次数) -a = 'hello python and learn python and have fun and practice' -print(a.replace('python','python2')) # 不加替换次数则替换全部 -print(a.replace('python','python2',1))# 可以配合count使用 -# 2.分割 split方法: 字符串序列.split(分割字符, num)-返回列表 -print(a.split('and')) -print(a.split('and',1)) # 最后一个参数代表分割次数 -# 3.join方法 字符或子串.join(多字符串组成的序列) -list1=['a','b','c','d'] -t1=('aa','bb','cc') -print('-'.join(list1)) -print('--'.join(t1)) -# 4.strip方法 -a = ' hello python and learn python and have fun and practice ' -print(a.lstrip())#清除左边的空格 -print(a.rstrip())#清除右边的空格 -print(a.strip())#清除两边的空格 -# 5.字符串对齐、居中 函数:ljust/rjust/center -a='hello' -print(a.ljust(10,'.')) -print(a.rjust(10,'.')) -print(a.center(10,'.')) - -# 四.判断 -# 1.starswith 字符串序列.startswith(子串, 开始位置下标, 结束位置下标) -a = 'hello python and learn python and have fun and practice' -print(a.startswith('hello')) #返回true -print(a.startswith('hello',10,40)) #返回false -print(a.startswith('hellos')) - -# 2.endswith -print(a.endswith('ce')) #返回true -print(a.endswith('practice',30,len(a))) #返回true - - +# 字符串常用操作:创建/查找/修改/判断 +# 一.创建 +# 1.单引号/双引号 +a = 'hello python' +b = "hello world" + +# 2.三引号 支持换行输入 +c = """hello + python""" +print(a) +print(b) +print(c) + +# 3.通过str()转换创建 +d = str(2) +print(type(d)) + +# 二.查找 +# 1.find方法 +a = 'hello python and learn python and have fun' +print(a.find('and')) +print(a.find('and',15,42))# 可以放查找的起始位置和结束位置,如不放则默认在全部范围内查找 +print(a.find('ands')) # find找不到会返回-1 + +# 2.index方法 +print(a.index('and')) +print(a.index('and',15,42))# 可以放查找的起始位置和结束位置,如不放则默认在全部范围内查找 +#print(a.index('ands'))#!!index 如果找不到会报错 + +# 3.rfind/rindex方法 :与find/index 方法一样,方向改成从右查找 +print(a.rindex('fun')) +print(a.rfind('fun')) + +# 4.count方法: 字符串序列.count(子串, 开始位置下标, 结束位置下标) +print(a.count('python')) + +# 三.修改 +# 1.replace方法 :字符串序列.replace(旧子串, 新子串, 替换次数) +a = 'hello python and learn python and have fun and practice' +print(a.replace('python','python2')) # 不加替换次数则替换全部 +print(a.replace('python','python2',1))# 可以配合count使用 +# 2.分割 split方法: 字符串序列.split(分割字符, num)-返回列表 +print(a.split('and')) +print(a.split('and',1)) # 最后一个参数代表分割次数 +# 3.join方法 字符或子串.join(多字符串组成的序列) +list1=['a','b','c','d'] +t1=('aa','bb','cc') +print('-'.join(list1)) +print('--'.join(t1)) +# 4.strip方法 +a = ' hello python and learn python and have fun and practice ' +print(a.lstrip())#清除左边的空格 +print(a.rstrip())#清除右边的空格 +print(a.strip())#清除两边的空格 +# 5.字符串对齐、居中 函数:ljust/rjust/center +a='hello' +print(a.ljust(10,'.')) +print(a.rjust(10,'.')) +print(a.center(10,'.')) + +# 四.判断 +# 1.starswith 字符串序列.startswith(子串, 开始位置下标, 结束位置下标) +a = 'hello python and learn python and have fun and practice' +print(a.startswith('hello')) #返回true +print(a.startswith('hello',10,40)) #返回false +print(a.startswith('hellos')) + +# 2.endswith +print(a.endswith('ce')) #返回true +print(a.endswith('practice',30,len(a))) #返回true + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204\350\276\223\345\205\245 format.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204\350\276\223\345\205\245 format.py" index 6e9f961912ba6e7d2512956dbfe5a585d61929ca..f9f231433e43f31411778395375aa05f88b49ccb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204\350\276\223\345\205\245 format.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\255\227\347\254\246\344\270\262\347\232\204\350\276\223\345\205\245 format.py" @@ -1,14 +1,14 @@ -# 方法1: -hello='hello' -name='apple' -age=18 -weigh=52.5 -print(f'{hello},{name},welcome!') - -# 方法2: -print('%s,%s,welcome!'%(hello,name)) -print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) - -#方法3 -f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) +# 方法1: +hello='hello' +name='apple' +age=18 +weigh=52.5 +print(f'{hello},{name},welcome!') + +# 方法2: +print('%s,%s,welcome!'%(hello,name)) +print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) + +#方法3 +f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) print(f) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\260\206\350\276\223\345\205\245\345\206\205\345\256\271\345\257\274\345\205\245\346\234\254\345\234\260\346\226\207\344\273\266.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\260\206\350\276\223\345\205\245\345\206\205\345\256\271\345\257\274\345\205\245\346\234\254\345\234\260\346\226\207\344\273\266.py" index 75b1c4146401f07757e476b832f294433f589948..e2308b715baefdf4a0022fe8a81953328dd84ad8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\260\206\350\276\223\345\205\245\345\206\205\345\256\271\345\257\274\345\205\245\346\234\254\345\234\260\346\226\207\344\273\266.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\260\206\350\276\223\345\205\245\345\206\205\345\256\271\345\257\274\345\205\245\346\234\254\345\234\260\346\226\207\344\273\266.py" @@ -1,16 +1,16 @@ -f=open('doc20201225.txt','w',encoding='utf-8') -f.write("""# 方法1: -hello='hello' -name='apple' -age=18 -weigh=52.5 -print(f'{hello},{name},welcome!') - -# 方法2: -print('%s,%s,welcome!'%(hello,name)) -print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) - -#方法3 -f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) -print(f)""") +f=open('doc20201225.txt','w',encoding='utf-8') +f.write("""# 方法1: +hello='hello' +name='apple' +age=18 +weigh=52.5 +print(f'{hello},{name},welcome!') + +# 方法2: +print('%s,%s,welcome!'%(hello,name)) +print('my name is %s,age is %d,weigh is %.2f'%(name,age,weigh)) + +#方法3 +f='我的名字是{1},我的年龄是{2},我的体重是{0}'.format(weigh,name,age) +print(f)""") f.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" index 539357f6d712b00bd556d61a5f857a31b1fca672..f91cdad85ff7770367eba4ac53e9e3db56fa28d1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" @@ -1,13 +1,13 @@ -# 1.编码 encode -a='你好啊' -b=a.encode(encoding='utf-8') -print(b) -# 2.解码 -c=b.decode(encoding='utf-8') -print(c) -# 3.混合编码 -e='你好'.encode(encoding='utf-8')+'你不好'.encode(encoding='gbk') -print(e) -# 4.混合码解码(鬼符) -print(e.decode('utf-8',errors='replace'))# 错误的码会提示 +# 1.编码 encode +a='你好啊' +b=a.encode(encoding='utf-8') +print(b) +# 2.解码 +c=b.decode(encoding='utf-8') +print(c) +# 3.混合编码 +e='你好'.encode(encoding='utf-8')+'你不好'.encode(encoding='gbk') +print(e) +# 4.混合码解码(鬼符) +print(e.decode('utf-8',errors='replace'))# 错误的码会提示 print(e.decode('utf-8',errors='ignore'))# 错误的码会忽略 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\264\346\250\241\345\235\227.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\264\346\250\241\345\235\227.py" index 98c1ea9b5fc27baed063feb6ee6e730c298fdc1d..ca144f64b201a2aa04daaafb77f33e6919fc940a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\264\346\250\241\345\235\227.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\346\227\266\351\227\264\346\250\241\345\235\227.py" @@ -1,38 +1,38 @@ -import time -import datetime -# time 模块 -shijianchou=time.time() -print(shijianchou) - -structtime=time.localtime(shijianchou) - -print(structtime) - -format_time=time.strftime("%Y/%m/%d %H:%M:%S") -print(format_time) - -# datetime模块 -# 构造一个datetime -dt=datetime.datetime(2020,1,1,15,3,45) -print(dt) - -# 获取当前时间 -now=datetime.datetime.now() -print(now) - -# 将当前时间转换为时间戳 timestamp -st=now.timestamp() -print(st) - -# 将时间戳转换为datetime -datetime1=datetime.datetime.fromtimestamp(st) -print(datetime1) - -# 将str转换为datetime -cday = datetime.datetime.strptime('2015/6/1 18:19:59','%Y/%m/%d %H:%M:%S') -print(cday) - -# 将datetime转换为str -now=datetime.datetime.now() -str_now=now.strftime('%Y/%m/%d %H:%M:%S') -print(str_now) +import time +import datetime +# time 模块 +shijianchou=time.time() +print(shijianchou) + +structtime=time.localtime(shijianchou) + +print(structtime) + +format_time=time.strftime("%Y/%m/%d %H:%M:%S") +print(format_time) + +# datetime模块 +# 构造一个datetime +dt=datetime.datetime(2020,1,1,15,3,45) +print(dt) + +# 获取当前时间 +now=datetime.datetime.now() +print(now) + +# 将当前时间转换为时间戳 timestamp +st=now.timestamp() +print(st) + +# 将时间戳转换为datetime +datetime1=datetime.datetime.fromtimestamp(st) +print(datetime1) + +# 将str转换为datetime +cday = datetime.datetime.strptime('2015/6/1 18:19:59','%Y/%m/%d %H:%M:%S') +print(cday) + +# 将datetime转换为str +now=datetime.datetime.now() +str_now=now.strftime('%Y/%m/%d %H:%M:%S') +print(str_now) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/mymath-\351\235\231\346\200\201\346\226\271\346\263\225.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/mymath-\351\235\231\346\200\201\346\226\271\346\263\225.py" index f746800eb5c74d2778de2cde42fe3a733b05afa7..c8c26c2a48a5dad0c3208c9c56acb16b7fa497c7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/mymath-\351\235\231\346\200\201\346\226\271\346\263\225.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/mymath-\351\235\231\346\200\201\346\226\271\346\263\225.py" @@ -1,17 +1,17 @@ -# 静态方法 -class Mymath: - @staticmethod - def myadd(num1,num2): - return num1+num2 - def my_subtraction(num1,num2): - return num1-num2 - def myplus(num1,num2): - return num1*num2 - def my_division(num1,num2): - return num1/num2 - def mypower(num1,num2): - return num1**num2 - - -print(Mymath.mypower(3,3)) - +# 静态方法 +class Mymath: + @staticmethod + def myadd(num1,num2): + return num1+num2 + def my_subtraction(num1,num2): + return num1-num2 + def myplus(num1,num2): + return num1*num2 + def my_division(num1,num2): + return num1/num2 + def mypower(num1,num2): + return num1**num2 + + +print(Mymath.mypower(3,3)) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\270\272\344\270\212\350\212\202\350\257\276\350\207\252\345\256\232\344\271\211\347\261\273\346\267\273\345\212\240\345\205\266\344\273\226\345\212\237\350\203\275.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\270\272\344\270\212\350\212\202\350\257\276\350\207\252\345\256\232\344\271\211\347\261\273\346\267\273\345\212\240\345\205\266\344\273\226\345\212\237\350\203\275.py" index d6a9063fe0abd1a2895063862801c24515100aa9..f8b2b698248efac7f8f1b862a858eba37c5fea10 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\270\272\344\270\212\350\212\202\350\257\276\350\207\252\345\256\232\344\271\211\347\261\273\346\267\273\345\212\240\345\205\266\344\273\226\345\212\237\350\203\275.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\344\270\272\344\270\212\350\212\202\350\257\276\350\207\252\345\256\232\344\271\211\347\261\273\346\267\273\345\212\240\345\205\266\344\273\226\345\212\237\350\203\275.py" @@ -1,51 +1,51 @@ -class Restaurant: - # 类属性 - eating=True - # 类的私有属性 - __earingmoney=True - # 类方法 - @classmethod - def get_money(cls): - return cls.__earingmoney - # 初始化实例属性 - def __init__(self,name,cuisine): - self.name=name - self.cuisine=cuisine - # 实例的私有属性 - self.__mymoney=200000 - - # __str --介绍餐馆 - def __str__(self): - return f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine}' - # 实例方法--餐馆介绍 - def describe(self): - print(f'餐馆的名字是{self.name}') - print(f'餐馆的菜式是{self.cuisine}') - # 实例方法--开馆营业 - def open_restaurant(self): - print(f'{self.name}要开馆营业啦,欢迎光临!') - -# coucou=Restaurant('凑凑','火锅') -# coucou.describe() -# coucou.open_restaurant() -# -# xicha=Restaurant("喜茶",'茶饮') -# xicha.describe() -# xicha.open_restaurant() - -# 调用类属性,类属性可以通过实例访问,也可以通过类访问 -xingbake=Restaurant('星巴克','下午茶') -print(xingbake.eating) -print(Restaurant.eating) - -# 调用类私有属性,语法是 类._类名__私有变量名 -print(xingbake._Restaurant__earingmoney) - -# 调用类方法 -print(xingbake.get_money()) - -# 调用实例的私有属性 -print(xingbake._Restaurant__mymoney) - -# 调用str方法 -print(xingbake) +class Restaurant: + # 类属性 + eating=True + # 类的私有属性 + __earingmoney=True + # 类方法 + @classmethod + def get_money(cls): + return cls.__earingmoney + # 初始化实例属性 + def __init__(self,name,cuisine): + self.name=name + self.cuisine=cuisine + # 实例的私有属性 + self.__mymoney=200000 + + # __str --介绍餐馆 + def __str__(self): + return f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine}' + # 实例方法--餐馆介绍 + def describe(self): + print(f'餐馆的名字是{self.name}') + print(f'餐馆的菜式是{self.cuisine}') + # 实例方法--开馆营业 + def open_restaurant(self): + print(f'{self.name}要开馆营业啦,欢迎光临!') + +# coucou=Restaurant('凑凑','火锅') +# coucou.describe() +# coucou.open_restaurant() +# +# xicha=Restaurant("喜茶",'茶饮') +# xicha.describe() +# xicha.open_restaurant() + +# 调用类属性,类属性可以通过实例访问,也可以通过类访问 +xingbake=Restaurant('星巴克','下午茶') +print(xingbake.eating) +print(Restaurant.eating) + +# 调用类私有属性,语法是 类._类名__私有变量名 +print(xingbake._Restaurant__earingmoney) + +# 调用类方法 +print(xingbake.get_money()) + +# 调用实例的私有属性 +print(xingbake._Restaurant__mymoney) + +# 调用str方法 +print(xingbake) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/my math.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/my math.py" index 182f60a60d8ed79ce509f0da0c794b25da3aab58..16edae20db04656596f09d01cbec0d1a446d2123 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/my math.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/my math.py" @@ -1,14 +1,14 @@ -class Mymath: - def myadd(self,num1,num2): - return num1+num2 - def my_subtraction(self,num1,num2): - return num1-num2 - def myplus(self,num1,num2): - return num1*num2 - def my_division(self,num1,num2): - return num1/num2 - def mypower(self,num1,num2): - return num1**num2 - -mymath1=Mymath() -print(mymath1.mypower(2,4)) +class Mymath: + def myadd(self,num1,num2): + return num1+num2 + def my_subtraction(self,num1,num2): + return num1-num2 + def myplus(self,num1,num2): + return num1*num2 + def my_division(self,num1,num2): + return num1/num2 + def mypower(self,num1,num2): + return num1**num2 + +mymath1=Mymath() +print(mymath1.mypower(2,4)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\344\270\200\344\270\252\347\261\273\357\274\214\345\271\266\345\210\233\345\273\272\345\244\232\344\270\252\345\256\236\344\276\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\344\270\200\344\270\252\347\261\273\357\274\214\345\271\266\345\210\233\345\273\272\345\244\232\344\270\252\345\256\236\344\276\213.py" index d6a9063fe0abd1a2895063862801c24515100aa9..f8b2b698248efac7f8f1b862a858eba37c5fea10 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\344\270\200\344\270\252\347\261\273\357\274\214\345\271\266\345\210\233\345\273\272\345\244\232\344\270\252\345\256\236\344\276\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\344\270\200\344\270\252\347\261\273\357\274\214\345\271\266\345\210\233\345\273\272\345\244\232\344\270\252\345\256\236\344\276\213.py" @@ -1,51 +1,51 @@ -class Restaurant: - # 类属性 - eating=True - # 类的私有属性 - __earingmoney=True - # 类方法 - @classmethod - def get_money(cls): - return cls.__earingmoney - # 初始化实例属性 - def __init__(self,name,cuisine): - self.name=name - self.cuisine=cuisine - # 实例的私有属性 - self.__mymoney=200000 - - # __str --介绍餐馆 - def __str__(self): - return f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine}' - # 实例方法--餐馆介绍 - def describe(self): - print(f'餐馆的名字是{self.name}') - print(f'餐馆的菜式是{self.cuisine}') - # 实例方法--开馆营业 - def open_restaurant(self): - print(f'{self.name}要开馆营业啦,欢迎光临!') - -# coucou=Restaurant('凑凑','火锅') -# coucou.describe() -# coucou.open_restaurant() -# -# xicha=Restaurant("喜茶",'茶饮') -# xicha.describe() -# xicha.open_restaurant() - -# 调用类属性,类属性可以通过实例访问,也可以通过类访问 -xingbake=Restaurant('星巴克','下午茶') -print(xingbake.eating) -print(Restaurant.eating) - -# 调用类私有属性,语法是 类._类名__私有变量名 -print(xingbake._Restaurant__earingmoney) - -# 调用类方法 -print(xingbake.get_money()) - -# 调用实例的私有属性 -print(xingbake._Restaurant__mymoney) - -# 调用str方法 -print(xingbake) +class Restaurant: + # 类属性 + eating=True + # 类的私有属性 + __earingmoney=True + # 类方法 + @classmethod + def get_money(cls): + return cls.__earingmoney + # 初始化实例属性 + def __init__(self,name,cuisine): + self.name=name + self.cuisine=cuisine + # 实例的私有属性 + self.__mymoney=200000 + + # __str --介绍餐馆 + def __str__(self): + return f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine}' + # 实例方法--餐馆介绍 + def describe(self): + print(f'餐馆的名字是{self.name}') + print(f'餐馆的菜式是{self.cuisine}') + # 实例方法--开馆营业 + def open_restaurant(self): + print(f'{self.name}要开馆营业啦,欢迎光临!') + +# coucou=Restaurant('凑凑','火锅') +# coucou.describe() +# coucou.open_restaurant() +# +# xicha=Restaurant("喜茶",'茶饮') +# xicha.describe() +# xicha.open_restaurant() + +# 调用类属性,类属性可以通过实例访问,也可以通过类访问 +xingbake=Restaurant('星巴克','下午茶') +print(xingbake.eating) +print(Restaurant.eating) + +# 调用类私有属性,语法是 类._类名__私有变量名 +print(xingbake._Restaurant__earingmoney) + +# 调用类方法 +print(xingbake.get_money()) + +# 调用实例的私有属性 +print(xingbake._Restaurant__mymoney) + +# 调用str方法 +print(xingbake) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\273\247\346\211\277.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\273\247\346\211\277.py" index cda94c9661d7ea856059359365e60ee7755b3cd0..770913a9c1fd757f417397507230e32d104f1ae3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\273\247\346\211\277.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/5\347\217\255_Carmen_\347\254\254\345\233\233\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\273\247\346\211\277.py" @@ -1,50 +1,50 @@ -class Restaurant: - def __init__(self,name,cuisine): - self.name=name - self.cuisine=cuisine - self.number_served=100 - # 开馆营业 - def open_restaurant(self): - print(f'{self.name}要开馆营业啦,欢迎光临!') - # 更新设置就餐人数 - def print_num_served(self,num): - if num >= self.number_served: - self.number_served=num - else: - print('就餐人数只能变多不能减少哦') - # 增加就餐人数 - - def increment_served(self,add_num): - self.number_served+=add_num -# 餐馆介绍 - def describe(self): - print(f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine},就餐人数有{self.number_served}') - -# 创建新的子类-冰淇淋店 -class IceCreamStand(Restaurant): - def __init__(self,name,cuisine): - super().__init__(name,cuisine) - self.flavor_list=[] - # 更新口味列表 - # def print_icecream_flavor(self,flavor): - # flavor_list=['波波茶'] - # flavor_list.append(flavor) - # print(f'冰淇淋店铺内的口味有{flavor_list}') - # 增加新的口味 - def add_icecream_flavor(self,flavorlist): - self.flavor_list.append(flavorlist) - # 描述全部的口味 - def print_icecream_flavor(self): - print(f'冰淇淋店铺内的口味有{self.flavor_list}') - - -mixuebingcheng=IceCreamStand('蜜雪冰城','茶饮') -mixuebingcheng.describe() -mixuebingcheng.add_icecream_flavor('波波茶') -mixuebingcheng.print_icecream_flavor() - -mixuebingcheng.add_icecream_flavor('乌龙茶') -mixuebingcheng.print_icecream_flavor() - -mixuebingcheng.add_icecream_flavor('牛乳茶') +class Restaurant: + def __init__(self,name,cuisine): + self.name=name + self.cuisine=cuisine + self.number_served=100 + # 开馆营业 + def open_restaurant(self): + print(f'{self.name}要开馆营业啦,欢迎光临!') + # 更新设置就餐人数 + def print_num_served(self,num): + if num >= self.number_served: + self.number_served=num + else: + print('就餐人数只能变多不能减少哦') + # 增加就餐人数 + + def increment_served(self,add_num): + self.number_served+=add_num +# 餐馆介绍 + def describe(self): + print(f'餐馆的名字是{self.name},餐馆的菜式是{self.cuisine},就餐人数有{self.number_served}') + +# 创建新的子类-冰淇淋店 +class IceCreamStand(Restaurant): + def __init__(self,name,cuisine): + super().__init__(name,cuisine) + self.flavor_list=[] + # 更新口味列表 + # def print_icecream_flavor(self,flavor): + # flavor_list=['波波茶'] + # flavor_list.append(flavor) + # print(f'冰淇淋店铺内的口味有{flavor_list}') + # 增加新的口味 + def add_icecream_flavor(self,flavorlist): + self.flavor_list.append(flavorlist) + # 描述全部的口味 + def print_icecream_flavor(self): + print(f'冰淇淋店铺内的口味有{self.flavor_list}') + + +mixuebingcheng=IceCreamStand('蜜雪冰城','茶饮') +mixuebingcheng.describe() +mixuebingcheng.add_icecream_flavor('波波茶') +mixuebingcheng.print_icecream_flavor() + +mixuebingcheng.add_icecream_flavor('乌龙茶') +mixuebingcheng.print_icecream_flavor() + +mixuebingcheng.add_icecream_flavor('牛乳茶') mixuebingcheng.print_icecream_flavor() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\257\276-json\347\273\203\344\271\240\344\272\254\344\270\234\345\225\206\345\223\201\350\257\204\350\256\272\345\210\227\350\241\250.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\257\276-json\347\273\203\344\271\240\344\272\254\344\270\234\345\225\206\345\223\201\350\257\204\350\256\272\345\210\227\350\241\250.py" index 6f2d68cc54cc1799b1fff38a8e5a3e5525fb46aa..cad3195fdd64fca7f99ec877da9e93d28302aa63 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\257\276-json\347\273\203\344\271\240\344\272\254\344\270\234\345\225\206\345\223\201\350\257\204\350\256\272\345\210\227\350\241\250.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\200\350\257\276-json\347\273\203\344\271\240\344\272\254\344\270\234\345\225\206\345\223\201\350\257\204\350\256\272\345\210\227\350\241\250.py" @@ -1,20 +1,20 @@ -import requests -import json -import time -from jsonpath import jsonpath -import pprint - -for page in range(1,6): - time.sleep(8) - print(f'以下是第{page}页------------------------------') - url=f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=3107472&score=0&sortType=5&page={page-1}&pageSize=10&isShadowSku=0&fold=1' - headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"} - response=requests.get(url=url,headers=headers).text - response=response.replace('fetchJSON_comment98(',"") - response=response.replace(');',"") - with open("search_keyword.html", "w", encoding="utf-8") as f: - f.write(response) - f.close() - jsonjiexi=json.loads(response) - 列表=jsonpath(jsonjiexi,'$..content') +import requests +import json +import time +from jsonpath import jsonpath +import pprint + +for page in range(1,6): + time.sleep(8) + print(f'以下是第{page}页------------------------------') + url=f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=3107472&score=0&sortType=5&page={page-1}&pageSize=10&isShadowSku=0&fold=1' + headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"} + response=requests.get(url=url,headers=headers).text + response=response.replace('fetchJSON_comment98(',"") + response=response.replace(');',"") + with open("search_keyword.html", "w", encoding="utf-8") as f: + f.write(response) + f.close() + jsonjiexi=json.loads(response) + 列表=jsonpath(jsonjiexi,'$..content') pprint.pprint(列表) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\211\350\257\276-\347\273\203\344\271\240\347\210\254\345\217\226\345\226\234\351\251\254\346\213\211\351\233\205\351\237\263\351\242\221.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\211\350\257\276-\347\273\203\344\271\240\347\210\254\345\217\226\345\226\234\351\251\254\346\213\211\351\233\205\351\237\263\351\242\221.py" index 4d7b40ab037edc925fa38ed9adf3a798ee170a8b..50ad1c82534fa2d73e60210e761f267871ac4495 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\211\350\257\276-\347\273\203\344\271\240\347\210\254\345\217\226\345\226\234\351\251\254\346\213\211\351\233\205\351\237\263\351\242\221.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\270\211\350\257\276-\347\273\203\344\271\240\347\210\254\345\217\226\345\226\234\351\251\254\346\213\211\351\233\205\351\237\263\351\242\221.py" @@ -1,53 +1,53 @@ -import requests -from lxml import etree -import json -import jsonpath -网址 = 'https://www.ximalaya.com/xiangsheng/9723091/' -UA伪装 = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'} -响应数据 = requests.get(url=网址,headers=UA伪装).text -解析 = etree.HTML(响应数据) -总页数 = 解析.xpath('//ul[@class="pagination-page WJ_"]/li[last()-1]//text()')[0] -# print(type(总页数)) -for i in range(1,int(总页数)+1): - if i ==1: - 网址=f'https://www.ximalaya.com/xiangsheng/9723091/' - else: - 网址=f'https://www.ximalaya.com/xiangsheng/9723091/p{i}/' - 响应数据 = requests.get(url=网址, headers=UA伪装).text - 解析 = etree.HTML(响应数据) - 名称列表 = 解析.xpath('//div[@class="sound-list _is"]/ul/li/div[2]/a/span/text()') - 编号列表 = 解析.xpath('//div[@class="sound-list _is"]/ul/li/div[2]/a/@href') - 编号列表 = [编号.split('/')[-1] for 编号 in 编号列表] - 字典=dict(zip(名称列表,编号列表)) - 请求头 = {"Accept": "*/*", - "Accept-Encoding": "gzip, deflate, br", - "Accept-Language": "zh-CN,zh;q=0.9", - "Connection": "keep-alive", - "Cookie": "_xmLog=h5&feaa1aeb-2d30-410c-9cd8-56941706c9b2&2.2.12; x_xmly_traffic=utm_source%253A%2526utm_medium%253A%2526utm_campaign%253A%2526utm_content%253A%2526utm_term%253A%2526utm_from%253A; Hm_lvt_4a7d8ec50cfd6af753c4f8aee3425070=1611587199,1611624927; Hm_lpvt_4a7d8ec50cfd6af753c4f8aee3425070=1611626594", - "Host": "www.ximalaya.com", - "Referer": "https://www.ximalaya.com/xiangsheng/9723091/", - "sec-ch-ua-mobile": "?0", - "Sec-Fetch-Dest": "empty", - "Sec-Fetch-Mode": "cors", - "Sec-Fetch-Site": "same-origin", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", - "xm-sign": "3c6a1e0c1d047a4fc000304f0b9184cd(11)1611629168243(57)1611627938923"} - - for 名称,编号 in 字典.items(): - # print(名称,编号) - # 通过网址得到的响应中包含 每一个音频的存储地址 - 网址=f'https://www.ximalaya.com/revision/play/v1/audio?id={编号}&ptype=1' - 响应数据 = requests.get(url=网址,headers=请求头).text - 相应数据 - print(响应数据) - # 解析=json.loads(响应数据) - # 音频网址=jsonpath(解析,'$..src') - # # print(音频网址) - # 解析 = etree.HTML(响应数据) - - - - - - - +import requests +from lxml import etree +import json +import jsonpath +网址 = 'https://www.ximalaya.com/xiangsheng/9723091/' +UA伪装 = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'} +响应数据 = requests.get(url=网址,headers=UA伪装).text +解析 = etree.HTML(响应数据) +总页数 = 解析.xpath('//ul[@class="pagination-page WJ_"]/li[last()-1]//text()')[0] +# print(type(总页数)) +for i in range(1,int(总页数)+1): + if i ==1: + 网址=f'https://www.ximalaya.com/xiangsheng/9723091/' + else: + 网址=f'https://www.ximalaya.com/xiangsheng/9723091/p{i}/' + 响应数据 = requests.get(url=网址, headers=UA伪装).text + 解析 = etree.HTML(响应数据) + 名称列表 = 解析.xpath('//div[@class="sound-list _is"]/ul/li/div[2]/a/span/text()') + 编号列表 = 解析.xpath('//div[@class="sound-list _is"]/ul/li/div[2]/a/@href') + 编号列表 = [编号.split('/')[-1] for 编号 in 编号列表] + 字典=dict(zip(名称列表,编号列表)) + 请求头 = {"Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-CN,zh;q=0.9", + "Connection": "keep-alive", + "Cookie": "_xmLog=h5&feaa1aeb-2d30-410c-9cd8-56941706c9b2&2.2.12; x_xmly_traffic=utm_source%253A%2526utm_medium%253A%2526utm_campaign%253A%2526utm_content%253A%2526utm_term%253A%2526utm_from%253A; Hm_lvt_4a7d8ec50cfd6af753c4f8aee3425070=1611587199,1611624927; Hm_lpvt_4a7d8ec50cfd6af753c4f8aee3425070=1611626594", + "Host": "www.ximalaya.com", + "Referer": "https://www.ximalaya.com/xiangsheng/9723091/", + "sec-ch-ua-mobile": "?0", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + "xm-sign": "3c6a1e0c1d047a4fc000304f0b9184cd(11)1611629168243(57)1611627938923"} + + for 名称,编号 in 字典.items(): + # print(名称,编号) + # 通过网址得到的响应中包含 每一个音频的存储地址 + 网址=f'https://www.ximalaya.com/revision/play/v1/audio?id={编号}&ptype=1' + 响应数据 = requests.get(url=网址,headers=请求头).text + 相应数据 + print(响应数据) + # 解析=json.loads(响应数据) + # 音频网址=jsonpath(解析,'$..src') + # # print(音频网址) + # 解析 = etree.HTML(响应数据) + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\350\257\276beautifulsoup\345\272\223\347\273\203\344\271\240\347\210\254\345\217\226\350\261\206\347\223\243top250.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\350\257\276beautifulsoup\345\272\223\347\273\203\344\271\240\347\210\254\345\217\226\350\261\206\347\223\243top250.py" index 561c26908912e72e3ca1189fb62f6bb335e6c1db..8bc28760929d8f045b4f642ed336fe2ce4a1ee34 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\350\257\276beautifulsoup\345\272\223\347\273\203\344\271\240\347\210\254\345\217\226\350\261\206\347\223\243top250.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\271\235\345\221\2500222-0228/5\347\217\255_Carmen_\347\254\254\344\271\235\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\350\257\276beautifulsoup\345\272\223\347\273\203\344\271\240\347\210\254\345\217\226\350\261\206\347\223\243top250.py" @@ -1,23 +1,23 @@ -import requests -from bs4 import BeautifulSoup - -class Douban: - def __init__(self): - self.URL = 'https://movie.douban.com/top250' - self.starnum =[] - for start_num in range(0,251,25): - self.starnum.append(start_num) - self.header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'} - - def get_top250(self): - for start in self.starnum: - start = str(start) - html = requests.get(self.URL, params={'start':start},headers = self.header) - soup = BeautifulSoup(html.text,"html.parser") - name = soup.select('#content > div > div.article > ol > li > div > div.info > div.hd > a > span:nth-child(1)') - for name in name: - print(name.get_text()) - -if __name__== "__main__": - cls = Douban() +import requests +from bs4 import BeautifulSoup + +class Douban: + def __init__(self): + self.URL = 'https://movie.douban.com/top250' + self.starnum =[] + for start_num in range(0,251,25): + self.starnum.append(start_num) + self.header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'} + + def get_top250(self): + for start in self.starnum: + start = str(start) + html = requests.get(self.URL, params={'start':start},headers = self.header) + soup = BeautifulSoup(html.text,"html.parser") + name = soup.select('#content > div > div.article > ol > li > div > div.info > div.hd > a > span:nth-child(1)') + for name in name: + print(name.get_text()) + +if __name__== "__main__": + cls = Douban() cls.get_top250() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\347\272\277\347\250\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\347\272\277\347\250\213.py" index 7d49cd73445425dd901d2c001decb09e0af6bb41..8a0312c91a85ceb01848396a7a481b18efac38dd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\347\272\277\347\250\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\347\272\277\347\250\213.py" @@ -1,25 +1,25 @@ -import threading -import time - -# 唱歌任务 -def sing(): - for i in range(3): - print("正在唱歌...%d" % i) - time.sleep(1) - -# 跳舞任务 -def dance(): - for i in range(3): - print("正在跳舞...%d" % i) - time.sleep(1) - - -if __name__ == '__main__': - # target: 线程执行的函数名 - # 创建两个线程 - sing_thread = threading.Thread(target=sing) - dance_thread = threading.Thread(target=dance) - - # 开启线程 - sing_thread.start() +import threading +import time + +# 唱歌任务 +def sing(): + for i in range(3): + print("正在唱歌...%d" % i) + time.sleep(1) + +# 跳舞任务 +def dance(): + for i in range(3): + print("正在跳舞...%d" % i) + time.sleep(1) + + +if __name__ == '__main__': + # target: 线程执行的函数名 + # 创建两个线程 + sing_thread = threading.Thread(target=sing) + dance_thread = threading.Thread(target=dance) + + # 开启线程 + sing_thread.start() dance_thread.start() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\350\277\233\347\250\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\350\277\233\347\250\213.py" index 162076dda7ef98ede0a89de78d13333c16c7be5f..d424034e622ed8ad3318f15af3dc4729221d43ed 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\350\277\233\347\250\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/\345\210\233\345\273\272\345\244\232\350\277\233\347\250\213.py" @@ -1,25 +1,25 @@ -import multiprocessing -import time - - -# 跳舞任务 -def dance(): - for i in range(5): - print("跳舞中...") - time.sleep(1) - - -# 唱歌任务 -def sing(): - for i in range(5): - print("唱歌中...") - time.sleep(1) - -if __name__ == '__main__': - # 创建跳舞的子进程 - dance_process = multiprocessing.Process(target=dance) - sing_process = multiprocessing.Process(target=sing) - - # 启动子进程执行对应的任务 - dance_process.start() +import multiprocessing +import time + + +# 跳舞任务 +def dance(): + for i in range(5): + print("跳舞中...") + time.sleep(1) + + +# 唱歌任务 +def sing(): + for i in range(5): + print("唱歌中...") + time.sleep(1) + +if __name__ == '__main__': + # 创建跳舞的子进程 + dance_process = multiprocessing.Process(target=dance) + sing_process = multiprocessing.Process(target=sing) + + # 启动子进程执行对应的任务 + dance_process.start() sing_process.start() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\215\217\347\250\213\350\256\241\347\256\227\345\271\263\345\235\207\346\225\260.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\215\217\347\250\213\350\256\241\347\256\227\345\271\263\345\235\207\346\225\260.py" index f17ea127f8034f2b09ddc264185caaeaa647dcfa..5d924d3df0e0c789a217b4ace46828ee3d31cde7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\215\217\347\250\213\350\256\241\347\256\227\345\271\263\345\235\207\346\225\260.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\345\215\217\347\250\213\350\256\241\347\256\227\345\271\263\345\235\207\346\225\260.py" @@ -1,31 +1,31 @@ -# 生成器计算平均数 -# def my_avg(num): -# total=0 -# cishu=0 -# while cishu<=num: -# total+=cishu -# cishu+=1 -# yield total/cishu -# -# result=my_avg(3) -# print(next(result)) - - -# 协程计算平均数 -def coro_avg(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -my_avg = coro_avg() -print(next(my_avg)) -print(my_avg.send(2)) -print(my_avg.send(3)) - - +# 生成器计算平均数 +# def my_avg(num): +# total=0 +# cishu=0 +# while cishu<=num: +# total+=cishu +# cishu+=1 +# yield total/cishu +# +# result=my_avg(3) +# print(next(result)) + + +# 协程计算平均数 +def coro_avg(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +my_avg = coro_avg() +print(next(my_avg)) +print(my_avg.send(2)) +print(my_avg.send(3)) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\344\272\222\346\226\245\351\224\201.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\344\272\222\346\226\245\351\224\201.py" index 66a1f91f89636ed78ce0599afed63fb7abe57f39..cdec8d2601bdaafb23f8bffdd0c4ec02e36cfef0 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\344\272\222\346\226\245\351\224\201.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\344\272\224\345\221\2500111-0117/5\347\217\255_Carmen_\347\254\254\344\272\224\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\344\272\222\346\226\245\351\224\201.py" @@ -1,42 +1,42 @@ -import threading - - -# 定义全局变量 -g_num = 0 - -# 创建全局互斥锁 -lock = threading.Lock() - - -# 循环一次给全局变量加1 -def sum_num1(): - # 上锁 - lock.acquire() - for i in range(1000000): - global g_num - g_num += 1 - - print("sum1:", g_num) - # 释放锁 - lock.release() - - -# 循环一次给全局变量加1 -def sum_num2(): - # 上锁 - lock.acquire() - for i in range(1000000): - global g_num - g_num += 1 - print("sum2:", g_num) - # 释放锁 - lock.release() - - -if __name__ == '__main__': - # 创建两个线程 - first_thread = threading.Thread(target=sum_num1) - second_thread = threading.Thread(target=sum_num2) - # 启动线程 - first_thread.start() +import threading + + +# 定义全局变量 +g_num = 0 + +# 创建全局互斥锁 +lock = threading.Lock() + + +# 循环一次给全局变量加1 +def sum_num1(): + # 上锁 + lock.acquire() + for i in range(1000000): + global g_num + g_num += 1 + + print("sum1:", g_num) + # 释放锁 + lock.release() + + +# 循环一次给全局变量加1 +def sum_num2(): + # 上锁 + lock.acquire() + for i in range(1000000): + global g_num + g_num += 1 + print("sum2:", g_num) + # 释放锁 + lock.release() + + +if __name__ == '__main__': + # 创建两个线程 + first_thread = threading.Thread(target=sum_num1) + second_thread = threading.Thread(target=sum_num2) + # 启动线程 + first_thread.start() second_thread.start() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" index c45c9be502cf2e02356e22f8de657d0e126c436d..e3b234d051b90d5ded7ec34fb6199455e5a12e68 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,25 +1,25 @@ -- #### 一、讲清楚浏览器地址栏敲下`url`发生了什么? - - - ##### 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 - - - 客户端要求建立连接 - - 服务器收到请求后确认联机信息,像客户端返回信息表示准备好 - - 客户端收到服务器返回信息,与服务器建立连接 - - - ##### 建立好连接后,客户端向服务端发送请求 - - - ##### 服务端处理请求并返回结果 - - - ##### 浏览器接收到响应后, 做相应的渲染 - - ##### - - ##### - -- #### 二、五层协议有哪五层, 举例说明. - - - 应用层(网易云/浏览网页) - - 传输层(负责向两个主机应用进程的通信提供服务.) - - 网络层(决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段.) - - 数据链路层 +- #### 一、讲清楚浏览器地址栏敲下`url`发生了什么? + + - ##### 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 + + - 客户端要求建立连接 + - 服务器收到请求后确认联机信息,像客户端返回信息表示准备好 + - 客户端收到服务器返回信息,与服务器建立连接 + + - ##### 建立好连接后,客户端向服务端发送请求 + + - ##### 服务端处理请求并返回结果 + + - ##### 浏览器接收到响应后, 做相应的渲染 + + ##### + + ##### + +- #### 二、五层协议有哪五层, 举例说明. + + - 应用层(网易云/浏览网页) + - 传输层(负责向两个主机应用进程的通信提供服务.) + - 网络层(决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段.) + - 数据链路层 - 物理层 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" index 0f236220bf0411813c0233026f93ba06d72fddb7..6969b4eb989e8aa4dcb9fef27de812e643dec9b9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,61 +1,61 @@ - - -# 第六周-第三节课 - -## 抓包 - -抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. - -对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. - -- 一、抓包软件 - - - Fiddler - - ``` - https://www.telerik.com/fiddler - ``` - - - Charles - - - wireshark - -- 二、web端抓包 - - 现代互联网环境几乎都是https协议的网站 - -- 三、App端抓包 - - - 下载夜神模拟器 - - 打开远程终端连接 - - wifi调出设置的时候要长按 - - 查看当前fiddler所在pc本地局域网ip - - ipconfig/ifconfig - - 在代理项中填写ip地址和fiddler端口, 默认是8888 - - 信任证书 - - App有一定的反爬措施, 第一件事就是修改请求协议 - - 双向验证------需要客户端也带上证书 - - 解决请求协议上的反爬措施 - - 安装VirtualXposed_0.18.2, JustTrustMe - -- 四、PostMan简单使用 - - - GET - - - POST - - - form_data - - 参数表单 - - - x-www-form-urlencoded - - 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 - - - raw - - 请求的真实body内容. - -- 补充网络资料 - + + +# 第六周-第三节课 + +## 抓包 + +抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. + +对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. + +- 一、抓包软件 + + - Fiddler + + ``` + https://www.telerik.com/fiddler + ``` + + - Charles + + - wireshark + +- 二、web端抓包 + + 现代互联网环境几乎都是https协议的网站 + +- 三、App端抓包 + + - 下载夜神模拟器 + - 打开远程终端连接 + - wifi调出设置的时候要长按 + - 查看当前fiddler所在pc本地局域网ip + - ipconfig/ifconfig + - 在代理项中填写ip地址和fiddler端口, 默认是8888 + - 信任证书 + - App有一定的反爬措施, 第一件事就是修改请求协议 + - 双向验证------需要客户端也带上证书 + - 解决请求协议上的反爬措施 + - 安装VirtualXposed_0.18.2, JustTrustMe + +- 四、PostMan简单使用 + + - GET + + - POST + + - form_data + + 参数表单 + + - x-www-form-urlencoded + + 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 + + - raw + + 请求的真实body内容. + +- 补充网络资料 + - Fiddler抓包工具总结 https://www.cnblogs.com/yyhh/p/5140852.html \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.md" index 6627f946ab08346ccf31a3b515676bbb4f9e8f6d..f2bb41819084e7637df8d0db30a2cd50b44d05a9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Carmen/\347\254\254\345\205\255\345\221\2500118-0124/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_Carmen_\347\254\254\345\205\255\345\221\250 \347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,29 +1,29 @@ -- #### 一、讲述三次握手的过程 - -- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常(客户端说:我要连接你~) -- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常(服务端说:我收到你的链接要求,你来吧!) -- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常(客户端:好的,我知道你收到了,那我来了!) - - - -- #### 二、讲述四次挥手的过程 - - - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道(客户端:我要走了!) - - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭(服务端:好的,我知道你要走了~) - - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道(服务端:那我也走了~) - - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭(客户端:好的,我知道你也走了,拜拜!) - - - - - - ##### - -- #### 三、https加密的过程 - - - 1.客户端向服务端发送通信请求 - - 2.服务端返回给客户端证书和密钥 - - 客户端通过CA中心验证证书的真实性 - - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端 - - 服务端收到加密后的请求数据后, 使用私钥进行解密. +- #### 一、讲述三次握手的过程 + +- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常(客户端说:我要连接你~) +- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常(服务端说:我收到你的链接要求,你来吧!) +- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常(客户端:好的,我知道你收到了,那我来了!) + + + +- #### 二、讲述四次挥手的过程 + + - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道(客户端:我要走了!) + - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭(服务端:好的,我知道你要走了~) + - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道(服务端:那我也走了~) + - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭(客户端:好的,我知道你也走了,拜拜!) + + + + + + ##### + +- #### 三、https加密的过程 + + - 1.客户端向服务端发送通信请求 + - 2.服务端返回给客户端证书和密钥 + - 客户端通过CA中心验证证书的真实性 + - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端 + - 服务端收到加密后的请求数据后, 使用私钥进行解密. - 服务器和客户端使用**对称加密**进行通信 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2541\343\200\2012\351\227\256--\345\233\233\345\244\247\346\225\260\346\215\256\347\261\273\345\236\213\347\232\204\345\210\206\347\261\273.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2541\343\200\2012\351\227\256--\345\233\233\345\244\247\346\225\260\346\215\256\347\261\273\345\236\213\347\232\204\345\210\206\347\261\273.md" index 80863560e934b0351051d74138af386c3a4fb3dc..2ca8d99684260606ccc8b150f51b02b4a478e04c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2541\343\200\2012\351\227\256--\345\233\233\345\244\247\346\225\260\346\215\256\347\261\273\345\236\213\347\232\204\345\210\206\347\261\273.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2541\343\200\2012\351\227\256--\345\233\233\345\244\247\346\225\260\346\215\256\347\261\273\345\236\213\347\232\204\345\210\206\347\261\273.md" @@ -1,9 +1,9 @@ -**四大数据类型的分类** - -- 是否可以更改 - - 可以更改:list(列表)、dict(字典)、set(集合) - - 不可更改:tuple(元祖) -- 是否有序 - - 有序:list(列表)、tuple(元祖) - - 无需:dict(字典)、set(集合) - +**四大数据类型的分类** + +- 是否可以更改 + - 可以更改:list(列表)、dict(字典)、set(集合) + - 不可更改:tuple(元祖) +- 是否有序 + - 有序:list(列表)、tuple(元祖) + - 无需:dict(字典)、set(集合) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2543\351\227\256--\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2543\351\227\256--\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" index 9166bb2bac5d23b6d2760ea117ebb5bf60e1462e..78b8a002af7bd24ea1cfa85a7439b4ab478f2114 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2543\351\227\256--\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\200\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202\344\275\234\344\270\2322020-12-20/\347\254\2543\351\227\256--\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" @@ -1,19 +1,19 @@ -#list(列表) 六大基本类型:int float string bool bytes none -a=[1, 2.0, 'hello world', True, b'one', None] -print(a) -print(type(a)) - -#tuple(元祖) 六大基本类型:int float string bool bytes none -b=(1, 2.0, 'hello world', True, b'one', None) -print(b) -print(type(b)) - -#set(集合) 六大基本类型:int float string bool bytes none -c={1, 2.0, 'hello world', True, b'one', None} -print(c) -print(type(c)) - -#dict(字典) 六大基本类型:int float string bool bytes none -d={"A":1, "B":2.0, "C":'hello world', "D":True, "E":b'one', "F":None} -print(d) +#list(列表) 六大基本类型:int float string bool bytes none +a=[1, 2.0, 'hello world', True, b'one', None] +print(a) +print(type(a)) + +#tuple(元祖) 六大基本类型:int float string bool bytes none +b=(1, 2.0, 'hello world', True, b'one', None) +print(b) +print(type(b)) + +#set(集合) 六大基本类型:int float string bool bytes none +c={1, 2.0, 'hello world', True, b'one', None} +print(c) +print(type(c)) + +#dict(字典) 六大基本类型:int float string bool bytes none +d={"A":1, "B":2.0, "C":'hello world', "D":True, "E":b'one', "F":None} +print(d) print(type(d)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/keep1" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/keep1" index 8b137891791fe96927ad78e64b0aad7bded08bdc..d3f5a12faa99758192ecc4ed3fc22c9249232e86 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/keep1" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/keep1" @@ -1 +1 @@ - + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" index cbdb45422bd647c315f1d5de61621c04771001a3..957b507fc5352ad38d560bf69069decc5c59264e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" @@ -1,75 +1,75 @@ -#第一题、用for循环和while来完成简单的计数 -#for循环 -l = [1, 2, 3, 4] -for e in l: - print(e) -print(f"final e value: {e}\n") - -#while循环 -counter = 0 - -while counter < 10: - if counter == 10: - break - print(f"sim statement: {counter}") - counter += 1 - - -#第二题、用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 -#for循环 -a = 0 -b = 1 -sum = 0 -for sum in range(0, 12): - if sum < 2: - print(sum) - else: - sum = a + b; - a = b; - b = sum; - print(sum) - -#while循环 -a_1 = 0 -b_1 = 1 -sum_1 = 0 -while sum_1 < 80: - if sum_1 < 2: - print(sum_1) - sum_1 += 1; - elif sum_1 < 80: - sum_1 = a_1 + b_1; - a_1 = b_1; - b_1 = sum_1; - if sum_1 >= 2: - print(sum_1) - elif sum_1 > 80: - break -#第三题、在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError -def add(a, b): - return a + b - - -def sub(a, b): - return a - b - - -def mul(a, b): - return a * b - - -def div(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError - -a = 2 -b = 0 - - -print("a+b=", add(a, b)) -print("a-b=", sub(a, b)) -print("a*b=", mul(a, b)) -print("a/b=", div(a, b)) - +#第一题、用for循环和while来完成简单的计数 +#for循环 +l = [1, 2, 3, 4] +for e in l: + print(e) +print(f"final e value: {e}\n") + +#while循环 +counter = 0 + +while counter < 10: + if counter == 10: + break + print(f"sim statement: {counter}") + counter += 1 + + +#第二题、用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 +#for循环 +a = 0 +b = 1 +sum = 0 +for sum in range(0, 12): + if sum < 2: + print(sum) + else: + sum = a + b; + a = b; + b = sum; + print(sum) + +#while循环 +a_1 = 0 +b_1 = 1 +sum_1 = 0 +while sum_1 < 80: + if sum_1 < 2: + print(sum_1) + sum_1 += 1; + elif sum_1 < 80: + sum_1 = a_1 + b_1; + a_1 = b_1; + b_1 = sum_1; + if sum_1 >= 2: + print(sum_1) + elif sum_1 > 80: + break +#第三题、在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError +def add(a, b): + return a + b + + +def sub(a, b): + return a - b + + +def mul(a, b): + return a * b + + +def div(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError + +a = 2 +b = 0 + + +print("a+b=", add(a, b)) +print("a-b=", sub(a, b)) +print("a*b=", mul(a, b)) +print("a/b=", div(a, b)) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" index da8259f9a638a80e7790b2f474cf04abab80cb0b..3f893b010b229bcfa15ecfd0b6e30c938344296a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -1,66 +1,66 @@ -# 第一题、练习作用域之间的转换 -a = 1 -# 局部变量转化为全局变量 -def foo(): - global a #定以在函数外的变量就是全局变量, 如果在函数体定义那就时局部变量. - a = 2 - print(a) - -foo() - -# 局部变量转化为自由变量 -def make_foo(): - a = 0 - b = 0 - def foo(value): - nonlocal a, b - a += value - b += 1 - return a / b - - return foo - - -my_avg=make_foo() -print(my_avg(1)) -print(my_avg(2)) - -#第二题、默写一个装饰器, 用来输出函数的执行时间. -import time -def foo(a, b): - count = 1 - while True: - if count >= a ** b: - break - count += 1 - -def clock_it(func, a, b): - start_time = time.time() - result = func(a, b) - end_time = time.time() - print(f"{func.__name__} execute time:{format(end_time - start_time, '.2f')} s") - return result -result = clock_it(foo, 10, 7) -print(result) - -#第三题、使用装饰器来为斐波那契函数添加缓存 -a = {} -def cache_deco(func): - global a - def wrap(n): - if n not in a: - a[n] = func(n) - return a[n] - return wrap - -@cache_deco -def fibo(n): - if n <= 1: - return n - else: - return fibo(n - 1) + fibo(n - 2) - -for i in range(0, 10): - print(fibo(i), end=', ') -print("\n") -print(a) +# 第一题、练习作用域之间的转换 +a = 1 +# 局部变量转化为全局变量 +def foo(): + global a #定以在函数外的变量就是全局变量, 如果在函数体定义那就时局部变量. + a = 2 + print(a) + +foo() + +# 局部变量转化为自由变量 +def make_foo(): + a = 0 + b = 0 + def foo(value): + nonlocal a, b + a += value + b += 1 + return a / b + + return foo + + +my_avg=make_foo() +print(my_avg(1)) +print(my_avg(2)) + +#第二题、默写一个装饰器, 用来输出函数的执行时间. +import time +def foo(a, b): + count = 1 + while True: + if count >= a ** b: + break + count += 1 + +def clock_it(func, a, b): + start_time = time.time() + result = func(a, b) + end_time = time.time() + print(f"{func.__name__} execute time:{format(end_time - start_time, '.2f')} s") + return result +result = clock_it(foo, 10, 7) +print(result) + +#第三题、使用装饰器来为斐波那契函数添加缓存 +a = {} +def cache_deco(func): + global a + def wrap(n): + if n not in a: + a[n] = func(n) + return a[n] + return wrap + +@cache_deco +def fibo(n): + if n <= 1: + return n + else: + return fibo(n - 1) + fibo(n - 2) + +for i in range(0, 10): + print(fibo(i), end=', ') +print("\n") +print(a) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" index 4ea6aa55300e27d615e6ae1ee309e41605ff312a..9ba0081615f11b4ad5cd07246d809e2c3dda0eea 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\270\211\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -1,41 +1,41 @@ -# 第一题、给定一个列表, 根据`grade`来排序 -from pprint import pprint -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -print("原始数据:") -pprint(classes) - -s_grade = sorted(classes, key=lambda x: x.get('grade') ) #通过lambda关键字来声明匿名函数 -print("\n按grade排序") -pprint(s_grade) - -# 第二题、通过filter语句来筛选出Grade为A的同学 -g = filter(lambda x:x.get('grade')=='A',classes) #filter(函数, 可迭代对象) -print("\ngrade为A的同学有:") -pprint(list(g)) - -#第三题、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) -def add(dict): - dict["age"] += 1 #对 age 加1;参数是一个字典 -m = map(add, classes) #classes中的每一个元素就是一个字典 -list(m) -print("\n改变年龄之后:") -pprint(classes) - -#第四题、使用递归函数重构斐波那契函数 -from pprint import pprint -def fact(n): - if n <= 1: - return n - else: - return fact(n-1) + fact(n-2) - -for i in range(0, 10): +# 第一题、给定一个列表, 根据`grade`来排序 +from pprint import pprint +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +print("原始数据:") +pprint(classes) + +s_grade = sorted(classes, key=lambda x: x.get('grade') ) #通过lambda关键字来声明匿名函数 +print("\n按grade排序") +pprint(s_grade) + +# 第二题、通过filter语句来筛选出Grade为A的同学 +g = filter(lambda x:x.get('grade')=='A',classes) #filter(函数, 可迭代对象) +print("\ngrade为A的同学有:") +pprint(list(g)) + +#第三题、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda) +def add(dict): + dict["age"] += 1 #对 age 加1;参数是一个字典 +m = map(add, classes) #classes中的每一个元素就是一个字典 +list(m) +print("\n改变年龄之后:") +pprint(classes) + +#第四题、使用递归函数重构斐波那契函数 +from pprint import pprint +def fact(n): + if n <= 1: + return n + else: + return fact(n-1) + fact(n-2) + +for i in range(0, 10): print(fact(i), end=', ') \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py.py" index 9166bb2bac5d23b6d2760ea117ebb5bf60e1462e..78b8a002af7bd24ea1cfa85a7439b4ab478f2114 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202/my_calculator.py.py" @@ -1,19 +1,19 @@ -#list(列表) 六大基本类型:int float string bool bytes none -a=[1, 2.0, 'hello world', True, b'one', None] -print(a) -print(type(a)) - -#tuple(元祖) 六大基本类型:int float string bool bytes none -b=(1, 2.0, 'hello world', True, b'one', None) -print(b) -print(type(b)) - -#set(集合) 六大基本类型:int float string bool bytes none -c={1, 2.0, 'hello world', True, b'one', None} -print(c) -print(type(c)) - -#dict(字典) 六大基本类型:int float string bool bytes none -d={"A":1, "B":2.0, "C":'hello world', "D":True, "E":b'one', "F":None} -print(d) +#list(列表) 六大基本类型:int float string bool bytes none +a=[1, 2.0, 'hello world', True, b'one', None] +print(a) +print(type(a)) + +#tuple(元祖) 六大基本类型:int float string bool bytes none +b=(1, 2.0, 'hello world', True, b'one', None) +print(b) +print(type(b)) + +#set(集合) 六大基本类型:int float string bool bytes none +c={1, 2.0, 'hello world', True, b'one', None} +print(c) +print(type(c)) + +#dict(字典) 六大基本类型:int float string bool bytes none +d={"A":1, "B":2.0, "C":'hello world', "D":True, "E":b'one', "F":None} +print(d) print(type(d)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" index 10a56a15347f7f0322bb31830af2dd6eab69d53f..a29fc22f9e40150e9c91155426c3622b25a9a962 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" @@ -1,143 +1,143 @@ -# 完成四大基础数据结构的CRUD操作 -#1、List(列表) -#1-1、Create(创建) -list_1 = ['a', 'b', 'c'] -#1-1-1、append 末尾添加元素 -list_1.append('d') -print(list_1) -#1-1-2、列表拼接 -list_2 = ['e', 'f'] -print(list_1 + list_2) -#1-1-3、列表增加 -print(list_1 * 2) -#1-1-4、insert 指定位置添加元素 -list_1.insert(4, 'e') -print(list_1) - -#1-2、Retrieve(检索) -#1-2-1切片 -list_3 = list(range(10)) -print(list_3[1:3]) -#1-2-2 index -list_4 = ['a', 'b', 'c'] -list_4.insert(list_4('b'), 'text') -print(list_4) - -#1-3、Update(更新) -#1-3-1索引赋值 -list_4[0] = 'a-1' -print(list_4) -#1-3-2切片赋值 -list_4[0:2] = 'a' -print(list_4) - -#1-4、Delete(删除) -#1-4-1 pop 从末尾删除元素并返回 -list_4.pop() -print(list_4) -#1-4-2 clear 清除列表中所有元素 -list_4.clear() -print(list_4) - - -#2、Tuple(元组) -#2-1、Create 无 - -#2-2、Retrieve -tuple_1 = (1, 2, 3, 4) -#2-2-1索引取值 -print(tuple_1[1]) -#2-2-2index -print(tuple_1.index(2)) -#2-2-3切片 -print(tuple_1[1:2]) - -#2-3、Update 无 - -#2-4、Delete 无 - - -#3、Dict(字典) -#3-1、Create -#3-1-1、键对值赋值 -dict_1 = {} -dict_1['a'] = 1 -dict_1['b'] = 2 -print(dict_1) - -#3-1-2、Update -dict_2 = {'c':3, 'd':4} -print(dict_1.update(dict_2)) - -#3-1-3、setdefault -dict_2.setdefault('e',0) -print(dict_2) - -#3-2、Retrieve -#3-2-1、键对值 -print(dict_2['c']) - -#3-2-2、get -print(dict_2.get('c')) - -#3-2-3、keys() -print(dict_2.keys()) - -#3-2-4、items() -print(dict_2.items()) - -#3-3、Update -#3-3-1、键对值赋值 -dict_2['c'] = 10 -print(dict_2) - -#3-3-2、update -dict_2.update({'c':5, 'f':10}) -print(dict_2) - -#3-4、Delete -#3-4-1、pop -dict_2.pop('f') -print(dict_2) - -#3-4-2、popitem() 相当于随机返回一个item -dict_2.popitem() -print(dict_2) - -#3-4-3、clear() 删除所有 -print(dict_2.clear()) - - -#4、Set(集合) -#4-1、Create -#4-1-1、add -s = set() -s.add('a') -print(s) - -#4-1-2、update -s.update('b') -print(s) - -#4-2、Retrieve -#4-2-1、运算符in -print('a' in s) - -#4-3、Update -#4-3-1、union -s.union({'c', 'd'}) -print(s) - -#4-4、Delete -#4-4-1、remove -s.remove('d') -print(s) - -#4-4-2、discard -s.discard('a') -print(s) - -#4-4-3、pop -s.pop() -print(s) - +# 完成四大基础数据结构的CRUD操作 +#1、List(列表) +#1-1、Create(创建) +list_1 = ['a', 'b', 'c'] +#1-1-1、append 末尾添加元素 +list_1.append('d') +print(list_1) +#1-1-2、列表拼接 +list_2 = ['e', 'f'] +print(list_1 + list_2) +#1-1-3、列表增加 +print(list_1 * 2) +#1-1-4、insert 指定位置添加元素 +list_1.insert(4, 'e') +print(list_1) + +#1-2、Retrieve(检索) +#1-2-1切片 +list_3 = list(range(10)) +print(list_3[1:3]) +#1-2-2 index +list_4 = ['a', 'b', 'c'] +list_4.insert(list_4('b'), 'text') +print(list_4) + +#1-3、Update(更新) +#1-3-1索引赋值 +list_4[0] = 'a-1' +print(list_4) +#1-3-2切片赋值 +list_4[0:2] = 'a' +print(list_4) + +#1-4、Delete(删除) +#1-4-1 pop 从末尾删除元素并返回 +list_4.pop() +print(list_4) +#1-4-2 clear 清除列表中所有元素 +list_4.clear() +print(list_4) + + +#2、Tuple(元组) +#2-1、Create 无 + +#2-2、Retrieve +tuple_1 = (1, 2, 3, 4) +#2-2-1索引取值 +print(tuple_1[1]) +#2-2-2index +print(tuple_1.index(2)) +#2-2-3切片 +print(tuple_1[1:2]) + +#2-3、Update 无 + +#2-4、Delete 无 + + +#3、Dict(字典) +#3-1、Create +#3-1-1、键对值赋值 +dict_1 = {} +dict_1['a'] = 1 +dict_1['b'] = 2 +print(dict_1) + +#3-1-2、Update +dict_2 = {'c':3, 'd':4} +print(dict_1.update(dict_2)) + +#3-1-3、setdefault +dict_2.setdefault('e',0) +print(dict_2) + +#3-2、Retrieve +#3-2-1、键对值 +print(dict_2['c']) + +#3-2-2、get +print(dict_2.get('c')) + +#3-2-3、keys() +print(dict_2.keys()) + +#3-2-4、items() +print(dict_2.items()) + +#3-3、Update +#3-3-1、键对值赋值 +dict_2['c'] = 10 +print(dict_2) + +#3-3-2、update +dict_2.update({'c':5, 'f':10}) +print(dict_2) + +#3-4、Delete +#3-4-1、pop +dict_2.pop('f') +print(dict_2) + +#3-4-2、popitem() 相当于随机返回一个item +dict_2.popitem() +print(dict_2) + +#3-4-3、clear() 删除所有 +print(dict_2.clear()) + + +#4、Set(集合) +#4-1、Create +#4-1-1、add +s = set() +s.add('a') +print(s) + +#4-1-2、update +s.update('b') +print(s) + +#4-2、Retrieve +#4-2-1、运算符in +print('a' in s) + +#4-3、Update +#4-3-1、union +s.union({'c', 'd'}) +print(s) + +#4-4、Delete +#4-4-1、remove +s.remove('d') +print(s) + +#4-4-2、discard +s.discard('a') +print(s) + +#4-4-3、pop +s.pop() +print(s) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" index c654c6e038f7c74b4f2472a40e2a2c2d212b4716..32a3f563bcd7fea06f17f13956a433dd81c62957 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\344\272\214\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\345\220\216\344\275\234\344\270\232.py" @@ -1,60 +1,60 @@ -output = open("第二周_第二节.py", "w", encoding="utf-8") -content = """ -# 1、练习字符串的编码和解码 -# 编码(encode):字节序列(bytes)->字符序列(string) -"你好".encode("utf-8") -# 解码(decode): 字符序列(string)->字节序列(bytes) -b = "你好".encode("utf-8") -b.decode("utf-8") - -#2、练习字符串的CRUD -# Create(创建) -a = "one" -b = "_two" -print(a + b) - -a += " two" -print(a) -#Retrieve(检索) -a = "hello, world" -print(a[1]) -print(a.find('e')) -print(a.index('e')) - -f = "2020-12-27-xxxx" -print(f.startswith("2020-12-27") ) - -f = xxxx.jpg -print(f.endswith("jpg")) - -#Update(更新) -#replace(替换) -a = "oolloo" -print( a.replace("l", "o")) -#split(分割) -a="one, two, three" -print(a.split(",")) -#join(拼接) -b = a.split(",") -print(",".join(b)) - -#Delete(删除) -a = "oolloo" -print(a.strip("o")) -print(a.lstrip("o")) -print(a.rstrip("o")) - -#3、练习字符串的格式化 -#按传入参数默认顺序 -a = "ping" -b = "pong" -print("play pingpong: {}, {}".format(a, b)) -#按指定参数索引 -print("play pingpong: {0}, {1}, {0}, {1}".format(a, b)) -#按关键词参数 -print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) -#按变量 -print("f.playing pingpong: {a},{b}") -""" -output.write(content) -output.close() +output = open("第二周_第二节.py", "w", encoding="utf-8") +content = """ +# 1、练习字符串的编码和解码 +# 编码(encode):字节序列(bytes)->字符序列(string) +"你好".encode("utf-8") +# 解码(decode): 字符序列(string)->字节序列(bytes) +b = "你好".encode("utf-8") +b.decode("utf-8") + +#2、练习字符串的CRUD +# Create(创建) +a = "one" +b = "_two" +print(a + b) + +a += " two" +print(a) +#Retrieve(检索) +a = "hello, world" +print(a[1]) +print(a.find('e')) +print(a.index('e')) + +f = "2020-12-27-xxxx" +print(f.startswith("2020-12-27") ) + +f = xxxx.jpg +print(f.endswith("jpg")) + +#Update(更新) +#replace(替换) +a = "oolloo" +print( a.replace("l", "o")) +#split(分割) +a="one, two, three" +print(a.split(",")) +#join(拼接) +b = a.split(",") +print(",".join(b)) + +#Delete(删除) +a = "oolloo" +print(a.strip("o")) +print(a.lstrip("o")) +print(a.rstrip("o")) + +#3、练习字符串的格式化 +#按传入参数默认顺序 +a = "ping" +b = "pong" +print("play pingpong: {}, {}".format(a, b)) +#按指定参数索引 +print("play pingpong: {0}, {1}, {0}, {1}".format(a, b)) +#按关键词参数 +print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) +#按变量 +print("f.playing pingpong: {a},{b}") +""" +output.write(content) +output.close() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" index 3fbe70d20cd0ddae337e09201107f220e399cb34..8406b10a79f435c1084e6c640246885c59280527 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -1,21 +1,21 @@ -#第一题、通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 -import math -import time -import datetime -#datetime.datetime -> str -now = datetime.datetime.now(tz=None) -print(now.strftime("%Y-%m-%d %H:%M:%S")) -#str -> datetime.datetime -print(datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S")) -#datetime.datetime -> timestamp -print(now.timestamp()) -#timestamp -> datetime.datetime -ts = now.timestamp() -print(datetime.datetime.fromtimestamp(ts, tz=None)) - -#第二题、封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-07. -from datetime import timedelta -print(now + timedelta(days=-1)) - - - +#第一题、通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换 +import math +import time +import datetime +#datetime.datetime -> str +now = datetime.datetime.now(tz=None) +print(now.strftime("%Y-%m-%d %H:%M:%S")) +#str -> datetime.datetime +print(datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S")) +#datetime.datetime -> timestamp +print(now.timestamp()) +#timestamp -> datetime.datetime +ts = now.timestamp() +print(datetime.datetime.fromtimestamp(ts, tz=None)) + +#第二题、封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-07. +from datetime import timedelta +print(now + timedelta(days=-1)) + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" index 5493d8e6ca28744b815d99cfa29cc3d8d174fc04..08a726e8496e569960083a5142e7ee2be7abf052 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -1,71 +1,71 @@ -#第一题、将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. -class ParamsError(object): - pass - - -class MyMath: - - @staticmethod - def add(a, b): - return a + b - - @staticmethod - def sub(a, b): - return a - b - - @staticmethod - def mul(a, b): - return a * b - - @staticmethod - def div(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("除法中,分母不能为0") - finally: - print('div None') - - @staticmethod - def remainder(a, b): - return a ** b - - @staticmethod - def sqare(a, b): - return a ** b - -print(MyMath.add(1, 2)) -print(MyMath.sub(4, 2)) -print(MyMath.mul(1, 2)) -print(MyMath.div(4, 2)) -print(MyMath.remainder(2, 4)) -print(MyMath.sqare(4, 1/2)) - -#第二题、为上节课自定义类添加以下功能: -#添加类属性 -#添加类私有属性 -#添加类方法或者类的私有属性 -#在__init__方法中初始化实例属性 -#在__init__方法中绑定私有实例属性 -#在自定义类中实现__str__, 自定义输出格式 - -class Cup: - GlassCup = True - __price = {"mate": 200} - def __init__(self, materail, price): - - self. materail = materail - self. __price = price - - @classmethod - def __new__(cls, *args, **kwargs): - print("杯子很好用") - return super().__new__(cls) - - def __str__(self): - return "杯子材质是%s , 价格是%d元" % (self. materail, self. __price) - - -print(Cup. _Cup__price) -A_Cup = Cup("玻璃", 200) +#第一题、将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别. +class ParamsError(object): + pass + + +class MyMath: + + @staticmethod + def add(a, b): + return a + b + + @staticmethod + def sub(a, b): + return a - b + + @staticmethod + def mul(a, b): + return a * b + + @staticmethod + def div(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("除法中,分母不能为0") + finally: + print('div None') + + @staticmethod + def remainder(a, b): + return a ** b + + @staticmethod + def sqare(a, b): + return a ** b + +print(MyMath.add(1, 2)) +print(MyMath.sub(4, 2)) +print(MyMath.mul(1, 2)) +print(MyMath.div(4, 2)) +print(MyMath.remainder(2, 4)) +print(MyMath.sqare(4, 1/2)) + +#第二题、为上节课自定义类添加以下功能: +#添加类属性 +#添加类私有属性 +#添加类方法或者类的私有属性 +#在__init__方法中初始化实例属性 +#在__init__方法中绑定私有实例属性 +#在自定义类中实现__str__, 自定义输出格式 + +class Cup: + GlassCup = True + __price = {"mate": 200} + def __init__(self, materail, price): + + self. materail = materail + self. __price = price + + @classmethod + def __new__(cls, *args, **kwargs): + print("杯子很好用") + return super().__new__(cls) + + def __str__(self): + return "杯子材质是%s , 价格是%d元" % (self. materail, self. __price) + + +print(Cup. _Cup__price) +A_Cup = Cup("玻璃", 200) print(A_Cup) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" index 5176caa0d59d459e5e2da09c13007ef394f5d54b..309fcd214eac8b98c639742af4e685561035d6bb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_Leo_\345\256\227\350\277\234/\347\254\254\345\233\233\345\221\250_\344\275\234\344\270\232\346\217\220\344\272\244/\347\254\254\345\233\233\345\221\250_\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -1,58 +1,58 @@ -# 第一题、用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 -class ParamsError(object): - pass - - -class MyMath: - def add(self, a, b): - return a + b - - def sub(self, a, b): - return a - b - - def mul(self, a, b): - return a * b - - def div(self, a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("除法中,分母不能为0") - finally: - print('div None') - - def remainder(self, a, b): - return a ** b - - def sqare(self, a, b): - return a ** b - -math = MyMath() -print(math.add(1, 2)) -print(math.sub(4, 2)) -print(math.mul(1, 2)) -print(math.div(4, 2)) -print(math.remainder(2, 4)) -print(math.sqare(4, 1/2)) - -# 第二题、自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 -class Cup(object): - subject = 'cup' - - def __init__(self, obj): - self.obj = obj - -# 第三题、创建多个继承作业2父类的子类 -class GlassCup(Cup): - materail = 'glass' - - -class PlasticCup(Cup): - materail = 'plastic' - - -A_Cup = GlassCup("玻璃杯") -B_Cup = PlasticCup("塑料杯") -print(A_Cup.materail) -print(B_Cup.materail) - +# 第一题、用类封装一个MyMath类, 实现加, 减, 乘, 除, 幂, 开方 +class ParamsError(object): + pass + + +class MyMath: + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b + + def mul(self, a, b): + return a * b + + def div(self, a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("除法中,分母不能为0") + finally: + print('div None') + + def remainder(self, a, b): + return a ** b + + def sqare(self, a, b): + return a ** b + +math = MyMath() +print(math.add(1, 2)) +print(math.sub(4, 2)) +print(math.mul(1, 2)) +print(math.div(4, 2)) +print(math.remainder(2, 4)) +print(math.sqare(4, 1/2)) + +# 第二题、自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 +class Cup(object): + subject = 'cup' + + def __init__(self, obj): + self.obj = obj + +# 第三题、创建多个继承作业2父类的子类 +class GlassCup(Cup): + materail = 'glass' + + +class PlasticCup(Cup): + materail = 'plastic' + + +A_Cup = GlassCup("玻璃杯") +B_Cup = PlasticCup("塑料杯") +print(A_Cup.materail) +print(B_Cup.materail) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-01.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-01.py" index c073f4afb0ba95a4ec445040159ef032773724ba..625fa2a250aa5c316a529887f6772bbdc2ad36fb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-01.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-01.py" @@ -1,135 +1,135 @@ -# !!!!!!!!!!!!!!001!!!!!!!!! -# a=100 -# if a>100: -# print("a>100") -# elif (a==50): -# print("a==50") -# else: -# print(a) -# e=101 -# # for循环 -# l=[1a,2b,3,4,5,6] -# for i in l: -# print(i) -# print(f"final e:{e}") #final e:101 - -# l=['1a','2b',3,4,5,6] -# for inde,valu in enumerate(l): #enumerate列举、枚举 -# print(f"index:{inde},value:{valu}") -# # 输出见下: -# # index:0,value:1a -# # index:1,value:2b -# # index:2,value:3 -# # index:3,value:4 -# # index:4,value:5 -# # index:5,value:6 - -# !!!!!!!!!!!!!!002!!!!!!!!! -# count=0 -# while count<18: -# print(f"sim statement:{count}") -# count+=1 - -# count=0 -# x=12 -# while True:#死循环 -# if count>x: -# break -# print(f"sim statement:{count}") -# count+=1 -# l=[1,2,3,4,5,6,7] -# for i in l: -# print(f"search element:{i}") -# if i==3: -# break -# !!!!!!!!!!!!!!003!!!!!!!!! -# l=[1,2,3,4,5] -# for i in l: -# if i==3: #遇到3就跳过; -# continue -# else: -# print(f"search element;{i}") -# print("for循环的最后一句",i,"-----") -# search element;1 -# for循环的最后一句 1 ----- -# search element;2 -# for循环的最后一句 2 ----- -# search element;4 -# for循环的最后一句 4 ----- -# search element;5 -# for循环的最后一句 5 ----- - -# l=[1,2,3,4,5] -# for i in l: -# if i==3: #遇到3就跳过;if外,for里面的还是要执行的 -# pass -# else: -# print(f"search element;{i}") -# print("for循环的最后一句",i,"------------") -# search element;1 -# for循环的最后一句 1 ------------ -# search element;2 -# for循环的最后一句 2 ------------ -# for循环的最后一句 3 ------------ -# search element;4 -# for循环的最后一句 4 ------------ -# search element;5 -# for循环的最后一句 5 ------------ -# !!!!!!!!!!!!!!004!!!!!!!!! -# 异常 -# def my_sub(a,b): -# return a/b -# print(my_sub(1,0)) -# def my_sub(a,b): -# try: -# return a/b -# except Exception as e: -# # print(e) -# print("分母不能为0") -# return None -# finally: -# print("my_sub,end") -# # f.close() -# print(my_sub(2,0)) - -# 常见异常 -# l=[1,2] -# l[2] -# Traceback (most recent call last): -# File "", line 1, in -# IndexError: list index out of range -# !!!!!!!!!!!!!!005!!!!!!!!! -# def my_sub(a, b): -# try: -# return a / b -# except ZeroDivisionError: -# print("分母不可为0") -# raise Exception("params error")#继续抛出错误;参数错误; -# finally: -# print("function my_sub end") -# -# my_sub(1,0) - -# zidignyi自定义 -class ParamsError(Exception): - pass - - -def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function my_sub end") - -print(my_sub(1,2)) -print(my_sub(1,0)) - - - - - - - - +# !!!!!!!!!!!!!!001!!!!!!!!! +# a=100 +# if a>100: +# print("a>100") +# elif (a==50): +# print("a==50") +# else: +# print(a) +# e=101 +# # for循环 +# l=[1a,2b,3,4,5,6] +# for i in l: +# print(i) +# print(f"final e:{e}") #final e:101 + +# l=['1a','2b',3,4,5,6] +# for inde,valu in enumerate(l): #enumerate列举、枚举 +# print(f"index:{inde},value:{valu}") +# # 输出见下: +# # index:0,value:1a +# # index:1,value:2b +# # index:2,value:3 +# # index:3,value:4 +# # index:4,value:5 +# # index:5,value:6 + +# !!!!!!!!!!!!!!002!!!!!!!!! +# count=0 +# while count<18: +# print(f"sim statement:{count}") +# count+=1 + +# count=0 +# x=12 +# while True:#死循环 +# if count>x: +# break +# print(f"sim statement:{count}") +# count+=1 +# l=[1,2,3,4,5,6,7] +# for i in l: +# print(f"search element:{i}") +# if i==3: +# break +# !!!!!!!!!!!!!!003!!!!!!!!! +# l=[1,2,3,4,5] +# for i in l: +# if i==3: #遇到3就跳过; +# continue +# else: +# print(f"search element;{i}") +# print("for循环的最后一句",i,"-----") +# search element;1 +# for循环的最后一句 1 ----- +# search element;2 +# for循环的最后一句 2 ----- +# search element;4 +# for循环的最后一句 4 ----- +# search element;5 +# for循环的最后一句 5 ----- + +# l=[1,2,3,4,5] +# for i in l: +# if i==3: #遇到3就跳过;if外,for里面的还是要执行的 +# pass +# else: +# print(f"search element;{i}") +# print("for循环的最后一句",i,"------------") +# search element;1 +# for循环的最后一句 1 ------------ +# search element;2 +# for循环的最后一句 2 ------------ +# for循环的最后一句 3 ------------ +# search element;4 +# for循环的最后一句 4 ------------ +# search element;5 +# for循环的最后一句 5 ------------ +# !!!!!!!!!!!!!!004!!!!!!!!! +# 异常 +# def my_sub(a,b): +# return a/b +# print(my_sub(1,0)) +# def my_sub(a,b): +# try: +# return a/b +# except Exception as e: +# # print(e) +# print("分母不能为0") +# return None +# finally: +# print("my_sub,end") +# # f.close() +# print(my_sub(2,0)) + +# 常见异常 +# l=[1,2] +# l[2] +# Traceback (most recent call last): +# File "", line 1, in +# IndexError: list index out of range +# !!!!!!!!!!!!!!005!!!!!!!!! +# def my_sub(a, b): +# try: +# return a / b +# except ZeroDivisionError: +# print("分母不可为0") +# raise Exception("params error")#继续抛出错误;参数错误; +# finally: +# print("function my_sub end") +# +# my_sub(1,0) + +# zidignyi自定义 +class ParamsError(Exception): + pass + + +def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function my_sub end") + +print(my_sub(1,2)) +print(my_sub(1,0)) + + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-02.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-02.py" index dbd4b66dcb3e7779cd32fa6bf163118a62c41c68..609dc6244c91171980f3c40c1972f0943fb28ef1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-02.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\344\272\221/\347\254\2543\345\221\2501228-0103/3-1-\344\275\234\344\270\232/3-1-02.py" @@ -1,22 +1,22 @@ -# 作业1 -# 用for循环和while来完成简单的计数 - -# n以内的数列: 7 -# 请输入n: -# 0 1 2 3 4 5 6 None - -# def print_n(n): -# for i in range(n): -# print(i,end=' ') - -def print_n(n): - i=0 - while i 100: - print("a 超过阈值") -elif a == 50: - print("a 只有阈值的一半") -else: - print("a 小于阈值") - -``` - -## 循环语句for - -遍历一个可迭代对象(如list) - -```python -l = [1, 2, 3, 4, 5, 6] -e = 0 - - -for e in l: - print(e) - -print(f"final e value: {e}") -``` - -## 获取索引值和值 - -```python -l=['1a','2b',3,4,5,6] -for inde,valu in enumerate(l): #enumerate列举、枚举 - print(f"index:{inde},value:{valu}") -# 输出见下: -# index:0,value:1a -# index:1,value:2b -# index:2,value:3 -# index:3,value:4 -# index:4,value:5 -# index:5,value:6 - -``` - -## `while`循环 - -要有逻辑判断语句,来退出`while`循环 - -```python -while 判断语句: - 表达式 - -while True: - 判断语句 - 表达式 - -# count=0 -# while count<18: -# print(f"sim statement:{count}") -# count+=1 -count=0 -while True:#死循环 - print(f"sim statement:{count}") - count+=1 - -# count=0 -# x=12 -# while True:#死循环 -# if count>x: -# break -# print(f"sim statement:{count}") -# count+=1 - -l=[1,24,3,4,5,6,7] -for i in l: - if i==3: #遇到3就跳过; - continue - else: - print(f"search element;{i}") - -``` - -## 跳出循环 - -- `break` - - 停止当前循环; - -- `continue` - - 跳过当前的执行逻辑, 立即执行下一个循环语句单元; - -- `pass` - - z只是跳过当前条件判断中的执行语句, 后续语句继续执行; - -```python -continue与 pass -# l=[1,2,3,4,5] -# for i in l: -# if i==3: #遇到3就跳过;立即开始下一个循环体; -# continue -# else: -# print(f"search element;{i}") -# print("for循环的最后一句",i,"-----") -# search element;1 -# for循环的最后一句 1 ----- -# search element;2 -# for循环的最后一句 2 ----- -# search element;4 -# for循环的最后一句 4 ----- -# search element;5 -# for循环的最后一句 5 ----- - - -l=[1,2,3,4,5] -for i in l: - if i==3: #遇到3就跳过;if外,for里面的还是要执行的 - pass - else: - print(f"search element;{i}") - print("for循环的最后一句",i,"------------") -# search element;1 -# for循环的最后一句 1 ------------ -# search element;2 -# for循环的最后一句 2 ------------ -# for循环的最后一句 3 ------------#遇到3就跳过;if外,for里面的还是要执行的 -# search element;4 -# for循环的最后一句 4 ------------ -# search element;5 -# for循环的最后一句 5 ------------ -``` - - - -# python的异常处理 - -- 异常 - - 程序遇到严重错误时, 会终止程序的运行并抛出异常 - - ```python - def my_sub(a, b): - return a / b - - my_sub(1, 0) - ZeroDivisionError: division by zero - - ``` - - - -- 捕获异常 - - ```python - try: - 表达式 - except [Exception] as e: - 表达式 #捕获异常,进行适当的输出提示信息; - finnaly: - 表达式 #没有异常,会执行这里; - - - - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - # print(e) - print("分母不可为0") - return None - finally: - print("function my_sub end") #不管怎么样,这里都会执行; - # f.close() - - my_sub(1, 0) - ``` - - - Exception - - 所有异常的基类, 所有的异常都是Exception的子类;ZeroDivisionError就是一个字类; - - - 处理异常颗粒度要细一点, 尽量不要捕获基类Exception, 尤其是数据处理的时候.爬虫;污染数据; - - - 常见的异常 - - - IndexError 索引值超过了列表长度 - - ```python - >>> l = [1] - >>> l[2] - Traceback (most recent call last): - File "", line 1, in - IndexError: list index out of range - ``` - - - KeyError找不到Key - - ```python - >>> d = {"a": 1} - >>> d["b"] - Traceback (most recent call last): - File "", line 1, in - KeyError: 'b' - ``` - - - ValueError传入的参数错误 - - ```python - >>> int('a1') #a1不是int类型; - Traceback (most recent call last): - File "", line 1, in - ValueError: invalid literal for int() with base 10: 'a1' - ``` - - - - - TypeError 类型错误, 常见于运算;两个不同类型的对象进行运算; - - ```python - >>> 1 + '2' - Traceback (most recent call last): - File "", line 1, in - TypeError: unsupported operand type(s) for +: 'int' and 'str' - ``` - - - - - SyntaxError 语法报错, 检查自己的语法有没有写错;关键字输入的错误等; - - - IndentationError 缩进错误 - - - 混用tab和space(空格) - - 缩进长度不对 - -- 如何处理异常 - - - 处理 - - - 抛出新异常 - - ```python - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - print("分母不可为0") - raise Exception("params error")#继续抛出错误;参数错误; - finally: - print("function my_sub end") - ``` - - - 重新抛出 - - ```python - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - print("分母不可为0") - raise ZeroDivisionError - finally: - print("function my_sub end") - ``` - - - 忽略(不推荐) - - `pass` - - 用来指示当前处理语句没有正式写完, 尽量不要忽略异常, 否则代码的健壮度会很差, 造成不可预知的bug. - -- 自定义异常,py中没有这个异常,自己需要定义一个异常; - - ```python - class ParamsError(Exception): - pass - - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function my_sub end") - ``` - - - -# 课后作业 - -- 用for循环和while来完成简单的计数 - -- 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 - - - 斐波那契函数 - - 第N项是N-1, N-2的和 - - ```python - F(n)=F(n - 1)+F(n - 2) - - [0, 1, 1, 2, 3, 5, 8, 13, 21....] - ``` - -- 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常`ParamsError` - - - - - +# 第3周_第1节(1229)26min + +# 1 python的流程控制语句 + +![image-20201229213252284](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20201229213252284.png) + +```python +n%400 是:闰年 +n%4 否;n%100,是,平年; +n%4 否;n%100,否;n%4,是;闰年; +n%4 否;n%100,否;n%4,否;平年; + +1896年为闰年,四年之后的1900年并不是闰年,直到再过四年之后的1904年才是闰年。 +一般情况下年份能被4整除即为闰年,而整百年的年份要被400整除才为闰年。 + + +公元年份除以100可整除但除以400不可整除,为平年。 +公元年份除以400可整除但除以3200不可整除,为闰年。 公元年份除以3200可整除,为平年。 + +公元年份除以4不可整除,为平年。 +公元年份除以4可整除但除以100不可整除,为闰年。 +公元年份除以100可整除但除以400不可整除,为平年。 +公元年份除以400可整除但除以3200不可整除,为闰年。 +公元年份除以3200可整除,为平年。 + +2004年是闰年 +2000年是闰年 +1900年不是闰年 + + +闰年的产生原理很简单,如果地球绕太阳一周如果恰好就是365天,那就不需要闰年这种东西了。 + +``` + +## 条件判断语句 + +```python +if +elif +else +最后只会走其中一条; + +a = 50 +if a > 100: + print("a 超过阈值") +elif a == 50: + print("a 只有阈值的一半") +else: + print("a 小于阈值") + +``` + +## 循环语句for + +遍历一个可迭代对象(如list) + +```python +l = [1, 2, 3, 4, 5, 6] +e = 0 + + +for e in l: + print(e) + +print(f"final e value: {e}") +``` + +## 获取索引值和值 + +```python +l=['1a','2b',3,4,5,6] +for inde,valu in enumerate(l): #enumerate列举、枚举 + print(f"index:{inde},value:{valu}") +# 输出见下: +# index:0,value:1a +# index:1,value:2b +# index:2,value:3 +# index:3,value:4 +# index:4,value:5 +# index:5,value:6 + +``` + +## `while`循环 + +要有逻辑判断语句,来退出`while`循环 + +```python +while 判断语句: + 表达式 + +while True: + 判断语句 + 表达式 + +# count=0 +# while count<18: +# print(f"sim statement:{count}") +# count+=1 +count=0 +while True:#死循环 + print(f"sim statement:{count}") + count+=1 + +# count=0 +# x=12 +# while True:#死循环 +# if count>x: +# break +# print(f"sim statement:{count}") +# count+=1 + +l=[1,24,3,4,5,6,7] +for i in l: + if i==3: #遇到3就跳过; + continue + else: + print(f"search element;{i}") + +``` + +## 跳出循环 + +- `break` + + 停止当前循环; + +- `continue` + + 跳过当前的执行逻辑, 立即执行下一个循环语句单元; + +- `pass` + + z只是跳过当前条件判断中的执行语句, 后续语句继续执行; + +```python +continue与 pass +# l=[1,2,3,4,5] +# for i in l: +# if i==3: #遇到3就跳过;立即开始下一个循环体; +# continue +# else: +# print(f"search element;{i}") +# print("for循环的最后一句",i,"-----") +# search element;1 +# for循环的最后一句 1 ----- +# search element;2 +# for循环的最后一句 2 ----- +# search element;4 +# for循环的最后一句 4 ----- +# search element;5 +# for循环的最后一句 5 ----- + + +l=[1,2,3,4,5] +for i in l: + if i==3: #遇到3就跳过;if外,for里面的还是要执行的 + pass + else: + print(f"search element;{i}") + print("for循环的最后一句",i,"------------") +# search element;1 +# for循环的最后一句 1 ------------ +# search element;2 +# for循环的最后一句 2 ------------ +# for循环的最后一句 3 ------------#遇到3就跳过;if外,for里面的还是要执行的 +# search element;4 +# for循环的最后一句 4 ------------ +# search element;5 +# for循环的最后一句 5 ------------ +``` + + + +# python的异常处理 + +- 异常 + + 程序遇到严重错误时, 会终止程序的运行并抛出异常 + + ```python + def my_sub(a, b): + return a / b + + my_sub(1, 0) + ZeroDivisionError: division by zero + + ``` + + + +- 捕获异常 + + ```python + try: + 表达式 + except [Exception] as e: + 表达式 #捕获异常,进行适当的输出提示信息; + finnaly: + 表达式 #没有异常,会执行这里; + + + + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + # print(e) + print("分母不可为0") + return None + finally: + print("function my_sub end") #不管怎么样,这里都会执行; + # f.close() + + my_sub(1, 0) + ``` + + - Exception + + 所有异常的基类, 所有的异常都是Exception的子类;ZeroDivisionError就是一个字类; + + - 处理异常颗粒度要细一点, 尽量不要捕获基类Exception, 尤其是数据处理的时候.爬虫;污染数据; + + - 常见的异常 + + - IndexError 索引值超过了列表长度 + + ```python + >>> l = [1] + >>> l[2] + Traceback (most recent call last): + File "", line 1, in + IndexError: list index out of range + ``` + + - KeyError找不到Key + + ```python + >>> d = {"a": 1} + >>> d["b"] + Traceback (most recent call last): + File "", line 1, in + KeyError: 'b' + ``` + + - ValueError传入的参数错误 + + ```python + >>> int('a1') #a1不是int类型; + Traceback (most recent call last): + File "", line 1, in + ValueError: invalid literal for int() with base 10: 'a1' + ``` + + + + - TypeError 类型错误, 常见于运算;两个不同类型的对象进行运算; + + ```python + >>> 1 + '2' + Traceback (most recent call last): + File "", line 1, in + TypeError: unsupported operand type(s) for +: 'int' and 'str' + ``` + + + + - SyntaxError 语法报错, 检查自己的语法有没有写错;关键字输入的错误等; + + - IndentationError 缩进错误 + + - 混用tab和space(空格) + - 缩进长度不对 + +- 如何处理异常 + + - 处理 + + - 抛出新异常 + + ```python + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + print("分母不可为0") + raise Exception("params error")#继续抛出错误;参数错误; + finally: + print("function my_sub end") + ``` + + - 重新抛出 + + ```python + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + print("分母不可为0") + raise ZeroDivisionError + finally: + print("function my_sub end") + ``` + + - 忽略(不推荐) + + `pass` + + 用来指示当前处理语句没有正式写完, 尽量不要忽略异常, 否则代码的健壮度会很差, 造成不可预知的bug. + +- 自定义异常,py中没有这个异常,自己需要定义一个异常; + + ```python + class ParamsError(Exception): + pass + + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function my_sub end") + ``` + + + +# 课后作业 + +- 用for循环和while来完成简单的计数 + +- 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 + + - 斐波那契函数 + + 第N项是N-1, N-2的和 + + ```python + F(n)=F(n - 1)+F(n - 2) + + [0, 1, 1, 2, 3, 5, 8, 13, 21....] + ``` + +- 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常`ParamsError` + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\346\254\241_\344\275\234\344\270\232.12.15/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202 \347\254\224\350\256\260 20201215 LQ.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\346\254\241_\344\275\234\344\270\232.12.15/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202 \347\254\224\350\256\260 20201215 LQ.md" index 3a6b1d85430b85eebd460eb98b9cec17e4a51e2e..e0f741c1bac46bf645b38921b3e51f678712e5b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\346\254\241_\344\275\234\344\270\232.12.15/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202 \347\254\224\350\256\260 20201215 LQ.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\346\254\241_\344\275\234\344\270\232.12.15/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\200\350\212\202 \347\254\224\350\256\260 20201215 LQ.md" @@ -1,107 +1,107 @@ -# 第一周 第一节 笔记 20201215 LQ - -## 学习习惯 - -- 做好笔记,文档管理 Typora - -- Typora - -- 创建标题 **Ctrl + 数字** - -- 创建目录列表结构 **- + 空格** - -- 创建代码块 - - ``` - ** Ctrl + Shift + K ** - ``` - -- 科学搜索 - - - -官方文档和***Github*** **Python 3.6.5, Documentation ** - - ``` - https://www.python.org/doc/ - https://circleci.com/integrations/github/?utm_source=gnb&utm_medium=SEM&utm_campaign=SEM-gnb-Github-Eng-ni&utm_content=SEM-gnb-Github-Eng-ni-Github&gclid=Cj0KCQiA2uH-BRCCARIsAEeef3k-8YmMqAsSMCVeW5RktCF8PzTiJcSrXHGxdszHagX_yj3jYaILwpwaAryyEALw_wcB - ``` - - - Stackoverflow (**error描述,排错**) - - ``` - https://stackoverflow.com/ - ``` - - - 简书 知乎 - - - 谷歌 - -- 良好的学习心态 - - - **面向需求** - - 有效率的学习 - - 自己求索+及时询问 - - 社群讨论 - -## 编程语言的基本概述 - -- What's programing language? - - - human & computer -- communication - -- Code **procedure** - - - Code--机器码--Computer--执行 - - 把代码翻译为机器码的翻译就是编译器,在python中也可以叫python解释器 - - 编程语言python是我们与解释器之间的翻译 - - 解释器是python与计算机之间的翻译 - -- 编程语言分类 - - - C - - C ++ - - Java - - Python - - JavaScript - - 编译型语言 解释性语言 和混合型语言 - - 动态语言和静态语言 - - 编译时不知道变量类型的叫做**动态语言**,编译时知道变量类型的叫做**静态语言** - - 动态语言 (Python, Javascript) - - 静态语言 (C, C++, Java) - - 强类型语言和弱类型语言 - - 在使用变量时,不会自动改变变量类型称为强类型;(**Python, Java, C, C++**) - - 在使用变量,会隐式帮你改变变量类型称为弱类型语言。(**Javascript**) - - ## Python环境搭建 - -- Python 下载 ( ver 3.6.5, 不要奇数版本,多测试用) - -- Python 安装 - - - 要牢记安装目录 - - 环境变量 - - 用户变量 - -- IDE 集成开发环境 - - - Pycharm - -- IDE安装 - - ## 运行第一个python程序 - -- pycharm 新建项目 - -- 运行第一个程序 - - - 编辑模式 编码器中写好代码再运行 - - 交互模式 会立刻打印当前对象的值 - -- Errors - - - 无法运行 找不到python **pycharm 和python 匹配** - - 缩进问题 **建议使用Tab缩进** - -## 课后作业 - -- Python环境搭建 +# 第一周 第一节 笔记 20201215 LQ + +## 学习习惯 + +- 做好笔记,文档管理 Typora + +- Typora + +- 创建标题 **Ctrl + 数字** + +- 创建目录列表结构 **- + 空格** + +- 创建代码块 + + ``` + ** Ctrl + Shift + K ** + ``` + +- 科学搜索 + + - -官方文档和***Github*** **Python 3.6.5, Documentation ** + + ``` + https://www.python.org/doc/ + https://circleci.com/integrations/github/?utm_source=gnb&utm_medium=SEM&utm_campaign=SEM-gnb-Github-Eng-ni&utm_content=SEM-gnb-Github-Eng-ni-Github&gclid=Cj0KCQiA2uH-BRCCARIsAEeef3k-8YmMqAsSMCVeW5RktCF8PzTiJcSrXHGxdszHagX_yj3jYaILwpwaAryyEALw_wcB + ``` + + - Stackoverflow (**error描述,排错**) + + ``` + https://stackoverflow.com/ + ``` + + - 简书 知乎 + + - 谷歌 + +- 良好的学习心态 + + - **面向需求** + - 有效率的学习 + - 自己求索+及时询问 + - 社群讨论 + +## 编程语言的基本概述 + +- What's programing language? + + - human & computer -- communication + +- Code **procedure** + + - Code--机器码--Computer--执行 + - 把代码翻译为机器码的翻译就是编译器,在python中也可以叫python解释器 + - 编程语言python是我们与解释器之间的翻译 + - 解释器是python与计算机之间的翻译 + +- 编程语言分类 + + - C + - C ++ + - Java + - Python + - JavaScript + - 编译型语言 解释性语言 和混合型语言 + - 动态语言和静态语言 + - 编译时不知道变量类型的叫做**动态语言**,编译时知道变量类型的叫做**静态语言** + - 动态语言 (Python, Javascript) + - 静态语言 (C, C++, Java) + - 强类型语言和弱类型语言 + - 在使用变量时,不会自动改变变量类型称为强类型;(**Python, Java, C, C++**) + - 在使用变量,会隐式帮你改变变量类型称为弱类型语言。(**Javascript**) + + ## Python环境搭建 + +- Python 下载 ( ver 3.6.5, 不要奇数版本,多测试用) + +- Python 安装 + + - 要牢记安装目录 + - 环境变量 + - 用户变量 + +- IDE 集成开发环境 + + - Pycharm + +- IDE安装 + + ## 运行第一个python程序 + +- pycharm 新建项目 + +- 运行第一个程序 + + - 编辑模式 编码器中写好代码再运行 + - 交互模式 会立刻打印当前对象的值 + +- Errors + + - 无法运行 找不到python **pycharm 和python 匹配** + - 缩进问题 **建议使用Tab缩进** + +## 课后作业 + +- Python环境搭建 - 练习添加环境变量 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\346\254\241_\344\275\234\344\270\232.12.19/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201219.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\346\254\241_\344\275\234\344\270\232.12.19/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201219.md" index b121aeed176db3bc9cf8a6cba0fa952b9633b112..07cdaeb137aeacdd6f8df9517d696fb5da28efb8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\346\254\241_\344\275\234\344\270\232.12.19/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201219.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\346\254\241_\344\275\234\344\270\232.12.19/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201219.md" @@ -1,232 +1,232 @@ -# 第一周-第三节-随堂笔记 20201219 - -## 变量和赋值 - -- 什么是变量? - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可变化,可重新赋值 - - - 为变量赋值 - - - 通过 = 来赋值 - - ``` - x = 3 - ``` - - - 被重新赋值之后的值去哪了? - - - 被系统回收了 - - - Python的常量 - - - Python没有常量这个数据类型 - - 程序员之间约定,如果这个变量的命名都是大写字母,就将被视为一个常量 - -## Python的六大基本类型 - -强调**基本类型** 的原因是数据类型和数据结构指向的范围更加广泛,不要产生错误的认识或者思维定式 - -- 通过type()函数来查看当前变量的数据类型 - -- Int(整数) - - ``` - int() #转为整数数据类型 - ``` - -- float (浮点数) - - ``` - float() #转为浮点数数据类型 - ``` - - - 计算机内部只能识别0或1,浮点数强调的是小数的表现形式 - -- string (字符串,字符序列) - - ``` - str() #转为字符串数据类型 - ``` - - - 在有些语言中,单个字符也是一个基本的数据类型 (Char) - - - 有序的 - - - 如何表示字符串? - - ``` - " " - '' - '''' - """" - ``` - - - 转义字符 - - 告诉python解释器,我们当前要表示的是一个字符或者是特殊字符 - - - 通过 \ 来转义 - - \n 换行 - - - boolean (布尔值) - - 用来表示 True 或者 False - - - True 等价于1 - - - Flase 等价于0 - - ``` - bool(2) ---True - bool(0) ---False - ``` - - - bytes (二进制系列) - - 二进制的表示形式 - - - None (空) - - - 有了False和0 为啥还需要None - - 因为False和0有时也代表了一种结果 - -## Python的四大基本数据结构 - -- list(列表) - - - 什么是列表? - - 用来转载**不同数据类型**的数据结构 - - - 列表的特点 - - - 有序 - - 可以转载任意数据类型 - - 可更改 - - - 如何表示list? - - - 通过list() 新建一个列表 - - ``` - list("hello world") - ``` - - - 通过[ ] 声明一个列表 - - ``` - a = [1,2,3] - ``` - -- tuple(元祖) - - - 什么是元祖? - - 可以认为,元祖是不可修改的列表,常用来表示记录 - - - 元祖的特点? - - - 有序 - - 可以转载任意的数据类型 - - 不可更改 - - - 如何表示tuple - - - 通过tuple() 新建一个元祖 - - ``` - tuple("hello") - ``` - - - 通过(,)来声明一个元祖 - - ``` - a = (1,2,3) - - #声明单个元素的元祖,要添加逗号 - a = (1, ) - ``` - -- dict(字典) - - - 什么是字典? - - 字典也叫 hashtable, 通过hash(散列函数)将传入的key值生成地址来查找value - - key -> hash 函数 ->返回了value的地址 ->通过地址返回value值 - - - 字典的特点? - - **无序** - - Python3.6 是有序的,无视这一点 - - - 字典中的key必须是可hash(不可更改,唯一的) - - ???可更改??? - - - 如何表示字典? - - - 通过dict() 来创建字典 - - ``` - dict(a=2) - ``` - - - 通过{ } 来声明一个字典 - - ``` - a = {"a": 2} - ``` - -- set(集合) - - - 什么是Set - - set其实就是没有value的字典 - - - Set (集合) 的特点 - - - 无序的 - - 集合中的Key 必须是可hash的 - - 可以更改 - - 元素是唯一的 - - - 如何表示Set - - - 通过set()来创建集合 - - ``` - set([1,2,2]) - ``` - - - 通过{ } 来表示 - - ``` - {1,2,3} - ``` - -## 课后作业 - -- 四大基本数据结构中哪些是可变的,哪些是不可变的? - - **可变的数据结构:list(列表),dict(字典),set(集合)** - - **不可变的数据结构:tuple (元祖)** - -- 四大基本数据结构中哪些是有序,哪些是无序的? - - **有序的数据结构:list(列表),tuple (元祖)** - - **无序的数据结构:dict(字典),set(集合)** - +# 第一周-第三节-随堂笔记 20201219 + +## 变量和赋值 + +- 什么是变量? + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可变化,可重新赋值 + + - 为变量赋值 + + - 通过 = 来赋值 + + ``` + x = 3 + ``` + + - 被重新赋值之后的值去哪了? + + - 被系统回收了 + + - Python的常量 + + - Python没有常量这个数据类型 + - 程序员之间约定,如果这个变量的命名都是大写字母,就将被视为一个常量 + +## Python的六大基本类型 + +强调**基本类型** 的原因是数据类型和数据结构指向的范围更加广泛,不要产生错误的认识或者思维定式 + +- 通过type()函数来查看当前变量的数据类型 + +- Int(整数) + + ``` + int() #转为整数数据类型 + ``` + +- float (浮点数) + + ``` + float() #转为浮点数数据类型 + ``` + + - 计算机内部只能识别0或1,浮点数强调的是小数的表现形式 + +- string (字符串,字符序列) + + ``` + str() #转为字符串数据类型 + ``` + + - 在有些语言中,单个字符也是一个基本的数据类型 (Char) + + - 有序的 + + - 如何表示字符串? + + ``` + " " + '' + '''' + """" + ``` + + - 转义字符 + + 告诉python解释器,我们当前要表示的是一个字符或者是特殊字符 + + - 通过 \ 来转义 + - \n 换行 + + - boolean (布尔值) + + 用来表示 True 或者 False + + - True 等价于1 + + - Flase 等价于0 + + ``` + bool(2) ---True + bool(0) ---False + ``` + + - bytes (二进制系列) + + 二进制的表示形式 + + - None (空) + + - 有了False和0 为啥还需要None + + 因为False和0有时也代表了一种结果 + +## Python的四大基本数据结构 + +- list(列表) + + - 什么是列表? + + 用来转载**不同数据类型**的数据结构 + + - 列表的特点 + + - 有序 + - 可以转载任意数据类型 + - 可更改 + + - 如何表示list? + + - 通过list() 新建一个列表 + + ``` + list("hello world") + ``` + + - 通过[ ] 声明一个列表 + + ``` + a = [1,2,3] + ``` + +- tuple(元祖) + + - 什么是元祖? + + 可以认为,元祖是不可修改的列表,常用来表示记录 + + - 元祖的特点? + + - 有序 + - 可以转载任意的数据类型 + - 不可更改 + + - 如何表示tuple + + - 通过tuple() 新建一个元祖 + + ``` + tuple("hello") + ``` + + - 通过(,)来声明一个元祖 + + ``` + a = (1,2,3) + + #声明单个元素的元祖,要添加逗号 + a = (1, ) + ``` + +- dict(字典) + + - 什么是字典? + + 字典也叫 hashtable, 通过hash(散列函数)将传入的key值生成地址来查找value + + key -> hash 函数 ->返回了value的地址 ->通过地址返回value值 + + - 字典的特点? + + **无序** + + Python3.6 是有序的,无视这一点 + + - 字典中的key必须是可hash(不可更改,唯一的) + - ???可更改??? + + - 如何表示字典? + + - 通过dict() 来创建字典 + + ``` + dict(a=2) + ``` + + - 通过{ } 来声明一个字典 + + ``` + a = {"a": 2} + ``` + +- set(集合) + + - 什么是Set + + set其实就是没有value的字典 + + - Set (集合) 的特点 + + - 无序的 + - 集合中的Key 必须是可hash的 + - 可以更改 + - 元素是唯一的 + + - 如何表示Set + + - 通过set()来创建集合 + + ``` + set([1,2,2]) + ``` + + - 通过{ } 来表示 + + ``` + {1,2,3} + ``` + +## 课后作业 + +- 四大基本数据结构中哪些是可变的,哪些是不可变的? + + **可变的数据结构:list(列表),dict(字典),set(集合)** + + **不可变的数据结构:tuple (元祖)** + +- 四大基本数据结构中哪些是有序,哪些是无序的? + + **有序的数据结构:list(列表),tuple (元祖)** + + **无序的数据结构:dict(字典),set(集合)** + - 创建set, list, dict, tuple实例每个数据结构的实例需要包括六大基本类型 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\272\214\346\254\241_\344\275\234\344\270\232.12.17/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201217.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\272\214\346\254\241_\344\275\234\344\270\232.12.17/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201217.md" index bdc7ca166d14792e3d880e37551c78225ee03dda..b4d996cdc3bb7167d750bf17cbfdaf50e033a822 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\272\214\346\254\241_\344\275\234\344\270\232.12.17/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201217.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\272\214\346\254\241_\344\275\234\344\270\232.12.17/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202-\351\232\217\345\240\202\347\254\224\350\256\260 20201217.md" @@ -1,183 +1,183 @@ -# 第一周-第二节-随堂笔记 - -#### 1,如何通过GIT来提交作业 - -###### 什么是GIT? - -最强大的**分布式**版本控制**系统** - -- 分布式 - - 分布式指的是成员fork之后的库,就像细胞分裂一样,彼此库是平等的,可以互相合并代码 - - 我们fork远程库之后,当前的库就已经属于我们自己 - - ``` - *此次,我们认为设置码育谷远程库作为主库 - ``` - -- **版本控制** - - ``` - *通过分支切换,实现对不同版本的代码控制 - ``` - -#### 2. GIT 的使用 - -- 安装 - - ``` - https://git-scm.com/downloads - ``` - -- 将GIT添加到环境变量 (https://jingyan.baidu.com/article/ff42efa9c7bd12c19e22028a.html) - - ``` - D:\Downloads\Git\cmd\git.exe - ``` - -- Pycharm配置GIT - - ``` - File-Setting-Version control-Path-Test - ``` - - - 查看安装路径 - - ``` - - where git (windows) - - which git (linux) - ``` - -- 如何调用Git - - **本地上传到远程库** - - - 在平台上新建远程库 - - - 配置用户 (一个环境只用配置一次) - - ``` - git config --global user.name "刘强" - git config --global user.email "liuqiangbio@126.com" #设置邮箱# - ``` - - - 初始化一个git仓库 - - ``` - git init - ``` - - - 配置远程仓库(远程代码仓库) - - ``` - git remote add origin https://gitee.com/plantsanseido/git_test.git - ``` - - - 选择要提交的项目文件 - - - 批量全部添加(不建议) - - ``` - git add ./* - ``` - - - 添加单个文件 - - ``` - git add xx/xx - ``` - - - 通过Pycharm手动添加 - - ``` - 文件选中, git处后选择 add,完成手动添加 - ``` - - - 新建 gitignore文件 - - 用来屏蔽不需要提交上传到项目的文件或文件夹 - - - 最好要默认要屏蔽的文件和文件夹 - - - ``` - .idea - .git - /venv/ - /test/ - */__pycache__ #* 代表所有目录, pycache: python代码翻译成自解码供机器读取,非每次都有,仅第一次出现。 - ``` - - - 提交项目 - - - commit - - 提交到自己的本地库 - - - push - - 提交到远程库 - - - commit and puch - - 二合一,提交到本地库和远程库 - - Note: (git init)要在文件添加之前建立,以防止不需要的文件(如.idae)等上传 - - - 远程同步到本地库 - - ``` - https://gitee.com/xxx(用户名)/xxx(项目名).git - ``` - - - 更新代码 - - ``` - git pull - ``` - - - 解决代码冲突 - - 当本地代码更新时发现和远程代码有冲突 - - - 左边是本地当前代码 - - 右边是远程库代码 - - 中间是最后选择读取的结果 - - - 历史回滚 - - 右键目标文件或者文件夹 点击 history - - 回滚部分代码 -> 在弹出窗口右侧进行修改 - - 回滚整个文件 -> 右键 revert - - - **注意事项** - - - 一定要先新建 .gitigonre - - 不要在服务器/生产环境下直接修改代码 - -#### 3. Python 的虚拟环境 - -一个与系统环境隔离的空间 - -- 虚拟环境的好处 - - - 与系统环境隔离,不会污染正式环境 - - 更新项目方便简洁 - - 通过" requiorement.txt "解决不同平台,不同环境下的环境同步问题 - -- 新建虚拟环境 - - ``` - python -m venv venv # windows环境 - ``` - -- 激活虚拟环境 - - ``` - venv\Scripts\Activate.bat #windows - source venv/bin/active #Linux - ``` - -课后作业 - -- 新建一个项目, 建立虚拟环境,在pycharm配置虚拟环境 -- 建立Git仓库。并同步码云 - +# 第一周-第二节-随堂笔记 + +#### 1,如何通过GIT来提交作业 + +###### 什么是GIT? + +最强大的**分布式**版本控制**系统** + +- 分布式 + + 分布式指的是成员fork之后的库,就像细胞分裂一样,彼此库是平等的,可以互相合并代码 + + 我们fork远程库之后,当前的库就已经属于我们自己 + + ``` + *此次,我们认为设置码育谷远程库作为主库 + ``` + +- **版本控制** + + ``` + *通过分支切换,实现对不同版本的代码控制 + ``` + +#### 2. GIT 的使用 + +- 安装 + + ``` + https://git-scm.com/downloads + ``` + +- 将GIT添加到环境变量 (https://jingyan.baidu.com/article/ff42efa9c7bd12c19e22028a.html) + + ``` + D:\Downloads\Git\cmd\git.exe + ``` + +- Pycharm配置GIT + + ``` + File-Setting-Version control-Path-Test + ``` + + - 查看安装路径 + + ``` + - where git (windows) + - which git (linux) + ``` + +- 如何调用Git + - **本地上传到远程库** + + - 在平台上新建远程库 + + - 配置用户 (一个环境只用配置一次) + + ``` + git config --global user.name "刘强" + git config --global user.email "liuqiangbio@126.com" #设置邮箱# + ``` + + - 初始化一个git仓库 + + ``` + git init + ``` + + - 配置远程仓库(远程代码仓库) + + ``` + git remote add origin https://gitee.com/plantsanseido/git_test.git + ``` + + - 选择要提交的项目文件 + + - 批量全部添加(不建议) + + ``` + git add ./* + ``` + + - 添加单个文件 + + ``` + git add xx/xx + ``` + + - 通过Pycharm手动添加 + + ``` + 文件选中, git处后选择 add,完成手动添加 + ``` + + - 新建 gitignore文件 + + 用来屏蔽不需要提交上传到项目的文件或文件夹 + + - 最好要默认要屏蔽的文件和文件夹 + + - ``` + .idea + .git + /venv/ + /test/ + */__pycache__ #* 代表所有目录, pycache: python代码翻译成自解码供机器读取,非每次都有,仅第一次出现。 + ``` + + - 提交项目 + + - commit + + 提交到自己的本地库 + + - push + + 提交到远程库 + + - commit and puch + + 二合一,提交到本地库和远程库 + + Note: (git init)要在文件添加之前建立,以防止不需要的文件(如.idae)等上传 + + - 远程同步到本地库 + + ``` + https://gitee.com/xxx(用户名)/xxx(项目名).git + ``` + + - 更新代码 + + ``` + git pull + ``` + + - 解决代码冲突 + + 当本地代码更新时发现和远程代码有冲突 + + - 左边是本地当前代码 + - 右边是远程库代码 + - 中间是最后选择读取的结果 + + - 历史回滚 + - 右键目标文件或者文件夹 点击 history + - 回滚部分代码 -> 在弹出窗口右侧进行修改 + - 回滚整个文件 -> 右键 revert + + - **注意事项** + + - 一定要先新建 .gitigonre + - 不要在服务器/生产环境下直接修改代码 + +#### 3. Python 的虚拟环境 + +一个与系统环境隔离的空间 + +- 虚拟环境的好处 + + - 与系统环境隔离,不会污染正式环境 + - 更新项目方便简洁 + - 通过" requiorement.txt "解决不同平台,不同环境下的环境同步问题 + +- 新建虚拟环境 + + ``` + python -m venv venv # windows环境 + ``` + +- 激活虚拟环境 + + ``` + venv\Scripts\Activate.bat #windows + source venv/bin/active #Linux + ``` + +课后作业 + +- 新建一个项目, 建立虚拟环境,在pycharm配置虚拟环境 +- 建立Git仓库。并同步码云 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" index a04ed1914b8bfaa7c59ec3168e80986a232ea550..41edca6af89deff7ee7ca8925e0edb2ded12b44c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.md" @@ -1,224 +1,224 @@ -# 第二周 第一节 - -## Python函数的基本介绍 - -- 什么是函数? - - 函数是一段可以直接被另外一段代码引用的程序或代码,也叫做子程序,方法。 - - - 可重复使用 - - 可互相使用 - -- 函数的目的 - - - 为了代码的复用 - -- 在Python 中如何定义一个函数? - - ``` - def foo(arg): - return "Hello " + str(arg) - result = foo("leo") - print(result) - ``` - -- 函数的组成 - - 1. 参数列表 - - - 必须参数 - - 当前参数必须**按顺利**传入 - - - 关键字参数 - - 根据关键字参数传参可以无视顺序 - - ``` - def nio(sky=None, arg_2=None) - ``` - - - 默认参数 - - ``` - def nio(sky="leo", arg_2=None) - ``` - - - 不定长参数 - - 可以接收任意长度的参数 - - ``` - 在装饰器中会大量应用 - ``` - - - *(星号)代表省略,省略了参数tuple(元祖) - - **(省略了关键字参数 dict (字典)) - - **(关键字参数是一个字典,必须参数是一个元祖)** - -2. 函数体 - - 3. 返回值 - - - 默认返回 None - - ``` - def foo(arg): - result = "Hello " + str(arg) - return result - ``` - - -## Python的运算符 - -- **算术运算** - - - +加法 - - - -减法 - - - *乘以 - - - “/” 除以 - - - ”//“ 整除 - - - % 取余数 - - - **幂运算 - - - 开方 没有提供直接的运算符 - - ``` - 4**(1/2) #4的开方,结果输出为2.0 - ``` - - - abs(数字) 取绝对值 - -- **赋值运算** - - - 通过 = 进行赋值 - - ``` - a = 1 - ``` - - - 比较运算 - - 比较的是两个对象的字面值,字面值暂时可以简单理解为输出值 - - ``` - < - > - <= - >= - == #比较是否相等 - != #不等于 - ``` - - - 标志号比较运算 - - 比较的是,两个变量的内存地址 - - - is / is not - - - 赋值类型为 str int 的时候 要考虑 python的常量池 - -- 成员检测运算 - - 判断**元素**(不是子集)是否在当前序列当中 - - - in / not in - - ``` - a = [1,2,3] - 1 in a - True - - b = [1.2] - b in a - False - - a = [[1,2],3] - b=[1,2] - b in a - True - ``` - -- 布尔运算 - - 判断当前语气的结果是True还是False - - - and 只有当两边都是True才返回 ture - - - or 短路逻辑,其中两边表达式有一个是true则结果为True - - ``` - 表达式A or 表达式B - 当表达式A为True时,表达式B就不会运行 - ``` - - - 逻辑取反 - - not - - ``` - not print("statement_b") or True - statement_b - True - # print("statement_b")执行后, 输出为None,not none为True,or是短路逻辑,到此程序结束,or后面部分不执行 - ``` - - - - - 位运算 - - ``` - 二进制运算,后面运用再补充! - ``` - - - - - - ^ - - ">>" - - "<<" - - & - - | - -### Python运算符优先级 - -| 运算符 | 描述 | -| ----------------------------------------- | ---------------------------------- | -| or | 布尔运算或 | -| and | 布尔运算或 | -| not | 布尔运算或逻辑取反 | -| in / not in/ is / is not / < / != / =.... | 比较运算,成员检测运算,标志号检测 | -| + - | 加法 减法 | -| * / // (整除) % (取余) | 乘法 除法 整除 取余 | -| +X -X | 正负数 | -| ** | 幂运算 | - -- 自定义优先级 - - ``` - 如果不确定优先级,出于可持续性和避免未知Bug, 应该使用 () 来自定义优先级 - ``` - - 通过圆括号自定义优先级 - - ``` - (not b and c) or (d and e) - ``` - -### 作业 - -- 用函数实现一个具有加减乘除,整除,取余,开方的计算器 - - ``` - my_calculator.py - def add(a,b): - .... - def sqrt(a,b): - ... - ``` - +# 第二周 第一节 + +## Python函数的基本介绍 + +- 什么是函数? + + 函数是一段可以直接被另外一段代码引用的程序或代码,也叫做子程序,方法。 + + - 可重复使用 + - 可互相使用 + +- 函数的目的 + + - 为了代码的复用 + +- 在Python 中如何定义一个函数? + + ``` + def foo(arg): + return "Hello " + str(arg) + result = foo("leo") + print(result) + ``` + +- 函数的组成 + + 1. 参数列表 + + - 必须参数 + + 当前参数必须**按顺利**传入 + + - 关键字参数 + + 根据关键字参数传参可以无视顺序 + + ``` + def nio(sky=None, arg_2=None) + ``` + + - 默认参数 + + ``` + def nio(sky="leo", arg_2=None) + ``` + + - 不定长参数 + + 可以接收任意长度的参数 + + ``` + 在装饰器中会大量应用 + ``` + + - *(星号)代表省略,省略了参数tuple(元祖) + - **(省略了关键字参数 dict (字典)) + - **(关键字参数是一个字典,必须参数是一个元祖)** + +2. 函数体 + + 3. 返回值 + + - 默认返回 None + + ``` + def foo(arg): + result = "Hello " + str(arg) + return result + ``` + + +## Python的运算符 + +- **算术运算** + + - +加法 + + - -减法 + + - *乘以 + + - “/” 除以 + + - ”//“ 整除 + + - % 取余数 + + - **幂运算 + + - 开方 没有提供直接的运算符 + + ``` + 4**(1/2) #4的开方,结果输出为2.0 + ``` + + - abs(数字) 取绝对值 + +- **赋值运算** + + - 通过 = 进行赋值 + + ``` + a = 1 + ``` + + - 比较运算 + + 比较的是两个对象的字面值,字面值暂时可以简单理解为输出值 + + ``` + < + > + <= + >= + == #比较是否相等 + != #不等于 + ``` + + - 标志号比较运算 + + 比较的是,两个变量的内存地址 + + - is / is not + + - 赋值类型为 str int 的时候 要考虑 python的常量池 + +- 成员检测运算 + + 判断**元素**(不是子集)是否在当前序列当中 + + - in / not in + + ``` + a = [1,2,3] + 1 in a + True + + b = [1.2] + b in a + False + + a = [[1,2],3] + b=[1,2] + b in a + True + ``` + +- 布尔运算 + + 判断当前语气的结果是True还是False + + - and 只有当两边都是True才返回 ture + + - or 短路逻辑,其中两边表达式有一个是true则结果为True + + ``` + 表达式A or 表达式B + 当表达式A为True时,表达式B就不会运行 + ``` + + - 逻辑取反 + + not + + ``` + not print("statement_b") or True + statement_b + True + # print("statement_b")执行后, 输出为None,not none为True,or是短路逻辑,到此程序结束,or后面部分不执行 + ``` + + + + - 位运算 + + ``` + 二进制运算,后面运用再补充! + ``` + + - - + - ^ + - ">>" + - "<<" + - & + - | + +### Python运算符优先级 + +| 运算符 | 描述 | +| ----------------------------------------- | ---------------------------------- | +| or | 布尔运算或 | +| and | 布尔运算或 | +| not | 布尔运算或逻辑取反 | +| in / not in/ is / is not / < / != / =.... | 比较运算,成员检测运算,标志号检测 | +| + - | 加法 减法 | +| * / // (整除) % (取余) | 乘法 除法 整除 取余 | +| +X -X | 正负数 | +| ** | 幂运算 | + +- 自定义优先级 + + ``` + 如果不确定优先级,出于可持续性和避免未知Bug, 应该使用 () 来自定义优先级 + ``` + + 通过圆括号自定义优先级 + + ``` + (not b and c) or (d and e) + ``` + +### 作业 + +- 用函数实现一个具有加减乘除,整除,取余,开方的计算器 + + ``` + my_calculator.py + def add(a,b): + .... + def sqrt(a,b): + ... + ``` + - 在交互模式中联系python运算符 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232my_calculator.py" index 7b91a5eddcfa0c4d7b72626b468a7e6ca6cbe4d9..3f926a04ee7da6c33fbffa7f824ce6642b53ee6c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232my_calculator.py" @@ -1,61 +1,61 @@ -# 定义函数 -def add (a, b): - """"加上""" - return a + b - -def subtract(a, b): - return a - b - -def multiply(a, b): - return a * b - -def divide(a, b): - return a / b - -def divisible(a, b): - return a // b - -def sqrt(a, b): - return a ** (1/b) - -def surplus(a, b): - return a % b - -#交互界面 -print("请选择您将进行的运算: ") -print("1,加上") -print("2,减去") -print("3,乘以") -print("4,除去") -print("5,整除") -print("6,开方") -print("7,取余") - -choice = input("请输入您的选择(1,2,3,4,5,6,7): ") -num1 = int(input("输入第一个数字: ")) -num2 = int(input("输入第二个数字: ")) - -if choice == '1': - print(num1, "+", num2, "=", add(num1, num2)) - -elif choice == '2': - print(num1, "-", num2, "=", subtract(num1, num2)) - -elif choice == '3': - print(num1, "*", num2, "=", multiply(num1, num2)) - -elif choice == '4': - print(num1, "/", num2, "=", divide(num1, num2)) - -elif choice == '5': - print(num1, "//", num2, "=", divisible(num1, num2)) - -elif choice == '6': - print(num1, "**", (1/num2), "=", sqrt(num1, num2)) - -elif choice == '7': - print(num1, "%", num2, "=", surplus(num1, num2)) - -else: - print("非法输入") - +# 定义函数 +def add (a, b): + """"加上""" + return a + b + +def subtract(a, b): + return a - b + +def multiply(a, b): + return a * b + +def divide(a, b): + return a / b + +def divisible(a, b): + return a // b + +def sqrt(a, b): + return a ** (1/b) + +def surplus(a, b): + return a % b + +#交互界面 +print("请选择您将进行的运算: ") +print("1,加上") +print("2,减去") +print("3,乘以") +print("4,除去") +print("5,整除") +print("6,开方") +print("7,取余") + +choice = input("请输入您的选择(1,2,3,4,5,6,7): ") +num1 = int(input("输入第一个数字: ")) +num2 = int(input("输入第二个数字: ")) + +if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + +elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + +elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + +elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + +elif choice == '5': + print(num1, "//", num2, "=", divisible(num1, num2)) + +elif choice == '6': + print(num1, "**", (1/num2), "=", sqrt(num1, num2)) + +elif choice == '7': + print(num1, "%", num2, "=", surplus(num1, num2)) + +else: + print("非法输入") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202_\344\272\224\347\217\255_\345\210\230\345\274\272.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202_\344\272\224\347\217\255_\345\210\230\345\274\272.md" index 341d96599d6cc05ebea6078f0c5e94c259e312e4..d3bf2b9fccb2c04e5ec8390872113f10c720723e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202_\344\272\224\347\217\255_\345\210\230\345\274\272.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202_\344\272\224\347\217\255_\345\210\230\345\274\272.md" @@ -1,387 +1,387 @@ -# 第二周-第三节课-五班-刘强 - -## 了解变量和引用 - -- 变量简单地说就是指向了一个内存实体 - -- 引用简单地说就是指向变量的变量 - - ``` - >>> a = 1 - >>> b = a - >>> id(a) - 1778508560 - >>> id(b) - 1778508560 - ``` - -## 基础数据结构的CRUD操作 - -- **List(列表)** - - **list中存的元素是引用**,内存地址不发生改变 - - - create(增加,创建) - - - append #末尾添加元素 **不改变内存地址** - - ``` ->>> l = [] - >>> id(l) - 55200584 - >>> l.append("a") - >>> l - ['a'] - >>> id(l) - 55200584 - ``` - - - `+` 和`+=` - - - `+` - - 拼接两个列表, 然后返回一个新列表 - - - **`+=`** - - ``` - >>> l = ['a'] - >>> id(l) - 55200664 - >>> l += ['b'] - >>> id(l) - 55200664 - >>> l - ['a', 'b'] - ``` - - - `*`和`*=` - - ``` - >>> a = 'a' - >>> id(a) - 53622432 - >>> l = [a] * 10 - >>> l - ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - >>> id(l[0]) - 53622432 - >>> id(l[1]) - 53622432 - >>> id(l[9]) - 53622432 - - # 赋值语句之后, a已经是一个新的对象了 - >>> a = 'b' - >>> l - ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - >>> id(a) - 53647264 - ``` - - - insert - - 指定位置添加元素 - - ``` - l.insert(0, 'b') - # 0 表示指定的位置 - ``` - -- Retrieve(检索) - - - 索引取值 - - 所有序列都支持索引取值 - - - 切片 - - ``` - your_list[start:end:step] - # 取一段区间 - your_list[start:end] - - # 取最后一个值 - your_list[-1] - - # 间隔问题 - your_list[1:20:2] - ``` - - - index - - ``` - >>> l - ['a', 'b', 'c'] - >>> l.index('a') - 0 - ``` - -- Update(更新) - - - 索引赋值 - - ``` - l[0] = 'a_1' - #赋值后 不改变内存地址 - ``` - - - 切片赋值 - - ``` - >>> l - ['a_1', 'a_2', 'b', 'c'] - >>> l[0:2] = "a" - >>> l - ['a', 'b', 'c'] - >>> l[0:2] = 1 - ``` - - - DELETE(删除) - - - pop() - - 从末尾删除元素并返回 - - ``` - >>> l - ['a', 'b', 'c'] - >>> x = l.pop() - >>> l - ['a', 'b'] - >>> x - 'c' - ``` - - - clear() - - 清除当前列表的元素, 不会改变列表的内存地址. - - - ★**SORT(排序)** - - - sort() 列表本身函数 - - ``` - >>> l - [1, 3, 2, 6, 4] - >>> l.sort() - >>> l - [1, 2, 3, 4, 6] - - ``` - - - sorted 内置函数 - - 排序后返回新列表 - - ``` - >>> l2 = sorted(l) - >>> l - [1, 3, 2, 6, 4] - >>> l2 - [1, 2, 3, 4, 6] - >>> id(l) - 55201384 - >>> id(l2) - 55200984 - ``` - - - reverse - - ``` - >>> l2 - [1, 2, 3, 4, 6] - >>> l2.reverse() - >>> l2 - [6, 4, 3, 2, 1] - ``` - - - reversed - - 倒序之后返回新列表 - - ``` - >>> l - [1, 3, 2, 6, 4] - >>> list(reversed(l)) - [4, 6, 2, 3, 1] - ``` - -- **tuple 不可变列表** - - - Create - - 无 - - - Retrieve - - - 索引取值 - - index - - 切片 - - - Update - - 无 - - - Delete - - 无 - -- dict 字典 - - - Create - - - 键对值赋值 - - - update - - 提供合并字典的功能 - - ``` - >>> d - {'a': 1} - >>> d2 = {"b":2, "c": 3} - >>> d.update(d2) - >>> d - {'a': 1, 'b': 2, 'c': 3} - #不改变id地址 - ``` - - - setdefault - - 如果字典中没有当前key, 那么就设置默认值 - - ``` - >>> d - {'a': 1, 'b': 2, 'c': 3} - >>> d.setdefault('b', 0) - 2 - >>> d.setdefault('d', 0) - 0 - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0} - - ``` - - - Retrieve 查阅 - - - 键对值访问 - - - get - - 键对值访问缺失key会报错, 而get可以指定默认值 - - ``` - >>> d['e'] - Traceback (most recent call last): - File "", line 1, in - KeyError: 'e' - >>> d.get('f') - >>> d.get('f', 0) - 0 - ``` - - - keys() - - 返回所有key - - ``` - d.keys() - ``` - - - values() - - 返回所有value - - ``` - d.values() - ``` - - - items() - - 返回所有键对值 - - ``` - d.items() - ``` - - - Update - - - 键对值赋值 - - ``` - d['a'] = 100 - ``` - - - update - - ``` - >>> d.update({"b": 200, "c": 300}) - >>> d - {'a': 100, 'b': 200, 'c': 300, 'd': 0} - ``` - - - Delete - - - pop(key) - - 删除当前元素并返回value - - - popitem() - - 对于人来说, 相当于随机返回一个item - - - clear() - -- **set** - - - Create - - - add - - update - - - Retrieve - - - 运算符`in` - - ``` - >>> s - {'a'} - >>> "a" in s - True - - ``` - - - update - - - union - - 合并两个set, 并返回一个新的set - - - delete - - - remove 和discard - - discard缺失元素时不会报错, 而remove会报错 - - ``` - >>> s - {'b', 'c', 'a'} - >>> s.remove("a") - >>> s - {'b', 'c'} - >>> s.discard("e") - >>> s.remove("a") - Traceback (most recent call last): - File "", line 1, in - KeyError: 'a' - >>> - ``` - - - pop() - - 当成无序删除并返回元素 - -## 课后作业 - +# 第二周-第三节课-五班-刘强 + +## 了解变量和引用 + +- 变量简单地说就是指向了一个内存实体 + +- 引用简单地说就是指向变量的变量 + + ``` + >>> a = 1 + >>> b = a + >>> id(a) + 1778508560 + >>> id(b) + 1778508560 + ``` + +## 基础数据结构的CRUD操作 + +- **List(列表)** + + **list中存的元素是引用**,内存地址不发生改变 + + - create(增加,创建) + + - append #末尾添加元素 **不改变内存地址** + + ``` +>>> l = [] + >>> id(l) + 55200584 + >>> l.append("a") + >>> l + ['a'] + >>> id(l) + 55200584 + ``` + + - `+` 和`+=` + + - `+` + + 拼接两个列表, 然后返回一个新列表 + + - **`+=`** + + ``` + >>> l = ['a'] + >>> id(l) + 55200664 + >>> l += ['b'] + >>> id(l) + 55200664 + >>> l + ['a', 'b'] + ``` + + - `*`和`*=` + + ``` + >>> a = 'a' + >>> id(a) + 53622432 + >>> l = [a] * 10 + >>> l + ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + >>> id(l[0]) + 53622432 + >>> id(l[1]) + 53622432 + >>> id(l[9]) + 53622432 + + # 赋值语句之后, a已经是一个新的对象了 + >>> a = 'b' + >>> l + ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + >>> id(a) + 53647264 + ``` + + - insert + + 指定位置添加元素 + + ``` + l.insert(0, 'b') + # 0 表示指定的位置 + ``` + +- Retrieve(检索) + + - 索引取值 + + 所有序列都支持索引取值 + + - 切片 + + ``` + your_list[start:end:step] + # 取一段区间 + your_list[start:end] + + # 取最后一个值 + your_list[-1] + + # 间隔问题 + your_list[1:20:2] + ``` + + - index + + ``` + >>> l + ['a', 'b', 'c'] + >>> l.index('a') + 0 + ``` + +- Update(更新) + + - 索引赋值 + + ``` + l[0] = 'a_1' + #赋值后 不改变内存地址 + ``` + + - 切片赋值 + + ``` + >>> l + ['a_1', 'a_2', 'b', 'c'] + >>> l[0:2] = "a" + >>> l + ['a', 'b', 'c'] + >>> l[0:2] = 1 + ``` + + - DELETE(删除) + + - pop() + + 从末尾删除元素并返回 + + ``` + >>> l + ['a', 'b', 'c'] + >>> x = l.pop() + >>> l + ['a', 'b'] + >>> x + 'c' + ``` + + - clear() + + 清除当前列表的元素, 不会改变列表的内存地址. + + - ★**SORT(排序)** + + - sort() 列表本身函数 + + ``` + >>> l + [1, 3, 2, 6, 4] + >>> l.sort() + >>> l + [1, 2, 3, 4, 6] + + ``` + + - sorted 内置函数 + + 排序后返回新列表 + + ``` + >>> l2 = sorted(l) + >>> l + [1, 3, 2, 6, 4] + >>> l2 + [1, 2, 3, 4, 6] + >>> id(l) + 55201384 + >>> id(l2) + 55200984 + ``` + + - reverse + + ``` + >>> l2 + [1, 2, 3, 4, 6] + >>> l2.reverse() + >>> l2 + [6, 4, 3, 2, 1] + ``` + + - reversed + + 倒序之后返回新列表 + + ``` + >>> l + [1, 3, 2, 6, 4] + >>> list(reversed(l)) + [4, 6, 2, 3, 1] + ``` + +- **tuple 不可变列表** + + - Create + + 无 + + - Retrieve + + - 索引取值 + - index + - 切片 + + - Update + + 无 + + - Delete + + 无 + +- dict 字典 + + - Create + + - 键对值赋值 + + - update + + 提供合并字典的功能 + + ``` + >>> d + {'a': 1} + >>> d2 = {"b":2, "c": 3} + >>> d.update(d2) + >>> d + {'a': 1, 'b': 2, 'c': 3} + #不改变id地址 + ``` + + - setdefault + + 如果字典中没有当前key, 那么就设置默认值 + + ``` + >>> d + {'a': 1, 'b': 2, 'c': 3} + >>> d.setdefault('b', 0) + 2 + >>> d.setdefault('d', 0) + 0 + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0} + + ``` + + - Retrieve 查阅 + + - 键对值访问 + + - get + + 键对值访问缺失key会报错, 而get可以指定默认值 + + ``` + >>> d['e'] + Traceback (most recent call last): + File "", line 1, in + KeyError: 'e' + >>> d.get('f') + >>> d.get('f', 0) + 0 + ``` + + - keys() + + 返回所有key + + ``` + d.keys() + ``` + + - values() + + 返回所有value + + ``` + d.values() + ``` + + - items() + + 返回所有键对值 + + ``` + d.items() + ``` + + - Update + + - 键对值赋值 + + ``` + d['a'] = 100 + ``` + + - update + + ``` + >>> d.update({"b": 200, "c": 300}) + >>> d + {'a': 100, 'b': 200, 'c': 300, 'd': 0} + ``` + + - Delete + + - pop(key) + + 删除当前元素并返回value + + - popitem() + + 对于人来说, 相当于随机返回一个item + + - clear() + +- **set** + + - Create + + - add + - update + + - Retrieve + + - 运算符`in` + + ``` + >>> s + {'a'} + >>> "a" in s + True + + ``` + + - update + + - union + + 合并两个set, 并返回一个新的set + + - delete + + - remove 和discard + + discard缺失元素时不会报错, 而remove会报错 + + ``` + >>> s + {'b', 'c', 'a'} + >>> s.remove("a") + >>> s + {'b', 'c'} + >>> s.discard("e") + >>> s.remove("a") + Traceback (most recent call last): + File "", line 1, in + KeyError: 'a' + >>> + ``` + + - pop() + + 当成无序删除并返回元素 + +## 课后作业 + - 完成四大基础数据结构的CRUD操作 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" index 998ec8e2ba7247d95beaea36f63dddbfb167d13b..5cb6350b5251fd5b7593cb1905dd29c12363357f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" @@ -1,178 +1,178 @@ -#完成四大基础数据结构的CRUD操作 -#1 list ->>> l = [] ->>> id(l) -2035138209416 ->>> l.append("a") ->>> l -['a'] ->>> id(l) -2035138209416 ->>> l = l + ["b"] ->>> l -['a', 'b'] ->>> l += ["c"] ->>> l -['a', 'b', 'c'] ->>> l -['a', 'b', 'c'] ->>> l = ["a"]*10 ->>> l -['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] ->>> id(l[2]) -2035137117800 ->>> id(l) -2035138209288 ->>> l[2] -'a' ->>> l -['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] ->>> l.insert(1, 'd') ->>> l -['a', 'd', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] ->>> l [2:8:3] -['a', 'a'] ->>> l = [1,2,3,4,5,6,7,8,9,] ->>> l [2:8:3] -[3, 6] ->>> l[-1] -9 ->>> l -[1, 2, 3, 4, 5, 6, 7, 8, 9] ->>> l.index('a') -Traceback (most recent call last): - File "", line 1, in -ValueError: 'a' is not in list ->>> l.index("a") -Traceback (most recent call last): - File "", line 1, in -ValueError: 'a' is not in list ->>> l.index(4) -3 ->>>>>> l -[1, 2, 3, 4, 5, 6, 7, 8, 9] ->>> l2 -[6, 5, 4, 3, 2, 1] ->>> l[-1] -9 ->>> l.index(9) -8 ->>> l[0]='leo' ->>> l -['leo', 2, 3, 4, 5, 6, 7, 8, 9] ->>> l[0:2]='sky' ->>> l -['s', 'k', 'y', 3, 4, 5, 6, 7, 8, 9] ->>> x = l.pop90 -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'list' object has no attribute 'pop90' ->>> x = l.pop() ->>> l -['s', 'k', 'y', 3, 4, 5, 6, 7, 8] ->>> x -9 ->>> clear() -Traceback (most recent call last): - File "", line 1, in -NameError: name 'clear' is not defined ->>> clear(l) -Traceback (most recent call last): - File "", line 1, in -NameError: name 'clear' is not defined ->>> l -['s', 'k', 'y', 3, 4, 5, 6, 7, 8] ->>> l.sort() -Traceback (most recent call last): - File "", line 1, in -TypeError: '<' not supported between instances of 'int' and 'str' -#2 Tuple ->>> d -{'a': 1} ->>> d2 = {"b":2, "c": 3} ->>> d.update(d2) ->>> d -{'a': 1, 'b': 2, 'c': 3} ->>> d -{'a': 1, 'b': 2, 'c': 3} ->>> d.setdefault('b', 0) -2 ->>> d.setdefault('d', 0) -0 ->>> d -{'a': 1, 'b': 2, 'c': 3, 'd': 0} ->>> d -{'a': 1, 'b': 2, 'c': 3} ->>> d3 ={"d":4, "e":5} ->>> d.update(d3) ->>> d -{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5} ->>> d.setdefault('d',0) -4 ->>> d['d'] -4 ->>> d.get('e') -5 ->>> d.get('e',0) -5 ->>> d.keys() -dict_keys(['a', 'b', 'c', 'd', 'e']) ->>> d.values() -dict_values([1, 2, 3, 4, 5]) ->>> d.items() -dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) ->>> d['a'=99] - File "", line 1 - d['a'=99] - ^ -SyntaxError: invalid syntax ->>> d['a']=99 ->>> d -{'a': 99, 'b': 2, 'c': 3, 'd': 4, 'e': 5} ->>> d.pop('a') -99 ->>> d -{'b': 2, 'c': 3, 'd': 4, 'e': 5} ->>> popitem() -Traceback (most recent call last): - File "", line 1, in -NameError: name 'popitem' is not defined ->>> d.popitem() -('e', 5) ->>> d.popitem() -('d', 4) ->>> d.popitem() -('c', 3) ->>> d.popitem() -('b', 2) ->>> popitem() -Traceback (most recent call last): - File "", line 1, in -NameError: name 'popitem' is not defined ->>> clear() -Traceback (most recent call last): - File "", line 1, in -NameError: name 'clear' is not defined ->>> d -{} - -#3 Set ->>> s = {'a', 'b', 'c'} ->>> s -{'b', 'a', 'c'} ->>> s.remove('a') ->>> s -{'b', 'c'} ->>> s.discard('e') ->>> s -{'b', 'c'} ->>> s.discard('b') ->>> s -{'c'} ->>> s.remove('c') ->>> s -set() ->>> - - - +#完成四大基础数据结构的CRUD操作 +#1 list +>>> l = [] +>>> id(l) +2035138209416 +>>> l.append("a") +>>> l +['a'] +>>> id(l) +2035138209416 +>>> l = l + ["b"] +>>> l +['a', 'b'] +>>> l += ["c"] +>>> l +['a', 'b', 'c'] +>>> l +['a', 'b', 'c'] +>>> l = ["a"]*10 +>>> l +['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] +>>> id(l[2]) +2035137117800 +>>> id(l) +2035138209288 +>>> l[2] +'a' +>>> l +['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] +>>> l.insert(1, 'd') +>>> l +['a', 'd', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] +>>> l [2:8:3] +['a', 'a'] +>>> l = [1,2,3,4,5,6,7,8,9,] +>>> l [2:8:3] +[3, 6] +>>> l[-1] +9 +>>> l +[1, 2, 3, 4, 5, 6, 7, 8, 9] +>>> l.index('a') +Traceback (most recent call last): + File "", line 1, in +ValueError: 'a' is not in list +>>> l.index("a") +Traceback (most recent call last): + File "", line 1, in +ValueError: 'a' is not in list +>>> l.index(4) +3 +>>>>>> l +[1, 2, 3, 4, 5, 6, 7, 8, 9] +>>> l2 +[6, 5, 4, 3, 2, 1] +>>> l[-1] +9 +>>> l.index(9) +8 +>>> l[0]='leo' +>>> l +['leo', 2, 3, 4, 5, 6, 7, 8, 9] +>>> l[0:2]='sky' +>>> l +['s', 'k', 'y', 3, 4, 5, 6, 7, 8, 9] +>>> x = l.pop90 +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'list' object has no attribute 'pop90' +>>> x = l.pop() +>>> l +['s', 'k', 'y', 3, 4, 5, 6, 7, 8] +>>> x +9 +>>> clear() +Traceback (most recent call last): + File "", line 1, in +NameError: name 'clear' is not defined +>>> clear(l) +Traceback (most recent call last): + File "", line 1, in +NameError: name 'clear' is not defined +>>> l +['s', 'k', 'y', 3, 4, 5, 6, 7, 8] +>>> l.sort() +Traceback (most recent call last): + File "", line 1, in +TypeError: '<' not supported between instances of 'int' and 'str' +#2 Tuple +>>> d +{'a': 1} +>>> d2 = {"b":2, "c": 3} +>>> d.update(d2) +>>> d +{'a': 1, 'b': 2, 'c': 3} +>>> d +{'a': 1, 'b': 2, 'c': 3} +>>> d.setdefault('b', 0) +2 +>>> d.setdefault('d', 0) +0 +>>> d +{'a': 1, 'b': 2, 'c': 3, 'd': 0} +>>> d +{'a': 1, 'b': 2, 'c': 3} +>>> d3 ={"d":4, "e":5} +>>> d.update(d3) +>>> d +{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5} +>>> d.setdefault('d',0) +4 +>>> d['d'] +4 +>>> d.get('e') +5 +>>> d.get('e',0) +5 +>>> d.keys() +dict_keys(['a', 'b', 'c', 'd', 'e']) +>>> d.values() +dict_values([1, 2, 3, 4, 5]) +>>> d.items() +dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) +>>> d['a'=99] + File "", line 1 + d['a'=99] + ^ +SyntaxError: invalid syntax +>>> d['a']=99 +>>> d +{'a': 99, 'b': 2, 'c': 3, 'd': 4, 'e': 5} +>>> d.pop('a') +99 +>>> d +{'b': 2, 'c': 3, 'd': 4, 'e': 5} +>>> popitem() +Traceback (most recent call last): + File "", line 1, in +NameError: name 'popitem' is not defined +>>> d.popitem() +('e', 5) +>>> d.popitem() +('d', 4) +>>> d.popitem() +('c', 3) +>>> d.popitem() +('b', 2) +>>> popitem() +Traceback (most recent call last): + File "", line 1, in +NameError: name 'popitem' is not defined +>>> clear() +Traceback (most recent call last): + File "", line 1, in +NameError: name 'clear' is not defined +>>> d +{} + +#3 Set +>>> s = {'a', 'b', 'c'} +>>> s +{'b', 'a', 'c'} +>>> s.remove('a') +>>> s +{'b', 'c'} +>>> s.discard('e') +>>> s +{'b', 'c'} +>>> s.discard('b') +>>> s +{'c'} +>>> s.remove('c') +>>> s +set() +>>> + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" index 7e2ffb254b9a680b69efc8c037af0bbd7122b1e3..e1a617b613fe5d890bc03090a19242d272b74c7d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\344\275\234\344\270\232_\344\272\224\347\217\255_\345\210\230\345\274\272.py" @@ -1,189 +1,189 @@ -# 字符串的编码 -'中国上海'.encode("unicode_escape").decode() - -'\u4e2d\u56fd\u4e0a\u6d77' - -# 字符串的解码 -"中国上海".encode("utf-8") -b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' - -# 练习字符串的CRUD ->>> a = "shanghai" ->>> id(a) -2587958455216 ->>> a = a + "dongfang" ->>> id(a) -2587958461328 ->>> print(a) -shanghaidongfang ->>> ->>> '中国上海'.encode("utf-8") -b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' ->>> b.decode("utf") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'str' object has no attribute 'decode' ->>> a = "shanghai" ->>> id(a) -2587958455216 ->>> a = a + "dongfang" ->>> id(a) -2587958461328 ->>> print(a) -shanghaidongfang ->>> a[3] -'n' ->>> a.find("a") -2 ->>> a.find("m") --1 ->>> a.startwith("\nzhongguo") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'str' object has no attribute 'startwith' ->>> a.startswith("\nzhongguo") -False ->>> a.startswith("zhongguo") -False ->>> m = "zhongguo-shanghai-dongfang" ->>> a.startswith("zhongguo") -False ->>> m.startswith("zhongguo") -True ->>> print m - File "", line 1 - print m - ^ -SyntaxError: Missing parentheses in call to 'print'. Did you mean print(m)? ->>> print(m) -zhongguo-shanghai-dongfang ->>> m.endswith("dongfang") -True ->>> m.replace("shanghai", "zhejiang") -'zhongguo-zhejiang-dongfang' ->>> m.split(",") -['zhongguo-shanghai-dongfang'] ->>> m = ("zhongguo", "shanghai", "dongfang") ->>> m.split(",") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'tuple' object has no attribute 'split' ->>> m = "zhongguo, shanghai, dongfang" ->>> m.split(",") -['zhongguo', ' shanghai', ' dongfang'] ->>> ",".join(m) -'z,h,o,n,g,g,u,o,,, ,s,h,a,n,g,h,a,i,,, ,d,o,n,g,f,a,n,g' ->>> print(m) -zhongguo, shanghai, dongfang ->>> m.strip() -'zhongguo, shanghai, dongfang' ->>> print(m) -zhongguo, shanghai, dongfang ->>> -# 练习字符串的格式化 ->>> g = "shang" ->>> h = "hai" ->>> "go to shanhai:{},{}.format(a,b) - File "", line 1 - "go to shanhai:{},{}.format(a,b) - ^ -SyntaxError: EOL while scanning string literal ->>> "stay shanhai:{},{}.format(a,b) - File "", line 1 - "stay shanhai:{},{}.format(a,b) - ^ -SyntaxError: EOL while scanning string literal ->>> "play shanghai:{}, {}".format(a,b) -'play shanghai:shanghaidongfang, ä¸\xadå\x9b½ä¸\x8aæµ·' ->>> "play shanghai:{}, {}".format(g, h) -'play shanghai:shang, hai' ->>> "go to shanghai:{}{}".format(a,b) -'go to shanghai:shanghaidongfangä¸\xadå\x9b½ä¸\x8aæµ·' ->>> "go to shanghai:{}{}".format(g,h) -'go to shanghai:shanghai' ->>> "go to shanghhai:{0}{0}{1}{1}”。format(g, h) - File "", line 1 - "go to shanghhai:{0}{0}{1}{1}”。format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> "go to shanghhai:{0}{0}{1}{1}”.format(g, h) - File "", line 1 - "go to shanghhai:{0}{0}{1}{1}”.format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> "go to shanghhai:{0},{0},{1},{1}”.format(g, h) - File "", line 1 - "go to shanghhai:{0},{0},{1},{1}”.format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> "go to shanghhai: {0}, {0}, {1}, {1}”.format(g, h) - File "", line 1 - "go to shanghhai: {0}, {0}, {1}, {1}”.format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> print(g) -shang ->>> "go to shanghhai: {0}, {1}, {0}, {1}”.format(g, h) - File "", line 1 - "go to shanghhai: {0}, {1}, {0}, {1}”.format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> "go to shanghai: {0}, {1}, {0}, {1}”.format(g, h) - File "", line 1 - "go to shanghai: {0}, {1}, {0}, {1}”.format(g, h) - ^ -SyntaxError: EOL while scanning string literal ->>> a= "ping" ->>> b = "pang" ->>> "play pingpong: {0},{1},{0},{1}".format(a, b) -'play pingpong: ping,pang,ping,pang' ->>> "play pingpong: {0}, {1},{0}, {1}".format(g,h) -'play pingpong: shang, hai,shang, hai' ->>> print("go to shanghai: {g}, {h}, {g}, {h}".format=(g='shang',h='hai')) - File "", line 1 - print("go to shanghai: {g}, {h}, {g}, {h}".format=(g='shang',h='hai')) - ^ -SyntaxError: invalid syntax ->>> print("go to shanghai: {g}, {h}, {g}, {h}".format(g='shang',h='hai')) -go to shanghai: shang, hai, shang, hai ->>> print(f"go to shanghai: {g},{h}") -go to shanghai: shang,hai ->>> "{:.2f}".format(5.122325425) -'5.12' ->>> "{:.4f}".format(5.122325425) -'5.1223' ->>> "go to %s %s" % ("ping", "pong") -'go to ping pong' - -# 将content内容保存到本地文件 ->>> output = open("output.txt", "w", encoding="utf-8") ->>> content = "go to shanghai" ->>> output.write(content) -14 ->>> output.close() ->>> ->>> output = open("shanghai.txt", "w", encoding="utf-8") ->>> content = "go to shanghai" ->>> output.write(content) -14 ->>> output.close() ->>> input = open("shanghai.txt", "r", encoding= "utf-8") ->>> content = input.read() ->>> print(content) -go to shanghai ->>> content = "\nI love shanghai" ->>> output.write(content) -Traceback (most recent call last): - File "", line 1, in -ValueError: I/O operation on closed file. ->>> output = open("shanghai.txt", "a", encoding="utf-8") ->>> content = "\nI love shanghai" ->>> output.write(content) -16 ->>> output.close() ->>> input = open("shanghai.txt", "r", encoding= "utf-8") ->>> content = input.read() ->>> print(content) -go to shanghai -I love shanghai ->>> +# 字符串的编码 +'中国上海'.encode("unicode_escape").decode() + +'\u4e2d\u56fd\u4e0a\u6d77' + +# 字符串的解码 +"中国上海".encode("utf-8") +b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' + +# 练习字符串的CRUD +>>> a = "shanghai" +>>> id(a) +2587958455216 +>>> a = a + "dongfang" +>>> id(a) +2587958461328 +>>> print(a) +shanghaidongfang +>>> +>>> '中国上海'.encode("utf-8") +b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' +>>> b.decode("utf") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'str' object has no attribute 'decode' +>>> a = "shanghai" +>>> id(a) +2587958455216 +>>> a = a + "dongfang" +>>> id(a) +2587958461328 +>>> print(a) +shanghaidongfang +>>> a[3] +'n' +>>> a.find("a") +2 +>>> a.find("m") +-1 +>>> a.startwith("\nzhongguo") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'str' object has no attribute 'startwith' +>>> a.startswith("\nzhongguo") +False +>>> a.startswith("zhongguo") +False +>>> m = "zhongguo-shanghai-dongfang" +>>> a.startswith("zhongguo") +False +>>> m.startswith("zhongguo") +True +>>> print m + File "", line 1 + print m + ^ +SyntaxError: Missing parentheses in call to 'print'. Did you mean print(m)? +>>> print(m) +zhongguo-shanghai-dongfang +>>> m.endswith("dongfang") +True +>>> m.replace("shanghai", "zhejiang") +'zhongguo-zhejiang-dongfang' +>>> m.split(",") +['zhongguo-shanghai-dongfang'] +>>> m = ("zhongguo", "shanghai", "dongfang") +>>> m.split(",") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'tuple' object has no attribute 'split' +>>> m = "zhongguo, shanghai, dongfang" +>>> m.split(",") +['zhongguo', ' shanghai', ' dongfang'] +>>> ",".join(m) +'z,h,o,n,g,g,u,o,,, ,s,h,a,n,g,h,a,i,,, ,d,o,n,g,f,a,n,g' +>>> print(m) +zhongguo, shanghai, dongfang +>>> m.strip() +'zhongguo, shanghai, dongfang' +>>> print(m) +zhongguo, shanghai, dongfang +>>> +# 练习字符串的格式化 +>>> g = "shang" +>>> h = "hai" +>>> "go to shanhai:{},{}.format(a,b) + File "", line 1 + "go to shanhai:{},{}.format(a,b) + ^ +SyntaxError: EOL while scanning string literal +>>> "stay shanhai:{},{}.format(a,b) + File "", line 1 + "stay shanhai:{},{}.format(a,b) + ^ +SyntaxError: EOL while scanning string literal +>>> "play shanghai:{}, {}".format(a,b) +'play shanghai:shanghaidongfang, ä¸\xadå\x9b½ä¸\x8aæµ·' +>>> "play shanghai:{}, {}".format(g, h) +'play shanghai:shang, hai' +>>> "go to shanghai:{}{}".format(a,b) +'go to shanghai:shanghaidongfangä¸\xadå\x9b½ä¸\x8aæµ·' +>>> "go to shanghai:{}{}".format(g,h) +'go to shanghai:shanghai' +>>> "go to shanghhai:{0}{0}{1}{1}”。format(g, h) + File "", line 1 + "go to shanghhai:{0}{0}{1}{1}”。format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> "go to shanghhai:{0}{0}{1}{1}”.format(g, h) + File "", line 1 + "go to shanghhai:{0}{0}{1}{1}”.format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> "go to shanghhai:{0},{0},{1},{1}”.format(g, h) + File "", line 1 + "go to shanghhai:{0},{0},{1},{1}”.format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> "go to shanghhai: {0}, {0}, {1}, {1}”.format(g, h) + File "", line 1 + "go to shanghhai: {0}, {0}, {1}, {1}”.format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> print(g) +shang +>>> "go to shanghhai: {0}, {1}, {0}, {1}”.format(g, h) + File "", line 1 + "go to shanghhai: {0}, {1}, {0}, {1}”.format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> "go to shanghai: {0}, {1}, {0}, {1}”.format(g, h) + File "", line 1 + "go to shanghai: {0}, {1}, {0}, {1}”.format(g, h) + ^ +SyntaxError: EOL while scanning string literal +>>> a= "ping" +>>> b = "pang" +>>> "play pingpong: {0},{1},{0},{1}".format(a, b) +'play pingpong: ping,pang,ping,pang' +>>> "play pingpong: {0}, {1},{0}, {1}".format(g,h) +'play pingpong: shang, hai,shang, hai' +>>> print("go to shanghai: {g}, {h}, {g}, {h}".format=(g='shang',h='hai')) + File "", line 1 + print("go to shanghai: {g}, {h}, {g}, {h}".format=(g='shang',h='hai')) + ^ +SyntaxError: invalid syntax +>>> print("go to shanghai: {g}, {h}, {g}, {h}".format(g='shang',h='hai')) +go to shanghai: shang, hai, shang, hai +>>> print(f"go to shanghai: {g},{h}") +go to shanghai: shang,hai +>>> "{:.2f}".format(5.122325425) +'5.12' +>>> "{:.4f}".format(5.122325425) +'5.1223' +>>> "go to %s %s" % ("ping", "pong") +'go to ping pong' + +# 将content内容保存到本地文件 +>>> output = open("output.txt", "w", encoding="utf-8") +>>> content = "go to shanghai" +>>> output.write(content) +14 +>>> output.close() +>>> +>>> output = open("shanghai.txt", "w", encoding="utf-8") +>>> content = "go to shanghai" +>>> output.write(content) +14 +>>> output.close() +>>> input = open("shanghai.txt", "r", encoding= "utf-8") +>>> content = input.read() +>>> print(content) +go to shanghai +>>> content = "\nI love shanghai" +>>> output.write(content) +Traceback (most recent call last): + File "", line 1, in +ValueError: I/O operation on closed file. +>>> output = open("shanghai.txt", "a", encoding="utf-8") +>>> content = "\nI love shanghai" +>>> output.write(content) +16 +>>> output.close() +>>> input = open("shanghai.txt", "r", encoding= "utf-8") +>>> content = input.read() +>>> print(content) +go to shanghai +I love shanghai +>>> diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\347\254\224\350\256\260_\344\272\224\347\217\255 _\345\210\230\345\274\272.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\347\254\224\350\256\260_\344\272\224\347\217\255 _\345\210\230\345\274\272.md" index 5f99b129aadfc37e743c2cfb43c7e94a54d949e6..854281787931705d28189a3c10fe8043b0df81a4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\347\254\224\350\256\260_\344\272\224\347\217\255 _\345\210\230\345\274\272.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\212\202\347\254\224\350\256\260_\344\272\224\347\217\255 _\345\210\230\345\274\272.md" @@ -1,300 +1,300 @@ -# 第二周-第二节课 - -## 字符串(字符序列)和字节序列 - -- 字符"ni" - - - 由于历史原因, 将字符定义为`unicode`字符还不够准确, 但是未来字符的定义一定是`unicode`字符 - -- 字节 - - 就是字符的二进制表现形式 - -- 码位 - - 我们计算机显示的实际上是码位 - - ``` - >>> '你好'.encode("unicode_escape").decode() - '\\u4f60\\u597d' - >>> - >>> '\u4f60\u597d' - '你好' - ``` - - - `UNICODE`标准中以4~6个十六进制数字表示 - -- 编码 - - - 字符序列(string) -> 字节序列(bytes) -------------编码(encode) - - ``` - >>> "你好".encode("utf-8") - b'\xe4\xbd\xa0\xe5\xa5\xbd' - ``` - - - 字节序列(bytes) -> 字符序列(string) -------------解码(decode) - - ``` - >>> b - b'\xe4\xbd\xa0\xe5\xa5\xbd' - >>> b.decode("utf") - '你好' - ``` - -- 编码错误 - - - 乱码和混合编码 - - - 检查编码 - - 没有办法通过字节序列来得出编码格式, 都是统计学来预估当前的编码 - - ``` - # 安装chardet - pip install chardet - - # 导入charet - >>> import chardet - >>> chardet.detect(b) - ``` - - - 解决乱码和混合编码 - - - 忽略错误编码 - - ``` - >>> b_2.decode("utf-8", errors='ignore') - '你好' - ``` - - - 利用鬼符来替换 - - ``` - >>> b_2.decode("utf-8", errors='replace') - '你好��' - ``` - - - -## 字符串的CRUD操作 - -``` -通过dir("")可以查看当前字符串的操作方法 -``` - -- Create(创建) - - - `+` - - ``` - >>> a = "a" - >>> id(a) - 22951584 - >>> a = a + "b" - >>> id(a) - 60513280 - >>> a - 'ab' - ``` - - - `+=` - - ``` - a += "b" 就是 a = a + "b" 省略写法 - ``` - -- Retrieve(检索) - - - 根据索引获取字符 - - 在计算机语言当中, 索引值是从0开始数的 - - ``` - >>> a = "hello, world" - >>> a[1] - 'e' - ``` - - - find和index(获取目标字符的索引值) - - ``` - >>> a.find("e") - 1 - >>> a.find("!") #找不到为-1 - -1 - - # 找不到目标字符时, index会报错 - >>> a.index("!") - Traceback (most recent call last): - File "", line 1, in - ValueError: substring not found - ``` - - - startwith和endwith - - ``` - >>> f = "2020-11-22-xxxxx" - >>> f.startswith("2020-11-22") - True - >>> f = "xxxxx.jpg" - >>> f.endswith("jpg") - True - ``` - -- UPDATE(更新) - - - replace(替换) - - 返回的是一个新的字符串 - - ``` - a.replace("wer", "wor") - ``` - - - split(分割) - - ``` - >>> a = "<>, <>, <>" - >>> a.split(",") - ['<>', ' <>', ' <>'] - ``` - - - join(拼接) - - ``` - >>> b - ['<>', ' <>', ' <>'] - >>> ",".join(b) - '<>, <>, <>' - ``` - -- DELETE(删除) - - - strip #去皮 - - ``` - >>> a - ' hello, world ' - >>> a.strip() - 'hello, world' - >>> - - ``` - - - lstrip - - - rstrip - -## 字符串的输出和输入 - -- 保存到文件 - - ``` - # open函数打开一个文件, 没有文件会新建, 但是路劲不对会报错 - # 指定文件名, 方法(读, 写, 追加), 编码格式 - output = open("output.txt", "w", encoding="utf-8") - content = "hello, world" - # 正式写入文件 - output.write(content) - # 关闭文件句柄 - output.close() - ``` - -- 读取文件 - - ``` - input = open("output.txt", "r", encoding="utf-8") - # 获取文件中的内容 - content = input.read() - print(content) - - # 暂时理解为只能读取一遍 - content_2 = input.read() - print(content_2) - ``` - -- 追加文件 - - ``` - output = open("output.txt", "a", encoding="utf-8") - content = "\nhello, world" - # 正式写入文件 - output.write(content) - # 关闭文件句柄 - output.close() - ``` - -## 字符串的格式化输出 - -- format - - - 按传入参数默认顺序 - - ``` - a = "ping" - b = "pong" - - "play pingpong: {}, {}".format(a, b) - ``` - - - 按指定参数索引 - - ``` - a = "ping" - b = "pong" - - "play pingpong: {0}, {1}, {0}, {1}".format(a, b) - ``` - - - 按关键词参数 - - ``` - a = "ping" - b = "pong" - - print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) - ``` - - - 按变量(推荐, 但是只有3.6以上才可以使用) - - ``` - a = "ping" - b = "pong" - - print(f"playing pingpong: {a}, {b}") - ``` - - - 小数的表示 - - ``` - >>> "{:.2f}".format(3.14159) - '3.14' - >>> - ``` - -- % - - ``` - >>> "playing %s %s" % ("ping", "pong") - 'playing ping pong' - - ``` - -## 课后作业 - -- 练习字符串的编码和解码 - -- 练习字符串的CRUD - -- 练习字符串的格式化 - - ``` - content = """ - >>> "playing %s %s" % ("ping", "pong") - 'playing ping pong' - - """ - ``` - +# 第二周-第二节课 + +## 字符串(字符序列)和字节序列 + +- 字符"ni" + + - 由于历史原因, 将字符定义为`unicode`字符还不够准确, 但是未来字符的定义一定是`unicode`字符 + +- 字节 + + 就是字符的二进制表现形式 + +- 码位 + + 我们计算机显示的实际上是码位 + + ``` + >>> '你好'.encode("unicode_escape").decode() + '\\u4f60\\u597d' + >>> + >>> '\u4f60\u597d' + '你好' + ``` + + - `UNICODE`标准中以4~6个十六进制数字表示 + +- 编码 + + - 字符序列(string) -> 字节序列(bytes) -------------编码(encode) + + ``` + >>> "你好".encode("utf-8") + b'\xe4\xbd\xa0\xe5\xa5\xbd' + ``` + + - 字节序列(bytes) -> 字符序列(string) -------------解码(decode) + + ``` + >>> b + b'\xe4\xbd\xa0\xe5\xa5\xbd' + >>> b.decode("utf") + '你好' + ``` + +- 编码错误 + + - 乱码和混合编码 + + - 检查编码 + + 没有办法通过字节序列来得出编码格式, 都是统计学来预估当前的编码 + + ``` + # 安装chardet + pip install chardet + + # 导入charet + >>> import chardet + >>> chardet.detect(b) + ``` + + - 解决乱码和混合编码 + + - 忽略错误编码 + + ``` + >>> b_2.decode("utf-8", errors='ignore') + '你好' + ``` + + - 利用鬼符来替换 + + ``` + >>> b_2.decode("utf-8", errors='replace') + '你好��' + ``` + + + +## 字符串的CRUD操作 + +``` +通过dir("")可以查看当前字符串的操作方法 +``` + +- Create(创建) + + - `+` + + ``` + >>> a = "a" + >>> id(a) + 22951584 + >>> a = a + "b" + >>> id(a) + 60513280 + >>> a + 'ab' + ``` + + - `+=` + + ``` + a += "b" 就是 a = a + "b" 省略写法 + ``` + +- Retrieve(检索) + + - 根据索引获取字符 + + 在计算机语言当中, 索引值是从0开始数的 + + ``` + >>> a = "hello, world" + >>> a[1] + 'e' + ``` + + - find和index(获取目标字符的索引值) + + ``` + >>> a.find("e") + 1 + >>> a.find("!") #找不到为-1 + -1 + + # 找不到目标字符时, index会报错 + >>> a.index("!") + Traceback (most recent call last): + File "", line 1, in + ValueError: substring not found + ``` + + - startwith和endwith + + ``` + >>> f = "2020-11-22-xxxxx" + >>> f.startswith("2020-11-22") + True + >>> f = "xxxxx.jpg" + >>> f.endswith("jpg") + True + ``` + +- UPDATE(更新) + + - replace(替换) + + 返回的是一个新的字符串 + + ``` + a.replace("wer", "wor") + ``` + + - split(分割) + + ``` + >>> a = "<>, <>, <>" + >>> a.split(",") + ['<>', ' <>', ' <>'] + ``` + + - join(拼接) + + ``` + >>> b + ['<>', ' <>', ' <>'] + >>> ",".join(b) + '<>, <>, <>' + ``` + +- DELETE(删除) + + - strip #去皮 + + ``` + >>> a + ' hello, world ' + >>> a.strip() + 'hello, world' + >>> + + ``` + + - lstrip + + - rstrip + +## 字符串的输出和输入 + +- 保存到文件 + + ``` + # open函数打开一个文件, 没有文件会新建, 但是路劲不对会报错 + # 指定文件名, 方法(读, 写, 追加), 编码格式 + output = open("output.txt", "w", encoding="utf-8") + content = "hello, world" + # 正式写入文件 + output.write(content) + # 关闭文件句柄 + output.close() + ``` + +- 读取文件 + + ``` + input = open("output.txt", "r", encoding="utf-8") + # 获取文件中的内容 + content = input.read() + print(content) + + # 暂时理解为只能读取一遍 + content_2 = input.read() + print(content_2) + ``` + +- 追加文件 + + ``` + output = open("output.txt", "a", encoding="utf-8") + content = "\nhello, world" + # 正式写入文件 + output.write(content) + # 关闭文件句柄 + output.close() + ``` + +## 字符串的格式化输出 + +- format + + - 按传入参数默认顺序 + + ``` + a = "ping" + b = "pong" + + "play pingpong: {}, {}".format(a, b) + ``` + + - 按指定参数索引 + + ``` + a = "ping" + b = "pong" + + "play pingpong: {0}, {1}, {0}, {1}".format(a, b) + ``` + + - 按关键词参数 + + ``` + a = "ping" + b = "pong" + + print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) + ``` + + - 按变量(推荐, 但是只有3.6以上才可以使用) + + ``` + a = "ping" + b = "pong" + + print(f"playing pingpong: {a}, {b}") + ``` + + - 小数的表示 + + ``` + >>> "{:.2f}".format(3.14159) + '3.14' + >>> + ``` + +- % + + ``` + >>> "playing %s %s" % ("ping", "pong") + 'playing ping pong' + + ``` + +## 课后作业 + +- 练习字符串的编码和解码 + +- 练习字符串的CRUD + +- 练习字符串的格式化 + + ``` + content = """ + >>> "playing %s %s" % ("ping", "pong") + 'playing ping pong' + + """ + ``` + - 将content内容保存到本地文件 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232_5\347\217\255_\345\210\230\345\274\272_\346\217\220\351\227\256.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232_5\347\217\255_\345\210\230\345\274\272_\346\217\220\351\227\256.md" index 28cb546685bffa44fb254fccdce2ffb7da988c6d..83899705e0898c5eaf019202a9a5d3eaca66c75c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232_5\347\217\255_\345\210\230\345\274\272_\346\217\220\351\227\256.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\210\230\345\274\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\23212.21-12.27/5\347\217\255_\345\210\230\345\274\272-\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\350\257\276\344\275\234\344\270\232_5\347\217\255_\345\210\230\345\274\272_\346\217\220\351\227\256.md" @@ -1,19 +1,19 @@ -问题1. 请问,字符串编码在编码区为什么跑不了?(只能在Terminal上直接出结果?) - -![image-20210110141656900](C:\Users\Leo\AppData\Roaming\Typora\typora-user-images\image-20210110141656900.png) - -问题2,字符串解码 - -``` ->>> '中国上海'.encode("utf-8") -b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' ->>> b.decode("utf") -Traceback (most recent call last): - File "", line 1, in -AttributeError: 'str' object has no attribute 'decode' -# 解码过程 str 没有对应的 decode? 请问一下,这个解码报错的原因 ->>> b -'ä¸\xadå\x9b½ä¸\x8aæµ·' - -``` - +问题1. 请问,字符串编码在编码区为什么跑不了?(只能在Terminal上直接出结果?) + +![image-20210110141656900](C:\Users\Leo\AppData\Roaming\Typora\typora-user-images\image-20210110141656900.png) + +问题2,字符串解码 + +``` +>>> '中国上海'.encode("utf-8") +b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x8a\xe6\xb5\xb7' +>>> b.decode("utf") +Traceback (most recent call last): + File "", line 1, in +AttributeError: 'str' object has no attribute 'decode' +# 解码过程 str 没有对应的 decode? 请问一下,这个解码报错的原因 +>>> b +'ä¸\xadå\x9b½ä¸\x8aæµ·' + +``` + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/main.py" index 832824b9e5e9b6eb20f211b8c681e3a0fad9f409..394f073102c4d0c9767abeb4a93a7900bb086585 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/main.py" @@ -1,30 +1,30 @@ -# int -a = int('1') - -# float -b = float('1.0') - -# string -c = str("abc") -d = str('d') - -# boolean -e = bool(2) - -# list -l =[a, b, c, e, a,bin(2),None] - -# tuple -t = (a, b, c, e, b,bin(2),None) - -# dict -d = {1: a,3: b,4: c,5: e,6:bin(2),7:None} - -# set -s = set(l) - - -print(l) -print(t) -print(d) +# int +a = int('1') + +# float +b = float('1.0') + +# string +c = str("abc") +d = str('d') + +# boolean +e = bool(2) + +# list +l =[a, b, c, e, a,bin(2),None] + +# tuple +t = (a, b, c, e, b,bin(2),None) + +# dict +d = {1: a,3: b,4: c,5: e,6:bin(2),7:None} + +# set +s = set(l) + + +print(l) +print(t) +print(d) print(s) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 83b74e1767adb0b73d9ffb94d8bfbef57949d1b7..c3a468887d6594c7180e42e4d47bb573bbd22efa 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\23212.14-12.20/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232/\347\254\254\344\270\200\345\221\250\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,213 +1,213 @@ -## 第一周第三节课-随堂笔记 - -## 变量和赋值 - -- 什么是变量 - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可重新赋值 - -- 为变量赋值 - - - 通过=来赋值 - - ``` - x=3 - ``` - - - 被重新赋值之后的值去哪了 - - 被系统回收了 - -- python常量 - - python没有常量这个数据类型 - - 程序员之间约定命名为大写字母的为常量 - -## python的六大基本类型 - -- 强调基本的原因数据类型和数据结构指向的范围更加广泛,不要产生错误的认知,形成思维定式 - -- 通过type()函数来查看当前变量的数据类型 - - - Int(整数) - - ``` - int('1') - ``` - - - float(浮点数) - - ``` - float('1.0') - float('INF') - ``` - - - 因为计算机内部只认识1和100,所以浮点数强调的是小数的表现形式 - - - string(字符串,字符序列) - - ``` - str(x) - ``` - - - 在有些语言中,单个字符也是一个基本数据类型(char) - - 有序的 - - 如何表示字符串 - - “ ”(可以在命令行中换行) - - ’ ‘ - - - 转义字符 - - 告诉python解释器,我们当前要表示的是一个字符或者特殊字符 - - - 通过\来转义 - - ``` - "2\"" - "2\n" - ``` - - - boolean(布尔值) - - ``` - bool(2) - bool(0) - ``` - - 用来表示True或者false - - - True等价1 - - - false等价0 - - - bytes(二进制序列) - - 二进制的表示 - - None(空) - - - 有了false和0为什么还要none - - 因为false和0有时候也代表一种结果 - - - -## python的四大基本数据结构 - -- list(列表) - - 用来装载不同数据类型的数据结构 - - - 列表的特点 - - - 有序的 - - 可以装载任意数据类型 - - 可以更改的 - - - 如何表示list - - - 通过list()新建一个列表 - - ``` - list("hello") - ``` - - - 通过[]声明一个列表 - - ``` - a=[1,2,3] - ``` - -- tuple(元组) - - - 可以简单的认为元组就是不可修改的列表,常用来表示记录 - - 特点 - - 有序的 - - 可以装载任意数据类型 - - 不可更改 - - - 如何表示tuple - - - 通过tuple()新建一个元组 - - ``` - tuple("hello") - ``` - - - 通过(,)来声明一个元组(圆括号可以表示优先级) - - 声明单个元素的元组,要添加逗号 - - ``` - a=(1,) - ``` - -- dict(字典) - - - 字典也叫hashtable,通过hash(散列)函数传入的key值生成地址来查找value - - key->hash函数->返回value的地址->通过value地址返回value值 - - - 特点 - - - 无序 - - python3.6是有序的,无视这一点 - - - 字典中的key必须是可hash的,也就是不可更改的唯一的 - - 可以更改 - - - 表示字典 - - - 通过dict()来创建字典 - - ``` - dict(a=2) - ``` - - - 通过{}来声明一个字典 - - ``` - a={"a":2} - ``` - -- set(集合) - - - 什么是set - - set是没有value的字典 - - - 特点 - - 无序 - - 集合中的key必须是可hash的 - - 可以更改 - - 元素是唯一的 - - - 如何表示set - - - 通过set()来创建集合 - - ``` - set([1,2,3]) - ``` - - - 通过{1,2,3}来表示 - - # 课后作业 - - - 四大基本数据结构中哪些是可变的,哪些是不可变的? - - list,dict,set是可变的, tuple是不可变的。 - - - 四大基本数据结构中哪些是有序的,哪些是无序的 - - list,tuple是有序的,dict,set是无序的 - - - 创建set,list,dict,tuple实例,每个数据结构的实例需要包含六大基本类型 - +## 第一周第三节课-随堂笔记 + +## 变量和赋值 + +- 什么是变量 + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可重新赋值 + +- 为变量赋值 + + - 通过=来赋值 + + ``` + x=3 + ``` + + - 被重新赋值之后的值去哪了 + - 被系统回收了 + +- python常量 + - python没有常量这个数据类型 + - 程序员之间约定命名为大写字母的为常量 + +## python的六大基本类型 + +- 强调基本的原因数据类型和数据结构指向的范围更加广泛,不要产生错误的认知,形成思维定式 + +- 通过type()函数来查看当前变量的数据类型 + + - Int(整数) + + ``` + int('1') + ``` + + - float(浮点数) + + ``` + float('1.0') + float('INF') + ``` + + - 因为计算机内部只认识1和100,所以浮点数强调的是小数的表现形式 + + - string(字符串,字符序列) + + ``` + str(x) + ``` + + - 在有些语言中,单个字符也是一个基本数据类型(char) + - 有序的 + - 如何表示字符串 + - “ ”(可以在命令行中换行) + - ’ ‘ + + - 转义字符 + + 告诉python解释器,我们当前要表示的是一个字符或者特殊字符 + + - 通过\来转义 + + ``` + "2\"" + "2\n" + ``` + + - boolean(布尔值) + + ``` + bool(2) + bool(0) + ``` + + 用来表示True或者false + + - True等价1 + + - false等价0 + + - bytes(二进制序列) + + 二进制的表示 + + None(空) + + - 有了false和0为什么还要none + + 因为false和0有时候也代表一种结果 + + + +## python的四大基本数据结构 + +- list(列表) + + 用来装载不同数据类型的数据结构 + + - 列表的特点 + + - 有序的 + - 可以装载任意数据类型 + - 可以更改的 + + - 如何表示list + + - 通过list()新建一个列表 + + ``` + list("hello") + ``` + + - 通过[]声明一个列表 + + ``` + a=[1,2,3] + ``` + +- tuple(元组) + + - 可以简单的认为元组就是不可修改的列表,常用来表示记录 + - 特点 + - 有序的 + - 可以装载任意数据类型 + - 不可更改 + + - 如何表示tuple + + - 通过tuple()新建一个元组 + + ``` + tuple("hello") + ``` + + - 通过(,)来声明一个元组(圆括号可以表示优先级) + + 声明单个元素的元组,要添加逗号 + + ``` + a=(1,) + ``` + +- dict(字典) + + - 字典也叫hashtable,通过hash(散列)函数传入的key值生成地址来查找value + + key->hash函数->返回value的地址->通过value地址返回value值 + + - 特点 + + - 无序 + + python3.6是有序的,无视这一点 + + - 字典中的key必须是可hash的,也就是不可更改的唯一的 + - 可以更改 + + - 表示字典 + + - 通过dict()来创建字典 + + ``` + dict(a=2) + ``` + + - 通过{}来声明一个字典 + + ``` + a={"a":2} + ``` + +- set(集合) + + - 什么是set + + set是没有value的字典 + + - 特点 + - 无序 + - 集合中的key必须是可hash的 + - 可以更改 + - 元素是唯一的 + + - 如何表示set + + - 通过set()来创建集合 + + ``` + set([1,2,3]) + ``` + + - 通过{1,2,3}来表示 + + # 课后作业 + + - 四大基本数据结构中哪些是可变的,哪些是不可变的? + + list,dict,set是可变的, tuple是不可变的。 + + - 四大基本数据结构中哪些是有序的,哪些是无序的 + + list,tuple是有序的,dict,set是无序的 + + - 创建set,list,dict,tuple实例,每个数据结构的实例需要包含六大基本类型 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/3.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/3.1.py" index 7fa056abc68d89022366de0646503e14e695bb2c..2712aec5219475e81fc553704c55125f9ab304e1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/3.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/3.1.py" @@ -1,129 +1,129 @@ -#简单计数 -l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -for i in l: - print(i) -print("-----------------------------------------") - - -for i, e in enumerate(l): - print(f"index:{i}, value:{e}") -print("-----------------------------------------") - - -i = 0 -while i < 10: - print(f"sim statement:{i}") - i += 1 - -print("-----------------------------------------") - - - -i_2 = 0 -while True: - if i_2 == 20: - break - print(f"sim statement:{i_2}") - i_2 += 1 - -print("-----------------------------------------") - - -#实现斐波那契函数 -x_1=0 -x_2=1 -x_3=0 -for i in range(0, 100): - if i <2: - print(i) - else: - x_3=x_1+x_2 - print(x_3) - x_1=x_2 - x_2=x_3 - - -print("-----------------------------------------") -x_1=0 -x_2=1 -x_3=0 -i = 0 - -while i <= 100: - if i < 2: - print(i) - else: - x_3 = x_1 + x_2 - print(x_3) - x_1 = x_2 - x_2 = x_3 - i += 1 - - - -#自定义异常paramserror -class ParamsError (Exception): - pass -#加 -def add(a,b): - return a+b - - -#减 -def sub(a,b): - return a-b - -#乘 -def mul(a,b): - return a*b - -#除 -def divi(a,b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0!") - finally: - print("function my_sub end") - -#取整 -def edivi(a,b): - try: - return a // b - except ZeroDivisionError: - raise ParamsError("取整分母不可以为0!") - finally: - print("function my_sub end") - - -#取余 -def rem(a,b): - try: - return a % b - except ZeroDivisionError: - raise ParamsError("取余分母不可以为0!") - finally: - print("function my_sub end") - -a=44 - -b=0 - -#加 - -print("a加b等于"+str(add(a,b))) -#减 - -print("a减b等于"+str(sub(a,b))) -#乘 - -print("a乘b等于"+str(mul(a,b))) -#除 - -print("a除b等于"+str(divi(a,b))) -#整除 - -print("a整除b等于"+str(edivi(a,b))) -#取余 - -print("a对b取余等于"+str(rem(a,b))) +#简单计数 +l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +for i in l: + print(i) +print("-----------------------------------------") + + +for i, e in enumerate(l): + print(f"index:{i}, value:{e}") +print("-----------------------------------------") + + +i = 0 +while i < 10: + print(f"sim statement:{i}") + i += 1 + +print("-----------------------------------------") + + + +i_2 = 0 +while True: + if i_2 == 20: + break + print(f"sim statement:{i_2}") + i_2 += 1 + +print("-----------------------------------------") + + +#实现斐波那契函数 +x_1=0 +x_2=1 +x_3=0 +for i in range(0, 100): + if i <2: + print(i) + else: + x_3=x_1+x_2 + print(x_3) + x_1=x_2 + x_2=x_3 + + +print("-----------------------------------------") +x_1=0 +x_2=1 +x_3=0 +i = 0 + +while i <= 100: + if i < 2: + print(i) + else: + x_3 = x_1 + x_2 + print(x_3) + x_1 = x_2 + x_2 = x_3 + i += 1 + + + +#自定义异常paramserror +class ParamsError (Exception): + pass +#加 +def add(a,b): + return a+b + + +#减 +def sub(a,b): + return a-b + +#乘 +def mul(a,b): + return a*b + +#除 +def divi(a,b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0!") + finally: + print("function my_sub end") + +#取整 +def edivi(a,b): + try: + return a // b + except ZeroDivisionError: + raise ParamsError("取整分母不可以为0!") + finally: + print("function my_sub end") + + +#取余 +def rem(a,b): + try: + return a % b + except ZeroDivisionError: + raise ParamsError("取余分母不可以为0!") + finally: + print("function my_sub end") + +a=44 + +b=0 + +#加 + +print("a加b等于"+str(add(a,b))) +#减 + +print("a减b等于"+str(sub(a,b))) +#乘 + +print("a乘b等于"+str(mul(a,b))) +#除 + +print("a除b等于"+str(divi(a,b))) +#整除 + +print("a整除b等于"+str(edivi(a,b))) +#取余 + +print("a对b取余等于"+str(rem(a,b))) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/3.3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/3.3.py" index f98ed5ba1637cb5340aac54c8046e01bd90d0384..32cab428929f4ac9d75d458531cb754199dd4ca9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/3.3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/3.3.py" @@ -1,82 +1,82 @@ -#练习作用域之间的转换 -a=0 -b=[] -def foo(): - a=2 - #b.append(2) - #b=4 - print(b) - return None -foo() -print(a,b) - -c={} -def foo2(): - c["a"]=100 - return c -foo2() -print(c) - -d=5 -def foo3(): - global d - d=10 - print(d) -foo3() -print(d) - -print("--------------------------------") - -def f(): - total = 0 - def fo(value): - nonlocal total - total +=value - return total - print(total) - return fo -a=f() -print(a(6)) -print(a(8)) -print("----------------------------") - -# 实现一个装饰器,用来输出函数的执行时间 -import time -def clock_deco(func): - def wrap(*args): - start_time = time.time() - result = func(*args) - end_time = time.time() - print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") - return result - return wrap - -@clock_deco -def sum (a, b): - s=0 - for i in range(b+1): - s+=(a**i) - return s - -print(sum(3,5)) - -# 使用装饰器来为斐波那契函数增加缓存 -fi = {} -def cache_deco(func): - global fi - def wrap(num): - if num not in fi: - fi[num] = func(num) - return fi[num] - return wrap - -@cache_deco -def fib(x): - if x < 2: - return x - else: - return fib(x - 2) + fib(x - 1) - -print(fib(10)) -print(fib(10)) +#练习作用域之间的转换 +a=0 +b=[] +def foo(): + a=2 + #b.append(2) + #b=4 + print(b) + return None +foo() +print(a,b) + +c={} +def foo2(): + c["a"]=100 + return c +foo2() +print(c) + +d=5 +def foo3(): + global d + d=10 + print(d) +foo3() +print(d) + +print("--------------------------------") + +def f(): + total = 0 + def fo(value): + nonlocal total + total +=value + return total + print(total) + return fo +a=f() +print(a(6)) +print(a(8)) +print("----------------------------") + +# 实现一个装饰器,用来输出函数的执行时间 +import time +def clock_deco(func): + def wrap(*args): + start_time = time.time() + result = func(*args) + end_time = time.time() + print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") + return result + return wrap + +@clock_deco +def sum (a, b): + s=0 + for i in range(b+1): + s+=(a**i) + return s + +print(sum(3,5)) + +# 使用装饰器来为斐波那契函数增加缓存 +fi = {} +def cache_deco(func): + global fi + def wrap(num): + if num not in fi: + fi[num] = func(num) + return fi[num] + return wrap + +@cache_deco +def fib(x): + if x < 2: + return x + else: + return fib(x - 2) + fib(x - 1) + +print(fib(10)) +print(fib(10)) print(fi) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/3.2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/3.2.py" index d555f61ecc8e17b59797d75b152ca721f083e5e1..46c270c4eca8828e2e8a5045d30b4d22126f5a57 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/3.2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232/\347\254\254\344\270\211\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/3.2.py" @@ -1,37 +1,37 @@ -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] - -#根据grade排序 -a = classes -a. sort(key=lambda x: x["grade"]) -print(a) - -# 通过filter筛选出grade为A的同学 -b = filter(lambda x: x["grade"] == "A", classes) -print(list(b)) - - - -#通过Map函数让每个人的age加1 -def add(l): - l["age"] += 1 - return l -c = list(map(add, classes)) -print(c) - - -#斐波那契递归函数 -def f(x): - if (x <2): - return x - else: - return f(x - 1) + f(x - 2) -for i in range(30): +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + +#根据grade排序 +a = classes +a. sort(key=lambda x: x["grade"]) +print(a) + +# 通过filter筛选出grade为A的同学 +b = filter(lambda x: x["grade"] == "A", classes) +print(list(b)) + + + +#通过Map函数让每个人的age加1 +def add(l): + l["age"] += 1 + return l +c = list(map(add, classes)) +print(c) + + +#斐波那契递归函数 +def f(x): + if (x <2): + return x + else: + return f(x - 1) + f(x - 2) +for i in range(30): print(f(i), end=" ") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/9.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/9.1.py" index 92a791802a4d2fd9a2c91333d5bad9aff20dc195..cb47ea418c91c45b18022bee5bb8563d5ec52def 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/9.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/9.1.py" @@ -1,34 +1,34 @@ -from urllib.parse import quote, unquote -import requests - - -def request_jd(keyword): - url = "https://search.jd.com/Search" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers) - with open("jd_"+keyword+".html", "w", encoding="utf-8") as f: - f.write(response.text) - -#详情页 -def pars_jd(): - url = "https://item.jd.com/10025977282778.html" - params = { - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers) - with open("jd_pars.html", "w", encoding="utf-8") as f: - f.write(response.text) - - -if __name__=="__main__": - keyword_i=["键盘", "鼠标", "拖鞋", "牛仔裤", "帆布鞋", "包包", "香水", "手机", "笔记本", "帽子"] - for i in keyword_i: - request_jd(i) +from urllib.parse import quote, unquote +import requests + + +def request_jd(keyword): + url = "https://search.jd.com/Search" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers) + with open("jd_"+keyword+".html", "w", encoding="utf-8") as f: + f.write(response.text) + +#详情页 +def pars_jd(): + url = "https://item.jd.com/10025977282778.html" + params = { + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers) + with open("jd_pars.html", "w", encoding="utf-8") as f: + f.write(response.text) + + +if __name__=="__main__": + keyword_i=["键盘", "鼠标", "拖鞋", "牛仔裤", "帆布鞋", "包包", "香水", "手机", "笔记本", "帽子"] + for i in keyword_i: + request_jd(i) pars_jd() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/main.py" index 9c1b601d17eca9f592412ead66f8ba05c47a1f74..003bdffb4a96000566a36b8456c1dadc991c9857 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/main.py" @@ -1,50 +1,50 @@ -import requests -from jd_crawler.parser.search import parse_jd_item -import pymysql -import requests -from jd_crawler.settings import MYSQL_CONF,HEADERS -import sys -print(sys.path) - -# def saver(item_array): -# cursor = mysql_con.cursor() -# SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) -# VALUES (%s, %s, %s, %s, %s, %s)""" -# cursor.executemany(SQL, item_array) -# mysql_con.commit() -# cursor.close() -# -# -# -# def donwloader(task): -# """ -# 请求目标网址的组件 -# :param task: -# :return: -# """ -# url = "https://search.jd.com/Search" -# params = { -# "keyword": task -# } -# -# response = requests.get(url=url, params=params, headers=HEADERS) -# return response -# -# def main(task_array): -# """ -# 爬虫任务调度 -# :param task_array: -# :return: -# """ -# for task in task_array: -# result=donwloader(task) -# item_array=parse_jd_item(result.text) -# print("GET ITEMS", item_array) -# saver(item_array) -# -# -# if __name__=="__main__": -# # 用来代替生产者 -# mysql_con=pymysql.connect(**MYSQL_CONF) -# task_array = ["鼠标", "键盘", "显卡", "耳机"] -# main(task_array) +import requests +from jd_crawler.parser.search import parse_jd_item +import pymysql +import requests +from jd_crawler.settings import MYSQL_CONF,HEADERS +import sys +print(sys.path) + +# def saver(item_array): +# cursor = mysql_con.cursor() +# SQL = """INSERT INTO jd_search(sku_id, img, price, title, shop, icons) +# VALUES (%s, %s, %s, %s, %s, %s)""" +# cursor.executemany(SQL, item_array) +# mysql_con.commit() +# cursor.close() +# +# +# +# def donwloader(task): +# """ +# 请求目标网址的组件 +# :param task: +# :return: +# """ +# url = "https://search.jd.com/Search" +# params = { +# "keyword": task +# } +# +# response = requests.get(url=url, params=params, headers=HEADERS) +# return response +# +# def main(task_array): +# """ +# 爬虫任务调度 +# :param task_array: +# :return: +# """ +# for task in task_array: +# result=donwloader(task) +# item_array=parse_jd_item(result.text) +# print("GET ITEMS", item_array) +# saver(item_array) +# +# +# if __name__=="__main__": +# # 用来代替生产者 +# mysql_con=pymysql.connect(**MYSQL_CONF) +# task_array = ["鼠标", "键盘", "显卡", "耳机"] +# main(task_array) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/search.py" index 7f3dbbd059823eb44ac3a74bbef9af6b0f5d6084..09b063ca63ff406197835a83bf5cfeccd672be58 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/search.py" @@ -1,31 +1,31 @@ -import json - -from bs4 import BeautifulSoup - - -def parse_jd_item(html): - result = [] - - soup = BeautifulSoup(html, "lxml") - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class='p=name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" - title = title[0].text.strip() if title else "" - shop = shop[0].a.attrs['title'] if shop[0].text.strip() else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else '[]' - result.append((sku_id, img, price, title, shop, icons)) - return result - -if __name__ == "__main__": - with open(r"D:\pythonProject\py3\jd_crawler\test\search.html", "r", encoding="utf-8") as f: - html = f.read() - result = parse_jd_item(html) +import json + +from bs4 import BeautifulSoup + + +def parse_jd_item(html): + result = [] + + soup = BeautifulSoup(html, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p=name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else '[]' + result.append((sku_id, img, price, title, shop, icons)) + return result + +if __name__ == "__main__": + with open(r"D:\pythonProject\py3\jd_crawler\test\search.html", "r", encoding="utf-8") as f: + html = f.read() + result = parse_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/settings.py" index 535b5fdae9f089074bf9507db43b5d246e5f837d..d22151660fac947e84166eee468b837202ea7751 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/settings.py" @@ -1,11 +1,11 @@ -HEADERS = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", - "upgrade-insecure-requests" : "1" -} - -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "123456", - "db": "tunan_class" +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", + "upgrade-insecure-requests" : "1" +} + +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "123456", + "db": "tunan_class" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/9.2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/9.2.py" index ea4afbb1bb303178bcbd654cac41e18fa8895298..19a9ec2d75b65b03353d15adb7701a8efdade093 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/9.2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\271\235\345\221\250\344\275\234\344\270\232/\347\254\254\344\271\235\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/9.2.py" @@ -1,22 +1,22 @@ -from bs4 import BeautifulSoup - -def jd_search_parse(html): - html=html.replace("\r\n","").replace("\t","").replace("\n","") - soup = BeautifulSoup(html, "lxml") - item = soup.select("li[data-sku='7555264']")[0] - print(item.next_sibling) - print(item.previous_sibling) - print(item.parent) - print(item.children) - print(item.parent.text.strip()) - print(item.attrs) - value=item.attrs["data-sku"] - print(value) - - - - -if __name__=="__main__": - with open("jd_search.html","r",encoding="utf-8") as f: - html=f.read() +from bs4 import BeautifulSoup + +def jd_search_parse(html): + html=html.replace("\r\n","").replace("\t","").replace("\n","") + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='7555264']")[0] + print(item.next_sibling) + print(item.previous_sibling) + print(item.parent) + print(item.children) + print(item.parent.text.strip()) + print(item.attrs) + value=item.attrs["data-sku"] + print(value) + + + + +if __name__=="__main__": + with open("jd_search.html","r",encoding="utf-8") as f: + html=f.read() jd_search_parse(html) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/main.py" index 75ddcfaff28f02e7089cc30b7518cc66e5813845..d9808de9ec362cea2d8232eb367fd3fe541495f1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/main.py" @@ -1,28 +1,28 @@ -import my_calculator as cal - -a=44 - -b=15 - -#加 -c=cal.add(a,b) -print(str(a)+"加"+str(b)+"等于"+str(c)) -#减 -d=cal.sub(a,b) -print(str(a)+"减"+str(b)+"等于"+str(d)) -#乘 -e=cal.mul(a,b) -print(str(a)+"乘"+str(b)+"等于"+str(e)) -#除 -f=cal.divi(a,b) -print(str(a)+"除"+str(b)+"等于"+str(f)) -#整除 -g=cal.edivi(a,b) -print(str(a)+"整除"+str(b)+"等于"+str(g)) -#取余 -h=cal.rem(a,b) -print(str(a)+"与"+str(b)+"取余等于"+str(h)) -#平方 -i=cal.sqrt(a,b) -print(str(a)+"的"+str(b)+"次方等于"+str(i)) - +import my_calculator as cal + +a=44 + +b=15 + +#加 +c=cal.add(a,b) +print(str(a)+"加"+str(b)+"等于"+str(c)) +#减 +d=cal.sub(a,b) +print(str(a)+"减"+str(b)+"等于"+str(d)) +#乘 +e=cal.mul(a,b) +print(str(a)+"乘"+str(b)+"等于"+str(e)) +#除 +f=cal.divi(a,b) +print(str(a)+"除"+str(b)+"等于"+str(f)) +#整除 +g=cal.edivi(a,b) +print(str(a)+"整除"+str(b)+"等于"+str(g)) +#取余 +h=cal.rem(a,b) +print(str(a)+"与"+str(b)+"取余等于"+str(h)) +#平方 +i=cal.sqrt(a,b) +print(str(a)+"的"+str(b)+"次方等于"+str(i)) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/my_calculator.py" index 32e234bc72521b473c056aa3f56a5df7e6ec34ed..83e55827eeb60d6d1d7574505657ca89a46bec37 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/my_calculator.py" @@ -1,30 +1,30 @@ - -#加 -def add(a,b): - return a+b - - -#减 -def sub(a,b): - return a-b - -#乘 -def mul(a,b): - return a*b - -#除 -def divi(a,b): - return a/b - -#取整 -def edivi(a,b): - return a//b - -#平方 -def sqrt(a,b): - return a**b - - -#取余 -def rem(a,b): + +#加 +def add(a,b): + return a+b + + +#减 +def sub(a,b): + return a-b + +#乘 +def mul(a,b): + return a*b + +#除 +def divi(a,b): + return a/b + +#取整 +def edivi(a,b): + return a//b + +#平方 +def sqrt(a,b): + return a**b + + +#取余 +def rem(a,b): return a%b \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/CRUD_2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/CRUD_2.py" index fca91bf3510d3eb979acaa14d699741e4f106f7d..a05997e1cb00333cdab31dbcb3dd23e4fb8b77a2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/CRUD_2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/CRUD_2.py" @@ -1,185 +1,185 @@ -# list -a = [] -#末尾追加 -a.append(1) -print(a) - -#两个序列的拼接 -a += ["b"] -print(a) - -# 指定位置插入 -l = [1, 2, 3, 4, 5] -l.insert(3, 10) -print(l) - - -# 按索引取值 -print(a[1]) - - -# 切片 -print(l[1:4]) - - -# 列表最后一个 -print(l[-1]) - - -# 间隔取值 -l_2 = list(range(100)) -print(l_2[0:20:3]) - - -# 检索 -l_3 = ["a", "b", "c", "d", "t"] -print(l_3.index("b")) - - -# 索引赋值 -l_3[4] = "o" -print(l_3) - - -# 切片赋值 -l_3[0:3] = "1" -print(l_3) - - -# 删除末尾元素并返回 -l_3.pop() -print(l_3) - - -# 清除列表的元素,不会改变内存地址 -l_3.clear() -print(l_3) - - -# 排序1 -l_4 = [13, 1, 4, 2, 9] -l_4.sort() -print(l_4) - -# 排序2 -l_5 = [13, 1, 4, 2, 9] -l_6 = l_5.sorted() -print(l_5) -print(l_6) - -# 倒序 -l_6.reverse() -print(l_6) - - - - -# tuple -# 索引取值 -t = (4, 2, "a", "d", 5) -print(t[2]) - - -# index -print(t.index(0)) - - -# 切片 -print(t[0:3]) - - - - -# dict -# 键対值赋值 -d = {"a":3,"b":4,"c":2,"o":5} -d["t"] = 6 -print(d) - - -# 合并字典 -d_1 = {"h": 11} -d.update(d_1) -print(d) - - -# setdefault,没有key则加入新元素 -d.setdefault("k", 13) -print(d) - -# setdefault,有key则返回key值 -print(d.setdefault("a", 0)) -print(d) - - -# 键对值访问 -print(d["c"]) - -print(d.get("b")) - - -# 返回所有key -print(d.keys()) - - -# 返回所有value -print(d.values()) - - -# 返回所有键对值 -print(d.items()) - - -# 键对值赋值 -d["a"] = 55 -print(d) - -#update -d.update({"b": 200, "c": 300}) -print(d) - - -# 删除当前键对值 -d.pop("k") -print(d) - -# 返回一个item -print(d.popitem()) - - -# 清空字典 -d.clear() -print(d) - - - - -# set -s = set() -# 添加 -s.add("a") -print(s) - - -# 判断 -print("a" in s) - - -# union合并 -s_1 = {"b", "c"} -s_2 = s.union(s_1) -print(s_2) - - -# 移除 -s_2.remove("a") -print(s_2) - -s_2.discard("t") -print(s_2) - - -# 无序删除并返回 -s_2.pop() -print(s_2) - +# list +a = [] +#末尾追加 +a.append(1) +print(a) + +#两个序列的拼接 +a += ["b"] +print(a) + +# 指定位置插入 +l = [1, 2, 3, 4, 5] +l.insert(3, 10) +print(l) + + +# 按索引取值 +print(a[1]) + + +# 切片 +print(l[1:4]) + + +# 列表最后一个 +print(l[-1]) + + +# 间隔取值 +l_2 = list(range(100)) +print(l_2[0:20:3]) + + +# 检索 +l_3 = ["a", "b", "c", "d", "t"] +print(l_3.index("b")) + + +# 索引赋值 +l_3[4] = "o" +print(l_3) + + +# 切片赋值 +l_3[0:3] = "1" +print(l_3) + + +# 删除末尾元素并返回 +l_3.pop() +print(l_3) + + +# 清除列表的元素,不会改变内存地址 +l_3.clear() +print(l_3) + + +# 排序1 +l_4 = [13, 1, 4, 2, 9] +l_4.sort() +print(l_4) + +# 排序2 +l_5 = [13, 1, 4, 2, 9] +l_6 = l_5.sorted() +print(l_5) +print(l_6) + +# 倒序 +l_6.reverse() +print(l_6) + + + + +# tuple +# 索引取值 +t = (4, 2, "a", "d", 5) +print(t[2]) + + +# index +print(t.index(0)) + + +# 切片 +print(t[0:3]) + + + + +# dict +# 键対值赋值 +d = {"a":3,"b":4,"c":2,"o":5} +d["t"] = 6 +print(d) + + +# 合并字典 +d_1 = {"h": 11} +d.update(d_1) +print(d) + + +# setdefault,没有key则加入新元素 +d.setdefault("k", 13) +print(d) + +# setdefault,有key则返回key值 +print(d.setdefault("a", 0)) +print(d) + + +# 键对值访问 +print(d["c"]) + +print(d.get("b")) + + +# 返回所有key +print(d.keys()) + + +# 返回所有value +print(d.values()) + + +# 返回所有键对值 +print(d.items()) + + +# 键对值赋值 +d["a"] = 55 +print(d) + +#update +d.update({"b": 200, "c": 300}) +print(d) + + +# 删除当前键对值 +d.pop("k") +print(d) + +# 返回一个item +print(d.popitem()) + + +# 清空字典 +d.clear() +print(d) + + + + +# set +s = set() +# 添加 +s.add("a") +print(s) + + +# 判断 +print("a" in s) + + +# union合并 +s_1 = {"b", "c"} +s_2 = s.union(s_1) +print(s_2) + + +# 移除 +s_2.remove("a") +print(s_2) + +s_2.discard("t") +print(s_2) + + +# 无序删除并返回 +s_2.pop() +print(s_2) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/CRUD.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/CRUD.py" index bdbabdf8809a9e47365f362b8656a436ce10df20..a564ff7d6d4c9f6b347e5c4aac9ed45024b3ade4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/CRUD.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\214\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/CRUD.py" @@ -1,81 +1,81 @@ - -content=""" ->>> b="你好".encode("utf-8") ->>> b -b'\xe4\xbd\xa0\xe5\xa5\xbd' ->>> b.decode("utf-8") -'你好' - ->>> a="a" ->>> b="b" ->>> a+=b ->>> a -'ab' - ->>> a="hello,world" ->>> a[1] -'e' ->>> a.find("e") -1 ->>> a.find("?") --1 ->>> a.index("h") -0 ->>> a.index("?") -Traceback (most recent call last): - File "", line 1, in -ValueError: substring not found - ->>> f.startswith("2020-12-1") -True - ->>> f="xxx.jpg" ->>> f.endswith(".jpg") -True - ->>> a="hello,world" ->>> a.replace("hello","hi") -'hi,world' - - a="hello,world" ->>> a.replace("hello","hi") -'hi,world' ->>> a.split(",") -['hello', 'world'] - ->>> b="hello,world" ->>> b=b.split(",") ->>> b -['hello', 'world'] ->>> ",".join(b) -'hello,world' - ->>> a="ping" ->>> b="pong" ->>> "play pingpong:{}{}".format(a,b) -'play pingpong:pingpong' - ->>> "play pingpong:{0},{1},{0},{1}".format(a,b) -'play pingpong:ping,pong,ping,pong' - ->>> "play pingpong:{a},{b},{a},{b}".format(a='ping',b='pong') -'play pingpong:ping,pong,ping,pong' - ->>> "{:.2f}".format(3.14159) -'3.14' - ->>> "playing %s %s"%("ping","pong") -'playing ping pong' - -""" - - -output=open("output.txt","w",encoding="utf-8") -output.write(content) -output.close() - - -input=open("output.txt","r",encoding="utf-8") - -content_2=input.read() + +content=""" +>>> b="你好".encode("utf-8") +>>> b +b'\xe4\xbd\xa0\xe5\xa5\xbd' +>>> b.decode("utf-8") +'你好' + +>>> a="a" +>>> b="b" +>>> a+=b +>>> a +'ab' + +>>> a="hello,world" +>>> a[1] +'e' +>>> a.find("e") +1 +>>> a.find("?") +-1 +>>> a.index("h") +0 +>>> a.index("?") +Traceback (most recent call last): + File "", line 1, in +ValueError: substring not found + +>>> f.startswith("2020-12-1") +True + +>>> f="xxx.jpg" +>>> f.endswith(".jpg") +True + +>>> a="hello,world" +>>> a.replace("hello","hi") +'hi,world' + + a="hello,world" +>>> a.replace("hello","hi") +'hi,world' +>>> a.split(",") +['hello', 'world'] + +>>> b="hello,world" +>>> b=b.split(",") +>>> b +['hello', 'world'] +>>> ",".join(b) +'hello,world' + +>>> a="ping" +>>> b="pong" +>>> "play pingpong:{}{}".format(a,b) +'play pingpong:pingpong' + +>>> "play pingpong:{0},{1},{0},{1}".format(a,b) +'play pingpong:ping,pong,ping,pong' + +>>> "play pingpong:{a},{b},{a},{b}".format(a='ping',b='pong') +'play pingpong:ping,pong,ping,pong' + +>>> "{:.2f}".format(3.14159) +'3.14' + +>>> "playing %s %s"%("ping","pong") +'playing ping pong' + +""" + + +output=open("output.txt","w",encoding="utf-8") +output.write(content) +output.close() + + +input=open("output.txt","r",encoding="utf-8") + +content_2=input.read() print(content_2) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-T.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-T.py" index ad835b9a10e4c0135757c36adcee75b17a00732c..a7c07b2e348117f4f74e10c38eceb662142db5f5 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-T.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-T.py" @@ -1,30 +1,30 @@ -import requests -from threading import Thread -import time -from multiprocessing import process - - -result=[] -def requests_sogou(index): - time.sleep(2) - url="https://www.sogou.com/" - #body="" - headers={ - "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - #print(response) #response获得对象 - # print(response.text)#获得内容 - print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") - result.append(response) - -if __name__=="__main__": - t_array = [] - for i in range(10): - t=Thread(target=requests_sogou, args=(i,)) - t_array.append(t) - t.start() - for i in t_array: - t.join() - print("done!") - print(result) +import requests +from threading import Thread +import time +from multiprocessing import process + + +result=[] +def requests_sogou(index): + time.sleep(2) + url="https://www.sogou.com/" + #body="" + headers={ + "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + #print(response) #response获得对象 + # print(response.text)#获得内容 + print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") + result.append(response) + +if __name__=="__main__": + t_array = [] + for i in range(10): + t=Thread(target=requests_sogou, args=(i,)) + t_array.append(t) + t.start() + for i in t_array: + t.join() + print("done!") + print(result) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-p.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-p.py" index 22d211084817f143f3f9214320547ed649bcd80b..8d24fe28d1723e306f2298344de7fc943a0d3830 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-p.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/5.1-p.py" @@ -1,30 +1,30 @@ -import requests -from threading import Thread -import time -from multiprocessing import Process - - -result=[] -def requests_sogou(index): - time.sleep(2) - url="https://www.sogou.com/" - #body="" - headers={ - "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - #print(response) #response获得对象 - # print(response.text)#获得内容 - print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") - result.append(response) - -if __name__=="__main__": - p_array = [] - for i in range(10): - p=Process(target=requests_sogou, args=(i,)) - p_array.append(p) - p.start() - for i in p_array: - p.join() - print("done!") - print(result) +import requests +from threading import Thread +import time +from multiprocessing import Process + + +result=[] +def requests_sogou(index): + time.sleep(2) + url="https://www.sogou.com/" + #body="" + headers={ + "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + #print(response) #response获得对象 + # print(response.text)#获得内容 + print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") + result.append(response) + +if __name__=="__main__": + p_array = [] + for i in range(10): + p=Process(target=requests_sogou, args=(i,)) + p_array.append(p) + p.start() + for i in p_array: + p.join() + print("done!") + print(result) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3-asyncio.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3-asyncio.py" index c54237132878b08ddb39757b7fb0a5705fab9374..5177af5ac9eb48a8a65455bc6e5697b88cf325bd 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3-asyncio.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3-asyncio.py" @@ -1,26 +1,26 @@ -import asyncio - - -class Response: - staus_code = 200 - - -async def sim_request(index): - print(f"模拟发送请求 Index: {index}") - response = Response() - await asyncio.sleep(1) - print(f"request index {index}, response status_code: {response.staus_code}") - return response.staus_code - - -loop = asyncio.get_event_loop() - - -task_array = [] -for i in range(100): - task_array.append(sim_request(i)) - -result = loop.run_until_complete(asyncio.gather(*task_array)) -print(result) - +import asyncio + + +class Response: + staus_code = 200 + + +async def sim_request(index): + print(f"模拟发送请求 Index: {index}") + response = Response() + await asyncio.sleep(1) + print(f"request index {index}, response status_code: {response.staus_code}") + return response.staus_code + + +loop = asyncio.get_event_loop() + + +task_array = [] +for i in range(100): + task_array.append(sim_request(i)) + +result = loop.run_until_complete(asyncio.gather(*task_array)) +print(result) + loop.close() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3.py" index b346bc074b4cf0ec86bee673b52fa028fcde2853..26213934d030a795382b1f018f71c3ecb9479757 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/5.3.py" @@ -1,21 +1,21 @@ -def coro_avg(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -my_avg = coro_avg() -next(my_avg) -print("计算平均值") -i=1 -while True: - print(f"请输入第{i}数:") - a=int(input()) - print("当前平均值为:"+str(my_avg.send(a))) - i+=1 - +def coro_avg(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +my_avg = coro_avg() +next(my_avg) +print("计算平均值") +i=1 +while True: + print(f"请输入第{i}数:") + a=int(input()) + print("当前平均值为:"+str(my_avg.send(a))) + i+=1 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-P.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-P.py" index cdef9f176c0f3456f69a46dce2f8908540b31fe8..b5099938f467a9a10f222d7806f5a43b557377c3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-P.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-P.py" @@ -1,19 +1,19 @@ -from multiprocessing import Process, Lock - - -def save_to_file(index, lock): - with lock: - with open("test-P.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - - -if __name__ == "__main__": - process_array = [] - lock = Lock() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() +from multiprocessing import Process, Lock + + +def save_to_file(index, lock): + with lock: + with open("test-P.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + + +if __name__ == "__main__": + process_array = [] + lock = Lock() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() print("done!") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-Q.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-Q.py" index 45d7b5b72b04f7e926344cd6a417b9d4c840f990..c823064d5231abefe24ab64be3e5a5643ca1ab30 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-Q.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-Q.py" @@ -1,18 +1,18 @@ -from multiprocessing import Queue,Process - -def save_to_queue(index, my_queue): - my_queue.put(index) - - -if __name__ == "__main__": - process_array = [] - my_queue = Queue() - for i in range(26): - p = Process(target=save_to_queue, args=(65+i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - while True: +from multiprocessing import Queue,Process + +def save_to_queue(index, my_queue): + my_queue.put(index) + + +if __name__ == "__main__": + process_array = [] + my_queue = Queue() + for i in range(26): + p = Process(target=save_to_queue, args=(65+i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + while True: print(chr(my_queue.get())) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-T.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-T.py" index 3843dce0a16596dfbe6044e194d6c2ccc34fca33..8fd9a8cc280c1048c467e6cc85a181a2889f07b2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-T.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232/\347\254\254\344\272\224\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/5.2-T.py" @@ -1,19 +1,19 @@ -from multiprocessing import Process, Lock -from threading import Thread - -def save_to_file(index, lock): - with lock: - with open("test-T.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - - -if __name__ == "__main__": - t_array = [] - lock = Lock() - for i in range(10): - p = Thread(target=save_to_file, args=(i, lock)) - t_array.append(p) - p.start() - for p in t_array: - p.join() +from multiprocessing import Process, Lock +from threading import Thread + +def save_to_file(index, lock): + with lock: + with open("test-T.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + + +if __name__ == "__main__": + t_array = [] + lock = Lock() + for i in range(10): + p = Thread(target=save_to_file, args=(i, lock)) + t_array.append(p) + p.start() + for p in t_array: + p.join() print("done!") \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/parser_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/parser_test.py" index 524fc42506f9417663565fe935aa036101c04ba1..6c7f3c69b2f1b27fef9326f979a13e5f755eab4e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/parser_test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/parser_test.py" @@ -1,10 +1,10 @@ -import sys -print(sys.path) -import os -sys.path.append(os.getcwd()) -from jd_parser.search import parse_jd_item - -with open("test\search.html", "r", encoding="utf_8") as f: - html = f.read() - result = parse_jd_item(html) +import sys +print(sys.path) +import os +sys.path.append(os.getcwd()) +from jd_parser.search import parse_jd_item + +with open("test\search.html", "r", encoding="utf_8") as f: + html = f.read() + result = parse_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/4.1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/4.1.py" index 61de8185118da6520a53547dc15b578d402fc865..b54e5af3ea73338613e9e9c8754106300c57e8c2 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/4.1.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/4.1.py" @@ -1,34 +1,34 @@ -import datetime -import time - -#获取时间戳 -time_1=time.time() -#时间戳-->datetime.datetime -time_dd=datetime.datetime.fromtimestamp(time_1, tz=None) -#datetime.datetime-->str -time_str=time_dd.strftime("%Y/%m/%d %H:%M:%S") -#str-->datetime.datetime -time_datetime=datetime.datetime.strptime(time_str, "%Y/%m/%d %H:%M:%S") -#datetime.datetime-->时间戳 -time_stamp=time_datetime.timestamp() - -print("获取时间戳:", end=" ") -print(time_1) -print("时间戳-->datetime.datetime:", end=" ") -print(time_dd) -print("datetime.datetime-->str:", end=" ") -print(time_str) -print("str-->datetime.datetime:", end=" ") -print(time_datetime) -print("datetime.datetime-->时间戳:", end=" ") -print(time_stamp) - -print("----------------------------------") -# 如果传入的是`-1` , 输出就是字符串日期2020-01-02. -def get_date(day_delta): - now = datetime.datetime.now(tz=None) - if day_delta==-1: - print(now.strftime("%Y-%m-%d")) - - +import datetime +import time + +#获取时间戳 +time_1=time.time() +#时间戳-->datetime.datetime +time_dd=datetime.datetime.fromtimestamp(time_1, tz=None) +#datetime.datetime-->str +time_str=time_dd.strftime("%Y/%m/%d %H:%M:%S") +#str-->datetime.datetime +time_datetime=datetime.datetime.strptime(time_str, "%Y/%m/%d %H:%M:%S") +#datetime.datetime-->时间戳 +time_stamp=time_datetime.timestamp() + +print("获取时间戳:", end=" ") +print(time_1) +print("时间戳-->datetime.datetime:", end=" ") +print(time_dd) +print("datetime.datetime-->str:", end=" ") +print(time_str) +print("str-->datetime.datetime:", end=" ") +print(time_datetime) +print("datetime.datetime-->时间戳:", end=" ") +print(time_stamp) + +print("----------------------------------") +# 如果传入的是`-1` , 输出就是字符串日期2020-01-02. +def get_date(day_delta): + now = datetime.datetime.now(tz=None) + if day_delta==-1: + print(now.strftime("%Y-%m-%d")) + + get_date(-1) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/4.3.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/4.3.py" index 363fe9e5263291687f37de4c467abc6070db9217..52b0cda8ea0ec07613f76fee0fd156ff06f90ebb 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/4.3.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/4.3.py" @@ -1,94 +1,94 @@ -class MyMath: - # 加 - @staticmethod - def add(a, b): - return a + b - - # 减 - @staticmethod - def sub(a, b): - return a - b - - # 乘 - @staticmethod - def mul(a, b): - return a * b - - # 除 - @staticmethod - def divi(a, b): - return a / b - - # 幂 - @staticmethod - def po(a, b): - return a ** b - - # 开方 - @staticmethod - def st(a, b): - return a ** (1 / b) - - -x = 27 -y = 3 -print(f"x+y={MyMath.add(x, y)}") -print(f"x-y={MyMath.sub(x, y)}") -print(f"x×y={MyMath.mul(x, y)}") -print(f"x÷y={MyMath.divi(x, y)}") -print(f"x的y次方={MyMath.po(x, y)}") -print(f"x的开y次方={MyMath.st(x, y)}") - -print("---------------------------------") - -class Taxi: - number = None - __load = None - distance = None - __address = None - - def __init__(self, name, num, load,dis,addr): - self.name = name - self.number=num - self.__load=load - self.distance=dis - self.__address=addr - - - - @classmethod - def goaddress(self): - return print(f"到达目的地{self.__address}") - - - def __str__(self): - self.goaddress() - return f"{self.name}车牌号为{self.number}的车行驶了{self.distance}公里" - - -class Didi(Taxi): - - def __init__(self, num, load,dis,addr): - self.name = "嘀嘀打车" - self.number=num - self.__load=load - self.distance=dis - self.__address=addr - - -class Uber(Taxi): - def __init__(self, num, load ,dis,addr): - self.name = "Uber优步中国" - self.number=num - self.__load=load - self.distance=dis - self.__address=addr - - - - - -a=Uber(467237875 ,"1000kg" ,100 ,"世界之窗") - -print(a) - +class MyMath: + # 加 + @staticmethod + def add(a, b): + return a + b + + # 减 + @staticmethod + def sub(a, b): + return a - b + + # 乘 + @staticmethod + def mul(a, b): + return a * b + + # 除 + @staticmethod + def divi(a, b): + return a / b + + # 幂 + @staticmethod + def po(a, b): + return a ** b + + # 开方 + @staticmethod + def st(a, b): + return a ** (1 / b) + + +x = 27 +y = 3 +print(f"x+y={MyMath.add(x, y)}") +print(f"x-y={MyMath.sub(x, y)}") +print(f"x×y={MyMath.mul(x, y)}") +print(f"x÷y={MyMath.divi(x, y)}") +print(f"x的y次方={MyMath.po(x, y)}") +print(f"x的开y次方={MyMath.st(x, y)}") + +print("---------------------------------") + +class Taxi: + number = None + __load = None + distance = None + __address = None + + def __init__(self, name, num, load,dis,addr): + self.name = name + self.number=num + self.__load=load + self.distance=dis + self.__address=addr + + + + @classmethod + def goaddress(self): + return print(f"到达目的地{self.__address}") + + + def __str__(self): + self.goaddress() + return f"{self.name}车牌号为{self.number}的车行驶了{self.distance}公里" + + +class Didi(Taxi): + + def __init__(self, num, load,dis,addr): + self.name = "嘀嘀打车" + self.number=num + self.__load=load + self.distance=dis + self.__address=addr + + +class Uber(Taxi): + def __init__(self, num, load ,dis,addr): + self.name = "Uber优步中国" + self.number=num + self.__load=load + self.distance=dis + self.__address=addr + + + + + +a=Uber(467237875 ,"1000kg" ,100 ,"世界之窗") + +print(a) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/4.2.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/4.2.py" index 4ff73c82e65b276136e50464fe0ec95197630bbb..45dc477b4d5440f29a891fb7aaa32b8db749979b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/4.2.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232/\347\254\254\345\233\233\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/4.2.py" @@ -1,60 +1,60 @@ -class MyMath: - # 加 - def add(self, a, b): - return a + b - - # 减 - def sub(self, a, b): - return a - b - - # 乘 - def mul(self, a, b): - return a * b - - # 除 - def divi(self, a, b): - return a / b - - # 幂 - def po(self, a, b): - return a ** b - - # 开方 - def st(self, a, b): - return a ** (1 / b) - - -a = MyMath() -x = 27 -y = 3 -print(f"x+y={a.add(x, y)}") -print(f"x-y={a.sub(x, y)}") -print(f"x×y={a.mul(x, y)}") -print(f"x÷y={a.divi(x, y)}") -print(f"x的y次方={a.po(x, y)}") -print(f"x的开y次方={a.st(x, y)}") - - -class Taxi: - number = None - - def __init__(self, name): - self.name = name - - -class Didi(Taxi): - number = None - def __init__(self, name="滴滴出行"): - self.name = name - - -class Uber(Taxi): - number = None - def __init__(self, name="Uber优步中国"): - self.name = name - - -b = Didi() -c = Uber() -print(f"hail {b.name}") -print(f"hail {c.name}") +class MyMath: + # 加 + def add(self, a, b): + return a + b + + # 减 + def sub(self, a, b): + return a - b + + # 乘 + def mul(self, a, b): + return a * b + + # 除 + def divi(self, a, b): + return a / b + + # 幂 + def po(self, a, b): + return a ** b + + # 开方 + def st(self, a, b): + return a ** (1 / b) + + +a = MyMath() +x = 27 +y = 3 +print(f"x+y={a.add(x, y)}") +print(f"x-y={a.sub(x, y)}") +print(f"x×y={a.mul(x, y)}") +print(f"x÷y={a.divi(x, y)}") +print(f"x的y次方={a.po(x, y)}") +print(f"x的开y次方={a.st(x, y)}") + + +class Taxi: + number = None + + def __init__(self, name): + self.name = name + + +class Didi(Taxi): + number = None + def __init__(self, name="滴滴出行"): + self.name = name + + +class Uber(Taxi): + number = None + def __init__(self, name="Uber优步中国"): + self.name = name + + +b = Didi() +c = Uber() +print(f"hail {b.name}") +print(f"hail {c.name}") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14-12.20/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 12.20/third homework.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14-12.20/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 12.20/third homework.py" index 9093f18524239732339976f78101d7cb26c0f2d5..a68eb3fd69ae262db2f571f984596b10acc72f74 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14-12.20/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 12.20/third homework.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14-12.20/\347\254\254\344\270\200\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 12.20/third homework.py" @@ -1,29 +1,29 @@ -# 四大基本数据结构中 list 和 tuple是有序的, dict 和 set 是无序的 -# 四大数据结构, 除了 tuple不可更改,其余的都是可以更改的 - -age = 24 #整数 -money = 99.99 #浮点数 -T = bool(1) -F = bool(0) #布尔值 -er = bytes("so many money".encode("utf-8")) #二进制 -c = None - -list1 = ["I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c] -print(list1) - -tuple1 = ("I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c) -print(tuple1) - -set1 = {"I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c} -print(set1) - -dict1 = {"age": 24, "money": 99.99, "T": bool(1), - "er": bytes("so many money".encode("utf-8")), "c": None} -print(dict1) - -echo(list1) - - - - - +# 四大基本数据结构中 list 和 tuple是有序的, dict 和 set 是无序的 +# 四大数据结构, 除了 tuple不可更改,其余的都是可以更改的 + +age = 24 #整数 +money = 99.99 #浮点数 +T = bool(1) +F = bool(0) #布尔值 +er = bytes("so many money".encode("utf-8")) #二进制 +c = None + +list1 = ["I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c] +print(list1) + +tuple1 = ("I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c) +print(tuple1) + +set1 = {"I am", age, "years old, and I make", money, "money today.", er, "so I am very happy", T, c} +print(set1) + +dict1 = {"age": 24, "money": 99.99, "T": bool(1), + "er": bytes("so many money".encode("utf-8")), "c": None} +print(dict1) + +echo(list1) + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\200\350\212\202\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200/\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\200\350\212\202\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200/\347\254\254\344\270\200\350\212\202" index 046ef8785bafc511219e0d5e6f451f58238eadae..8e6f1e17c376fe61952acc414036b6cce1f7bbf7 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\200\350\212\202\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200/\347\254\254\344\270\200\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\200\350\212\202\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200/\347\254\254\344\270\200\350\212\202" @@ -1,8 +1,8 @@ -关系型数据库:建立在关系模型上的数据库,用来存储和管理结构化的数据 -非关系型数据库(Nosql):创建在Nosql系统(键对值)基础上的数据库,既可以存储结构化数据,也可以处理非结构化数据 -事务也就是关系型数据库,特点: ACID -Atomic:原子性, 不可分割的操作,只有完成和不完成,不存在其他中间态 -Consistence:一致性,事务A和事务B同时运行,无论谁先结束,数据库都会到达一致 -Isolation:隔离性, 解决多个事务同时对数据进行读写和修改的能力 -Duration:持久性,某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能被持久化的保存下来 - +关系型数据库:建立在关系模型上的数据库,用来存储和管理结构化的数据 +非关系型数据库(Nosql):创建在Nosql系统(键对值)基础上的数据库,既可以存储结构化数据,也可以处理非结构化数据 +事务也就是关系型数据库,特点: ACID +Atomic:原子性, 不可分割的操作,只有完成和不完成,不存在其他中间态 +Consistence:一致性,事务A和事务B同时运行,无论谁先结束,数据库都会到达一致 +Isolation:隔离性, 解决多个事务同时对数据进行读写和修改的能力 +Duration:持久性,某个事务一旦提交,无论数据库崩溃还是其他原因,该事务的结果都能被持久化的保存下来 + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\211\350\212\202CRUD \351\233\206\345\220\210\346\223\215\344\275\234/CRUD\346\223\215\344\275\234.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\211\350\212\202CRUD \351\233\206\345\220\210\346\223\215\344\275\234/CRUD\346\223\215\344\275\234.py" index 3aab04510704018287ea5c1a0e78a73973ed4aaa..a2ba7c8f3e60bfea181e863ace5f12244b9b4364 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\211\350\212\202CRUD \351\233\206\345\220\210\346\223\215\344\275\234/CRUD\346\223\215\344\275\234.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\203\345\221\250 1.25-131/\347\254\254\344\270\211\350\212\202CRUD \351\233\206\345\220\210\346\223\215\344\275\234/CRUD\346\223\215\344\275\234.py" @@ -1,91 +1,91 @@ -CRUD操作 - -Cerate -insert into 表名(字段1,字段2) values(值1,值2) - -Retrive - -获取所有记录 -select 字段 from 表名 -select * from 表名 - -条件查询(where, and, or) - -select 字段 from 表名 where 字段=值 //表达式 - -模糊匹配(like, %) -select 字段 from 表名 where 表达式 -select 字段 from 表名 where name like "m%" - -限制返回条数(limit) -查询表达式 limit 数量 -select 字段 from 表名 where 表达式 limit 1 - -过滤重复值(distinct) -对查询的结果进行过滤 -select distinct 字段 from 表名 [条件语句] - -排序问题 -默认升序 -select 字段 from 表名 order by 字段 -降序:select 字段 from 表名 order by 字段 desc - -获取查询结果的条数(count) -select count(*) from 表名 [条件语句] - -Update(更新) -update 表名 set 字段=新值 where 表达式 - -Delete(删除) -delect from 表名 where 表达式 - -集合操作 - -并集(union) -子语句select 必须有相同数量的字段,和相同的数据类型 -select 字段1 from 表名1 where 字段1 is not null -union -select 字段2 from 表名2 where 字段2 is not null - -交集(join, inner join) -select s1.字段1 from -(select 字段1 from 表名1 where 字段1 is not null) as s1 -join -(select 字段2 from 表名2 where 字段2 is not null) as s2 -on s1.字段1=s2.字段2 - -差集(left join, right join) - -A对B 的差集 -select s1.name from -(select name from class_1 where name is not null) as s1 -left join -(select name from class_2 where name is not null) as s2 -on s1.name=s2.name -where s2.name is null // 限定s1有, s2没有的记录 - -B对A的差集 -select s2.name from -(select name from class_1 where name is not null) as s1 -right join -(select name from calss_2 where name is not null) as s2 -on s1.name=s.name -where s1.name is null - -补集 -A与B的补集=A对B的差集 + B对A的差集 -selec s1.name from -(select name from calss_1 where name is not null) as s1 -left join -(select name from class_2 where name is not null) as s2 -on s1.name = s2.name -where s2.name is null - -union - -select s2.name from -(select name from class_1 where name is not null) as s1 -right join -(select name from class_2 where name is not null) as s2 -on s1.name = s2.name -where s1.name is null +CRUD操作 + +Cerate +insert into 表名(字段1,字段2) values(值1,值2) + +Retrive + +获取所有记录 +select 字段 from 表名 +select * from 表名 + +条件查询(where, and, or) + +select 字段 from 表名 where 字段=值 //表达式 + +模糊匹配(like, %) +select 字段 from 表名 where 表达式 +select 字段 from 表名 where name like "m%" + +限制返回条数(limit) +查询表达式 limit 数量 +select 字段 from 表名 where 表达式 limit 1 + +过滤重复值(distinct) +对查询的结果进行过滤 +select distinct 字段 from 表名 [条件语句] + +排序问题 +默认升序 +select 字段 from 表名 order by 字段 +降序:select 字段 from 表名 order by 字段 desc + +获取查询结果的条数(count) +select count(*) from 表名 [条件语句] + +Update(更新) +update 表名 set 字段=新值 where 表达式 + +Delete(删除) +delect from 表名 where 表达式 + +集合操作 + +并集(union) +子语句select 必须有相同数量的字段,和相同的数据类型 +select 字段1 from 表名1 where 字段1 is not null +union +select 字段2 from 表名2 where 字段2 is not null + +交集(join, inner join) +select s1.字段1 from +(select 字段1 from 表名1 where 字段1 is not null) as s1 +join +(select 字段2 from 表名2 where 字段2 is not null) as s2 +on s1.字段1=s2.字段2 + +差集(left join, right join) + +A对B 的差集 +select s1.name from +(select name from class_1 where name is not null) as s1 +left join +(select name from class_2 where name is not null) as s2 +on s1.name=s2.name +where s2.name is null // 限定s1有, s2没有的记录 + +B对A的差集 +select s2.name from +(select name from class_1 where name is not null) as s1 +right join +(select name from calss_2 where name is not null) as s2 +on s1.name=s.name +where s1.name is null + +补集 +A与B的补集=A对B的差集 + B对A的差集 +selec s1.name from +(select name from calss_1 where name is not null) as s1 +left join +(select name from class_2 where name is not null) as s2 +on s1.name = s2.name +where s2.name is null + +union + +select s2.name from +(select name from class_1 where name is not null) as s1 +right join +(select name from class_2 where name is not null) as s2 +on s1.name = s2.name +where s1.name is null diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/.py" index f64e14061afe40b8251d5febf8cb7d62f5668cda..f324892640bd91ce1b64e88276ffc0d9af125e58 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/.py" @@ -1,71 +1,71 @@ -# else语句 -print('\nelse 语句') - -e = 1 -while e < 10: - print(e) - e += 1 -else: - print('i is no longer than 10') - - -# 作业 - -#for循环计数 - -list = [1, 2, 3, 4, 5, 6, 7, 8] -for i in list: - print(i) - -#break 语句 -for e in list: - print(e) - if e == 4: #如果 e = 4, 停止循环 - break - -#continue -print('\n continue') -for x in list: - if x == 5: - continue # 到5的时候,继续循环, 不打印5 - print(x) - -# 获取索引值和值 -for a, b in enumerate(list): - print(f'index:{a}, value:{b}') - -# while 循环 -a = 1 -while a < 10: - print(a) - a += 1 - -b = 0 -while b < 10: - print(b) - b += 1 - if b == 5: # 当 b = 5,停止循环 - break - -b = 0 -while b < 10: - print(b) - b += 1 -else: - print('b is no longer than 10') - -#斐波那契函数 - -# for, 如何实现函数, 真的不是很懂, 代码看的是 嘘嘘 的 -a = 1 #我的理解, 前三个数字为0, 1, 1, 所以设置 a = 1, b = 1, c = 0 -b = 1 -c = 0 -print(a, end=" ") -print(b, end=" ") # 这步就不懂了 -for i in range(3, 101): # i 在 3 - 101 范围内 - c = a + b - a = b - b = c # 不懂了 - print(c, end=" ") - +# else语句 +print('\nelse 语句') + +e = 1 +while e < 10: + print(e) + e += 1 +else: + print('i is no longer than 10') + + +# 作业 + +#for循环计数 + +list = [1, 2, 3, 4, 5, 6, 7, 8] +for i in list: + print(i) + +#break 语句 +for e in list: + print(e) + if e == 4: #如果 e = 4, 停止循环 + break + +#continue +print('\n continue') +for x in list: + if x == 5: + continue # 到5的时候,继续循环, 不打印5 + print(x) + +# 获取索引值和值 +for a, b in enumerate(list): + print(f'index:{a}, value:{b}') + +# while 循环 +a = 1 +while a < 10: + print(a) + a += 1 + +b = 0 +while b < 10: + print(b) + b += 1 + if b == 5: # 当 b = 5,停止循环 + break + +b = 0 +while b < 10: + print(b) + b += 1 +else: + print('b is no longer than 10') + +#斐波那契函数 + +# for, 如何实现函数, 真的不是很懂, 代码看的是 嘘嘘 的 +a = 1 #我的理解, 前三个数字为0, 1, 1, 所以设置 a = 1, b = 1, c = 0 +b = 1 +c = 0 +print(a, end=" ") +print(b, end=" ") # 这步就不懂了 +for i in range(3, 101): # i 在 3 - 101 范围内 + c = a + b + a = b + b = c # 不懂了 + print(c, end=" ") + 希望老师解答一下 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\350\212\202/\344\275\234\347\224\250\345\237\237 \351\227\255\345\214\205 \350\243\205\351\245\260\345\231\250" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\350\212\202/\344\275\234\347\224\250\345\237\237 \351\227\255\345\214\205 \350\243\205\351\245\260\345\231\250" index f5e635d9a7a3e61b8585aa126672ee81764be482..86d36adee83129918e913338debb6a14d8e0e535 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\350\212\202/\344\275\234\347\224\250\345\237\237 \351\227\255\345\214\205 \350\243\205\351\245\260\345\231\250" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\270\211\345\221\250\347\254\254\344\270\211\350\212\202/\344\275\234\347\224\250\345\237\237 \351\227\255\345\214\205 \350\243\205\351\245\260\345\231\250" @@ -1,41 +1,41 @@ -#LEGB法则 -#Local: 局部变量(作用域) -#在函数def foo(): 下的局部变量 -#Eclosing: 嵌套作用域 -#是相对概念, 相对上一级函数是局部变量, 相对下一级函数是全局变量, 实为自由变量 -#Global:全局作用域 -#作用与当前文件——模块 -#Builtin:内置作用域 -#python内置,在python环境中都可以调用 - -#实现一个计时装饰器 -import time - -def clock_it(func, *args): - start_time = time.time() - result = func(*args) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - - -def clock_it_deco(func): #装饰 func - def wrapper(*args): # 接收参数 - start_time = time.time() - result = func(*args) # 执行 - end_time = time.time() - print(f"{func.__name__} 完成时间: {format(end_time - start_time, '.2f')} s") - return result - return wrapper # 将嵌套的函数抛出去, 延伸被装饰函数 func 的作用域 - - -@clock_it_deco # 调用装饰器 -def foo(a, b): - count = 1 - while True: - if count > a ** b: - break - count += 1 -foo(10, 5) - +#LEGB法则 +#Local: 局部变量(作用域) +#在函数def foo(): 下的局部变量 +#Eclosing: 嵌套作用域 +#是相对概念, 相对上一级函数是局部变量, 相对下一级函数是全局变量, 实为自由变量 +#Global:全局作用域 +#作用与当前文件——模块 +#Builtin:内置作用域 +#python内置,在python环境中都可以调用 + +#实现一个计时装饰器 +import time + +def clock_it(func, *args): + start_time = time.time() + result = func(*args) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + + +def clock_it_deco(func): #装饰 func + def wrapper(*args): # 接收参数 + start_time = time.time() + result = func(*args) # 执行 + end_time = time.time() + print(f"{func.__name__} 完成时间: {format(end_time - start_time, '.2f')} s") + return result + return wrapper # 将嵌套的函数抛出去, 延伸被装饰函数 func 的作用域 + + +@clock_it_deco # 调用装饰器 +def foo(a, b): + count = 1 + while True: + if count > a ** b: + break + count += 1 +foo(10, 5) + # 斐波那契还是有点难理解 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\272\214\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\272\214\350\212\202" index d498ce5d5c72a04359dfbfef1605def7ed6a42be..e7541940a1931c9c47c736496ef27e02f38da5a3 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\272\214\350\212\202" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\270\211\345\221\250\344\275\234\344\270\232 12.28 - 1.3/\347\254\254\344\272\214\350\212\202" @@ -1,40 +1,40 @@ -# 按 grade 排序 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] - -from pprint import pprint -classes.sort(key=lambda x: x["grade"]) -pprint(classes) - -#筛选 grade 为 A -print('\n') -from pprint import pprint -l = classes -f = filter(lambda x: x['grade']=='A', l) -pprint(list(f)) - -#年龄+1 -print('\n') -def add(n): - n['age'] += 1 - return n - -s = map(add, l) -from pprint import pprint -pprint(list(s)) - -#斐波那契 -print('\n') - -def fibs(n): - if n < 20: - return (n-1) + (n-2) - +# 按 grade 排序 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + +from pprint import pprint +classes.sort(key=lambda x: x["grade"]) +pprint(classes) + +#筛选 grade 为 A +print('\n') +from pprint import pprint +l = classes +f = filter(lambda x: x['grade']=='A', l) +pprint(list(f)) + +#年龄+1 +print('\n') +def add(n): + n['age'] += 1 + return n + +s = map(add, l) +from pprint import pprint +pprint(list(s)) + +#斐波那契 +print('\n') + +def fibs(n): + if n < 20: + return (n-1) + (n-2) + print(fibs(20)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/main.py" index 78c173a117a1544338be01c50f1776a75dc13c4a..b8905d82f38d7972193062c21ff786cfa8d11b0c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/main.py" @@ -1,49 +1,49 @@ -#程序入口模块 -import random -import requests -from jd_code.parase.search import parase_jd_item -from jd_code.settings import MYSQL_CONF,HEADERS -import pymysql - -def saver(item_array): - """ - 持久化爬取结果 - :param item_array: - :return: - """ - cursor = mysql_con.cursor() - SQL = """ INSERT INTO jd(sku_id,img,price,title,shop,icons) - VALUES (%s,%s,%s,%s,%s,%s)""" - cursor.executemany(SQL,item_array) - mysql_con.commit() - cursor.close() - -def downloader(task): # 下载器 - """ - 请求目标网址的组件 - :param task: - :return: - """ - url = "https://search.jd.com/Search" - params = {"keyword":task} - response = requests.get(url=url,params=params,headers=HEADERS,timeout=6) - return response - -def main(task_array): #主函数/调度器 - """ - 爬虫任务的调度 - :param task_array: - :return: - """ - for task in task_array: - result = downloader(task) # 下载器 - item_array = parase_jd_item(result.text) # 解析器 - print("GET ITEMS", item_array) - saver(item_array) - - -if __name__ == "__main__": - mysql_con = pymysql.connect(**MYSQL_CONF) - # 用来代替生产者 - task_array= ['鼠标','键盘','手机','电脑'] - main(task_array) +#程序入口模块 +import random +import requests +from jd_code.parase.search import parase_jd_item +from jd_code.settings import MYSQL_CONF,HEADERS +import pymysql + +def saver(item_array): + """ + 持久化爬取结果 + :param item_array: + :return: + """ + cursor = mysql_con.cursor() + SQL = """ INSERT INTO jd(sku_id,img,price,title,shop,icons) + VALUES (%s,%s,%s,%s,%s,%s)""" + cursor.executemany(SQL,item_array) + mysql_con.commit() + cursor.close() + +def downloader(task): # 下载器 + """ + 请求目标网址的组件 + :param task: + :return: + """ + url = "https://search.jd.com/Search" + params = {"keyword":task} + response = requests.get(url=url,params=params,headers=HEADERS,timeout=6) + return response + +def main(task_array): #主函数/调度器 + """ + 爬虫任务的调度 + :param task_array: + :return: + """ + for task in task_array: + result = downloader(task) # 下载器 + item_array = parase_jd_item(result.text) # 解析器 + print("GET ITEMS", item_array) + saver(item_array) + + +if __name__ == "__main__": + mysql_con = pymysql.connect(**MYSQL_CONF) + # 用来代替生产者 + task_array= ['鼠标','键盘','手机','电脑'] + main(task_array) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.html" index 47111c39f2e0bcaced1bd5b4b7b3887672465c41..09a8ed369c7c53882f2fa344885197fb95bfd744 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.html" @@ -1,5705 +1,5705 @@ - - - - - - - - - - - - - - - - - - - - -手机 - 商品搜索 - 京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                  - -
                                                                                                  - - - - - - - -
                                                                                                  - -
                                                                                                  - -
                                                                                                  - -
                                                                                                  - -
                                                                                                  - - - -
                                                                                                  - -
                                                                                                  - -
                                                                                                    - -
                                                                                                    - - - - - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - - - - - - 我的购物车 - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - - - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - - - -
                                                                                                    - - - - -
                                                                                                    - - -
                                                                                                    -
                                                                                                    -
                                                                                                    -
                                                                                                    - -
                                                                                                    - > -
                                                                                                    - "手机" -
                                                                                                    -
                                                                                                    -
                                                                                                    -
                                                                                                    - -
                                                                                                    - -
                                                                                                    - -
                                                                                                    -
                                                                                                    -
                                                                                                    品牌:
                                                                                                    -
                                                                                                    -
                                                                                                      -
                                                                                                    • 所有品牌
                                                                                                    • -
                                                                                                    • A
                                                                                                    • -
                                                                                                    • B
                                                                                                    • -
                                                                                                    • C
                                                                                                    • -
                                                                                                    • D
                                                                                                    • -
                                                                                                    • E
                                                                                                    • -
                                                                                                    • F
                                                                                                    • -
                                                                                                    • G
                                                                                                    • -
                                                                                                    • H
                                                                                                    • -
                                                                                                    • I
                                                                                                    • -
                                                                                                    • J
                                                                                                    • -
                                                                                                    • K
                                                                                                    • -
                                                                                                    • L
                                                                                                    • -
                                                                                                    • M
                                                                                                    • -
                                                                                                    • N
                                                                                                    • -
                                                                                                    • O
                                                                                                    • -
                                                                                                    • P
                                                                                                    • -
                                                                                                    • R
                                                                                                    • -
                                                                                                    • S
                                                                                                    • -
                                                                                                    • T
                                                                                                    • -
                                                                                                    • U
                                                                                                    • -
                                                                                                    • V
                                                                                                    • -
                                                                                                    • X
                                                                                                    • -
                                                                                                    • Y
                                                                                                    • -
                                                                                                    • Z
                                                                                                    • -
                                                                                                    -
                                                                                                    -
                                                                                                    - -
                                                                                                    -
                                                                                                    已选条件:
                                                                                                      -
                                                                                                      - 确定 - 取消 -
                                                                                                      -
                                                                                                      -
                                                                                                      - 更多 - 多选 -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      分类:
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      - 确定 - 取消 -
                                                                                                      -
                                                                                                      -
                                                                                                      - 更多 - -
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      -
                                                                                                      CPU型号:
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      - 确定 - 取消 -
                                                                                                      -
                                                                                                      -
                                                                                                      - 更多 - 多选 -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      运行内存:
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      - 确定 - 取消 -
                                                                                                      -
                                                                                                      -
                                                                                                      - 更多 - 多选 -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      高级选项:
                                                                                                      - -
                                                                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      - -
                                                                                                      - - - - - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - - -
                                                                                                      -
                                                                                                      -
                                                                                                      - - 清空 - 确定 -
                                                                                                      -
                                                                                                      -
                                                                                                      - - 1/97 - - < - > -
                                                                                                      -
                                                                                                      5800+件商品
                                                                                                      - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      配送至
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      北京
                                                                                                      - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - - -
                                                                                                      -
                                                                                                      - - -
                                                                                                      - - - -
                                                                                                      -
                                                                                                      正在加载中,请稍后~~
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - -

                                                                                                      商品精选

                                                                                                      -
                                                                                                      -
                                                                                                        -
                                                                                                      -
                                                                                                      -
                                                                                                      -

                                                                                                      精品推荐

                                                                                                      - -
                                                                                                      -
                                                                                                      - -
                                                                                                      - - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      商品精选
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - -
                                                                                                      -
                                                                                                      -
                                                                                                      -
                                                                                                      - - -
                                                                                                      - -
                                                                                                      - -
                                                                                                        - -
                                                                                                      1. - - 品类齐全,轻松购物 - -
                                                                                                      2. - -
                                                                                                      3. - - 多仓直发,极速配送 - -
                                                                                                      4. - -
                                                                                                      5. - - 正品行货,精致服务 - -
                                                                                                      6. - -
                                                                                                      7. - - 天天低价,畅选无忧 - -
                                                                                                      8. - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      购物指南
                                                                                                      - -
                                                                                                      - - 购物流程 - -
                                                                                                      - -
                                                                                                      - - 会员介绍 - -
                                                                                                      - -
                                                                                                      - - 生活旅行/团购 - -
                                                                                                      - -
                                                                                                      - - 常见问题 - -
                                                                                                      - -
                                                                                                      - - 大家电 - -
                                                                                                      - -
                                                                                                      - - 联系客服 - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      配送方式
                                                                                                      - -
                                                                                                      - - 上门自提 - -
                                                                                                      - -
                                                                                                      - - 211限时达 - -
                                                                                                      - -
                                                                                                      - - 配送服务查询 - -
                                                                                                      - -
                                                                                                      - - 配送费收取标准 - -
                                                                                                      - -
                                                                                                      - - 海外配送 - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      支付方式
                                                                                                      - -
                                                                                                      - - 货到付款 - -
                                                                                                      - -
                                                                                                      - - 在线支付 - -
                                                                                                      - -
                                                                                                      - - 分期付款 - -
                                                                                                      - -
                                                                                                      - - 公司转账 - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      售后服务
                                                                                                      - -
                                                                                                      - - 售后政策 - -
                                                                                                      - -
                                                                                                      - - 价格保护 - -
                                                                                                      - -
                                                                                                      - - 退款说明 - -
                                                                                                      - -
                                                                                                      - - 返修/退换货 - -
                                                                                                      - -
                                                                                                      - - 取消订单 - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      特色服务
                                                                                                      - -
                                                                                                      - - 夺宝岛 - -
                                                                                                      - -
                                                                                                      - - DIY装机 - -
                                                                                                      - -
                                                                                                      - - 延保服务 - -
                                                                                                      - -
                                                                                                      - - 京东E卡 - -
                                                                                                      - -
                                                                                                      - - 京东通信 - -
                                                                                                      - -
                                                                                                      - - 京鱼座智能 - -
                                                                                                      - -
                                                                                                      - - - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - -
                                                                                                      - - - - - -
                                                                                                      - - - - - - - + + + + + + + + + + + + + + + + + + + + +手机 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      + +
                                                                                                      + + + + + + + +
                                                                                                      + +
                                                                                                      + +
                                                                                                      + +
                                                                                                      + +
                                                                                                      + + + +
                                                                                                      + +
                                                                                                      + +
                                                                                                        + +
                                                                                                        + + + + + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + + + + + + 我的购物车 + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + + + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + + + +
                                                                                                        + + + + +
                                                                                                        + + +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                        + > +
                                                                                                        + "手机" +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        +
                                                                                                        +
                                                                                                        品牌:
                                                                                                        +
                                                                                                        +
                                                                                                          +
                                                                                                        • 所有品牌
                                                                                                        • +
                                                                                                        • A
                                                                                                        • +
                                                                                                        • B
                                                                                                        • +
                                                                                                        • C
                                                                                                        • +
                                                                                                        • D
                                                                                                        • +
                                                                                                        • E
                                                                                                        • +
                                                                                                        • F
                                                                                                        • +
                                                                                                        • G
                                                                                                        • +
                                                                                                        • H
                                                                                                        • +
                                                                                                        • I
                                                                                                        • +
                                                                                                        • J
                                                                                                        • +
                                                                                                        • K
                                                                                                        • +
                                                                                                        • L
                                                                                                        • +
                                                                                                        • M
                                                                                                        • +
                                                                                                        • N
                                                                                                        • +
                                                                                                        • O
                                                                                                        • +
                                                                                                        • P
                                                                                                        • +
                                                                                                        • R
                                                                                                        • +
                                                                                                        • S
                                                                                                        • +
                                                                                                        • T
                                                                                                        • +
                                                                                                        • U
                                                                                                        • +
                                                                                                        • V
                                                                                                        • +
                                                                                                        • X
                                                                                                        • +
                                                                                                        • Y
                                                                                                        • +
                                                                                                        • Z
                                                                                                        • +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                        +
                                                                                                        已选条件:
                                                                                                          +
                                                                                                          + 确定 + 取消 +
                                                                                                          +
                                                                                                          +
                                                                                                          + 更多 + 多选 +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          分类:
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          + 确定 + 取消 +
                                                                                                          +
                                                                                                          +
                                                                                                          + 更多 + +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          CPU型号:
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          + 确定 + 取消 +
                                                                                                          +
                                                                                                          +
                                                                                                          + 更多 + 多选 +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          运行内存:
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          + 确定 + 取消 +
                                                                                                          +
                                                                                                          +
                                                                                                          + 更多 + 多选 +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          高级选项:
                                                                                                          + +
                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          + +
                                                                                                          + + + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + - +
                                                                                                          +
                                                                                                          +
                                                                                                          + + 清空 + 确定 +
                                                                                                          +
                                                                                                          +
                                                                                                          + + 1/97 + + < + > +
                                                                                                          +
                                                                                                          5800+件商品
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          配送至
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          北京
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + +
                                                                                                          +
                                                                                                          + + +
                                                                                                          + + + +
                                                                                                          +
                                                                                                          正在加载中,请稍后~~
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + +

                                                                                                          商品精选

                                                                                                          +
                                                                                                          +
                                                                                                            +
                                                                                                          +
                                                                                                          +
                                                                                                          +

                                                                                                          精品推荐

                                                                                                          + +
                                                                                                          +
                                                                                                          + +
                                                                                                          + + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          商品精选
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + +
                                                                                                          + +
                                                                                                          + +
                                                                                                            + +
                                                                                                          1. + + 品类齐全,轻松购物 + +
                                                                                                          2. + +
                                                                                                          3. + + 多仓直发,极速配送 + +
                                                                                                          4. + +
                                                                                                          5. + + 正品行货,精致服务 + +
                                                                                                          6. + +
                                                                                                          7. + + 天天低价,畅选无忧 + +
                                                                                                          8. + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          购物指南
                                                                                                          + +
                                                                                                          + + 购物流程 + +
                                                                                                          + +
                                                                                                          + + 会员介绍 + +
                                                                                                          + +
                                                                                                          + + 生活旅行/团购 + +
                                                                                                          + +
                                                                                                          + + 常见问题 + +
                                                                                                          + +
                                                                                                          + + 大家电 + +
                                                                                                          + +
                                                                                                          + + 联系客服 + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          配送方式
                                                                                                          + +
                                                                                                          + + 上门自提 + +
                                                                                                          + +
                                                                                                          + + 211限时达 + +
                                                                                                          + +
                                                                                                          + + 配送服务查询 + +
                                                                                                          + +
                                                                                                          + + 配送费收取标准 + +
                                                                                                          + +
                                                                                                          + + 海外配送 + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          支付方式
                                                                                                          + +
                                                                                                          + + 货到付款 + +
                                                                                                          + +
                                                                                                          + + 在线支付 + +
                                                                                                          + +
                                                                                                          + + 分期付款 + +
                                                                                                          + +
                                                                                                          + + 公司转账 + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          售后服务
                                                                                                          + +
                                                                                                          + + 售后政策 + +
                                                                                                          + +
                                                                                                          + + 价格保护 + +
                                                                                                          + +
                                                                                                          + + 退款说明 + +
                                                                                                          + +
                                                                                                          + + 返修/退换货 + +
                                                                                                          + +
                                                                                                          + + 取消订单 + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          特色服务
                                                                                                          + +
                                                                                                          + + 夺宝岛 + +
                                                                                                          + +
                                                                                                          + + DIY装机 + +
                                                                                                          + +
                                                                                                          + + 延保服务 + +
                                                                                                          + +
                                                                                                          + + 京东E卡 + +
                                                                                                          + +
                                                                                                          + + 京东通信 + +
                                                                                                          + +
                                                                                                          + + 京鱼座智能 + +
                                                                                                          + +
                                                                                                          + + + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + + + + + +
                                                                                                          + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.py" index db568c3ca32e318b8379321de2ab9f5f5665a6e9..7454f77fe88fa013c4389240e5c2c4322a7c36c6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/search.py" @@ -1,35 +1,35 @@ -# 解析器,写代码耗时最长的组件 -# 现在网页查找,然后复制到python - -from bs4 import BeautifulSoup -import json - -def parase_jd_item(html): - result = [] - soup = BeautifulSoup(html,'lxml') - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class ='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" # 一层一层获取属性值 - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else "[]" - - result.append((sku_id, img, price, title, shop, icons)) - return result - #print(soup) # 无实际意义,debug 用 - - -if __name__ == "__main__": - with open(r"D:\code\jd_code\test\search.html","r",encoding="utf-8") as f: - html = f.read() - result = parase_jd_item(html) +# 解析器,写代码耗时最长的组件 +# 现在网页查找,然后复制到python + +from bs4 import BeautifulSoup +import json + +def parase_jd_item(html): + result = [] + soup = BeautifulSoup(html,'lxml') + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class ='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" # 一层一层获取属性值 + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else "[]" + + result.append((sku_id, img, price, title, shop, icons)) + return result + #print(soup) # 无实际意义,debug 用 + + +if __name__ == "__main__": + with open(r"D:\code\jd_code\test\search.html","r",encoding="utf-8") as f: + html = f.read() + result = parase_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/settings.py" index 9fbdf98b5ef219fe936022c5afd1f5e3ef18b1df..ac029665611ca77c89f8999a4e27ed273e458588 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/settings.py" @@ -1,12 +1,12 @@ -# 配置文件 -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "zxy961231", - "db": "zxy" -} - -HEADERS = { - "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36", - "upgrade-insecure-requests":"1" +# 配置文件 +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "zxy961231", + "db": "zxy" +} + +HEADERS = { + "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36", + "upgrade-insecure-requests":"1" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\270\200\350\212\202/json\344\275\277\347\224\250.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\270\200\350\212\202/json\344\275\277\347\224\250.py" index 8c625bb0efe46e8b57e1c8070886a2c9e43bfdcb..9c424e9e7442ab51b1e85b4cf50b75f1671711c8 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\270\200\350\212\202/json\344\275\277\347\224\250.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\270\200\350\212\202/json\344\275\277\347\224\250.py" @@ -1,11 +1,11 @@ -import json - -test_dict = { - "a": 1, - "b": ["1",2,None], - "c": {"d":1} -} - -json_data = json.dumps(test_dict) -print(type(json_data),json_data) +import json + +test_dict = { + "a": 1, + "b": ["1",2,None], + "c": {"d":1} +} + +json_data = json.dumps(test_dict) +print(type(json_data),json_data) print(json.loads(json_data)) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/main.py" index 78c173a117a1544338be01c50f1776a75dc13c4a..b8905d82f38d7972193062c21ff786cfa8d11b0c 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/main.py" @@ -1,49 +1,49 @@ -#程序入口模块 -import random -import requests -from jd_code.parase.search import parase_jd_item -from jd_code.settings import MYSQL_CONF,HEADERS -import pymysql - -def saver(item_array): - """ - 持久化爬取结果 - :param item_array: - :return: - """ - cursor = mysql_con.cursor() - SQL = """ INSERT INTO jd(sku_id,img,price,title,shop,icons) - VALUES (%s,%s,%s,%s,%s,%s)""" - cursor.executemany(SQL,item_array) - mysql_con.commit() - cursor.close() - -def downloader(task): # 下载器 - """ - 请求目标网址的组件 - :param task: - :return: - """ - url = "https://search.jd.com/Search" - params = {"keyword":task} - response = requests.get(url=url,params=params,headers=HEADERS,timeout=6) - return response - -def main(task_array): #主函数/调度器 - """ - 爬虫任务的调度 - :param task_array: - :return: - """ - for task in task_array: - result = downloader(task) # 下载器 - item_array = parase_jd_item(result.text) # 解析器 - print("GET ITEMS", item_array) - saver(item_array) - - -if __name__ == "__main__": - mysql_con = pymysql.connect(**MYSQL_CONF) - # 用来代替生产者 - task_array= ['鼠标','键盘','手机','电脑'] - main(task_array) +#程序入口模块 +import random +import requests +from jd_code.parase.search import parase_jd_item +from jd_code.settings import MYSQL_CONF,HEADERS +import pymysql + +def saver(item_array): + """ + 持久化爬取结果 + :param item_array: + :return: + """ + cursor = mysql_con.cursor() + SQL = """ INSERT INTO jd(sku_id,img,price,title,shop,icons) + VALUES (%s,%s,%s,%s,%s,%s)""" + cursor.executemany(SQL,item_array) + mysql_con.commit() + cursor.close() + +def downloader(task): # 下载器 + """ + 请求目标网址的组件 + :param task: + :return: + """ + url = "https://search.jd.com/Search" + params = {"keyword":task} + response = requests.get(url=url,params=params,headers=HEADERS,timeout=6) + return response + +def main(task_array): #主函数/调度器 + """ + 爬虫任务的调度 + :param task_array: + :return: + """ + for task in task_array: + result = downloader(task) # 下载器 + item_array = parase_jd_item(result.text) # 解析器 + print("GET ITEMS", item_array) + saver(item_array) + + +if __name__ == "__main__": + mysql_con = pymysql.connect(**MYSQL_CONF) + # 用来代替生产者 + task_array= ['鼠标','键盘','手机','电脑'] + main(task_array) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.html" index 47111c39f2e0bcaced1bd5b4b7b3887672465c41..09a8ed369c7c53882f2fa344885197fb95bfd744 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.html" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.html" @@ -1,5705 +1,5705 @@ - - - - - - - - - - - - - - - - - - - - -手机 - 商品搜索 - 京东 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                          - -
                                                                                                          - - - - - - - -
                                                                                                          - -
                                                                                                          - -
                                                                                                          - -
                                                                                                          - -
                                                                                                          - - - -
                                                                                                          - -
                                                                                                          - -
                                                                                                            - -
                                                                                                            - - - - - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - - - - - - 我的购物车 - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - - - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - - - -
                                                                                                            - - - - -
                                                                                                            - - -
                                                                                                            -
                                                                                                            -
                                                                                                            -
                                                                                                            - -
                                                                                                            - > -
                                                                                                            - "手机" -
                                                                                                            -
                                                                                                            -
                                                                                                            -
                                                                                                            - -
                                                                                                            - -
                                                                                                            - -
                                                                                                            -
                                                                                                            -
                                                                                                            品牌:
                                                                                                            -
                                                                                                            -
                                                                                                              -
                                                                                                            • 所有品牌
                                                                                                            • -
                                                                                                            • A
                                                                                                            • -
                                                                                                            • B
                                                                                                            • -
                                                                                                            • C
                                                                                                            • -
                                                                                                            • D
                                                                                                            • -
                                                                                                            • E
                                                                                                            • -
                                                                                                            • F
                                                                                                            • -
                                                                                                            • G
                                                                                                            • -
                                                                                                            • H
                                                                                                            • -
                                                                                                            • I
                                                                                                            • -
                                                                                                            • J
                                                                                                            • -
                                                                                                            • K
                                                                                                            • -
                                                                                                            • L
                                                                                                            • -
                                                                                                            • M
                                                                                                            • -
                                                                                                            • N
                                                                                                            • -
                                                                                                            • O
                                                                                                            • -
                                                                                                            • P
                                                                                                            • -
                                                                                                            • R
                                                                                                            • -
                                                                                                            • S
                                                                                                            • -
                                                                                                            • T
                                                                                                            • -
                                                                                                            • U
                                                                                                            • -
                                                                                                            • V
                                                                                                            • -
                                                                                                            • X
                                                                                                            • -
                                                                                                            • Y
                                                                                                            • -
                                                                                                            • Z
                                                                                                            • -
                                                                                                            -
                                                                                                            -
                                                                                                            - -
                                                                                                            -
                                                                                                            已选条件:
                                                                                                              -
                                                                                                              - 确定 - 取消 -
                                                                                                              -
                                                                                                              -
                                                                                                              - 更多 - 多选 -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              分类:
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              - 确定 - 取消 -
                                                                                                              -
                                                                                                              -
                                                                                                              - 更多 - -
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              -
                                                                                                              CPU型号:
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              - 确定 - 取消 -
                                                                                                              -
                                                                                                              -
                                                                                                              - 更多 - 多选 -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              运行内存:
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              - 确定 - 取消 -
                                                                                                              -
                                                                                                              -
                                                                                                              - 更多 - 多选 -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              高级选项:
                                                                                                              - -
                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              - -
                                                                                                              - - - - - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - - -
                                                                                                              -
                                                                                                              -
                                                                                                              - - 清空 - 确定 -
                                                                                                              -
                                                                                                              -
                                                                                                              - - 1/97 - - < - > -
                                                                                                              -
                                                                                                              5800+件商品
                                                                                                              - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              配送至
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              北京
                                                                                                              - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - - -
                                                                                                              -
                                                                                                              - - -
                                                                                                              - - - -
                                                                                                              -
                                                                                                              正在加载中,请稍后~~
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - -

                                                                                                              商品精选

                                                                                                              -
                                                                                                              -
                                                                                                                -
                                                                                                              -
                                                                                                              -
                                                                                                              -

                                                                                                              精品推荐

                                                                                                              - -
                                                                                                              -
                                                                                                              - -
                                                                                                              - - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              商品精选
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - -
                                                                                                              -
                                                                                                              -
                                                                                                              -
                                                                                                              - - -
                                                                                                              - -
                                                                                                              - -
                                                                                                                - -
                                                                                                              1. - - 品类齐全,轻松购物 - -
                                                                                                              2. - -
                                                                                                              3. - - 多仓直发,极速配送 - -
                                                                                                              4. - -
                                                                                                              5. - - 正品行货,精致服务 - -
                                                                                                              6. - -
                                                                                                              7. - - 天天低价,畅选无忧 - -
                                                                                                              8. - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              购物指南
                                                                                                              - -
                                                                                                              - - 购物流程 - -
                                                                                                              - -
                                                                                                              - - 会员介绍 - -
                                                                                                              - -
                                                                                                              - - 生活旅行/团购 - -
                                                                                                              - -
                                                                                                              - - 常见问题 - -
                                                                                                              - -
                                                                                                              - - 大家电 - -
                                                                                                              - -
                                                                                                              - - 联系客服 - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              配送方式
                                                                                                              - -
                                                                                                              - - 上门自提 - -
                                                                                                              - -
                                                                                                              - - 211限时达 - -
                                                                                                              - -
                                                                                                              - - 配送服务查询 - -
                                                                                                              - -
                                                                                                              - - 配送费收取标准 - -
                                                                                                              - -
                                                                                                              - - 海外配送 - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              支付方式
                                                                                                              - -
                                                                                                              - - 货到付款 - -
                                                                                                              - -
                                                                                                              - - 在线支付 - -
                                                                                                              - -
                                                                                                              - - 分期付款 - -
                                                                                                              - -
                                                                                                              - - 公司转账 - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              售后服务
                                                                                                              - -
                                                                                                              - - 售后政策 - -
                                                                                                              - -
                                                                                                              - - 价格保护 - -
                                                                                                              - -
                                                                                                              - - 退款说明 - -
                                                                                                              - -
                                                                                                              - - 返修/退换货 - -
                                                                                                              - -
                                                                                                              - - 取消订单 - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              特色服务
                                                                                                              - -
                                                                                                              - - 夺宝岛 - -
                                                                                                              - -
                                                                                                              - - DIY装机 - -
                                                                                                              - -
                                                                                                              - - 延保服务 - -
                                                                                                              - -
                                                                                                              - - 京东E卡 - -
                                                                                                              - -
                                                                                                              - - 京东通信 - -
                                                                                                              - -
                                                                                                              - - 京鱼座智能 - -
                                                                                                              - -
                                                                                                              - - - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - -
                                                                                                              - - - - - -
                                                                                                              - - - - - - - + + + + + + + + + + + + + + + + + + + + +手机 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              + +
                                                                                                              + + + + + + + +
                                                                                                              + +
                                                                                                              + +
                                                                                                              + +
                                                                                                              + +
                                                                                                              + + + +
                                                                                                              + +
                                                                                                              + +
                                                                                                                + +
                                                                                                                + + + + + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + + + + + + 我的购物车 + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + + + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + + + +
                                                                                                                + + + + +
                                                                                                                + + +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                + > +
                                                                                                                + "手机" +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                +
                                                                                                                +
                                                                                                                品牌:
                                                                                                                +
                                                                                                                +
                                                                                                                  +
                                                                                                                • 所有品牌
                                                                                                                • +
                                                                                                                • A
                                                                                                                • +
                                                                                                                • B
                                                                                                                • +
                                                                                                                • C
                                                                                                                • +
                                                                                                                • D
                                                                                                                • +
                                                                                                                • E
                                                                                                                • +
                                                                                                                • F
                                                                                                                • +
                                                                                                                • G
                                                                                                                • +
                                                                                                                • H
                                                                                                                • +
                                                                                                                • I
                                                                                                                • +
                                                                                                                • J
                                                                                                                • +
                                                                                                                • K
                                                                                                                • +
                                                                                                                • L
                                                                                                                • +
                                                                                                                • M
                                                                                                                • +
                                                                                                                • N
                                                                                                                • +
                                                                                                                • O
                                                                                                                • +
                                                                                                                • P
                                                                                                                • +
                                                                                                                • R
                                                                                                                • +
                                                                                                                • S
                                                                                                                • +
                                                                                                                • T
                                                                                                                • +
                                                                                                                • U
                                                                                                                • +
                                                                                                                • V
                                                                                                                • +
                                                                                                                • X
                                                                                                                • +
                                                                                                                • Y
                                                                                                                • +
                                                                                                                • Z
                                                                                                                • +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                +
                                                                                                                已选条件:
                                                                                                                  +
                                                                                                                  + 确定 + 取消 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + 更多 + 多选 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  分类:
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + 确定 + 取消 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + 更多 + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  CPU型号:
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + 确定 + 取消 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + 更多 + 多选 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  运行内存:
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + 确定 + 取消 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + 更多 + 多选 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  高级选项:
                                                                                                                  + +
                                                                                                                  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  + + + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + - +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + 清空 + 确定 +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + 1/97 + + < + > +
                                                                                                                  +
                                                                                                                  5800+件商品
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  配送至
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  北京
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  + + + +
                                                                                                                  +
                                                                                                                  正在加载中,请稍后~~
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +

                                                                                                                  商品精选

                                                                                                                  +
                                                                                                                  +
                                                                                                                    +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +

                                                                                                                  精品推荐

                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  商品精选
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                    + +
                                                                                                                  1. + + 品类齐全,轻松购物 + +
                                                                                                                  2. + +
                                                                                                                  3. + + 多仓直发,极速配送 + +
                                                                                                                  4. + +
                                                                                                                  5. + + 正品行货,精致服务 + +
                                                                                                                  6. + +
                                                                                                                  7. + + 天天低价,畅选无忧 + +
                                                                                                                  8. + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  购物指南
                                                                                                                  + +
                                                                                                                  + + 购物流程 + +
                                                                                                                  + +
                                                                                                                  + + 会员介绍 + +
                                                                                                                  + +
                                                                                                                  + + 生活旅行/团购 + +
                                                                                                                  + +
                                                                                                                  + + 常见问题 + +
                                                                                                                  + +
                                                                                                                  + + 大家电 + +
                                                                                                                  + +
                                                                                                                  + + 联系客服 + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  配送方式
                                                                                                                  + +
                                                                                                                  + + 上门自提 + +
                                                                                                                  + +
                                                                                                                  + + 211限时达 + +
                                                                                                                  + +
                                                                                                                  + + 配送服务查询 + +
                                                                                                                  + +
                                                                                                                  + + 配送费收取标准 + +
                                                                                                                  + +
                                                                                                                  + + 海外配送 + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  支付方式
                                                                                                                  + +
                                                                                                                  + + 货到付款 + +
                                                                                                                  + +
                                                                                                                  + + 在线支付 + +
                                                                                                                  + +
                                                                                                                  + + 分期付款 + +
                                                                                                                  + +
                                                                                                                  + + 公司转账 + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  售后服务
                                                                                                                  + +
                                                                                                                  + + 售后政策 + +
                                                                                                                  + +
                                                                                                                  + + 价格保护 + +
                                                                                                                  + +
                                                                                                                  + + 退款说明 + +
                                                                                                                  + +
                                                                                                                  + + 返修/退换货 + +
                                                                                                                  + +
                                                                                                                  + + 取消订单 + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  特色服务
                                                                                                                  + +
                                                                                                                  + + 夺宝岛 + +
                                                                                                                  + +
                                                                                                                  + + DIY装机 + +
                                                                                                                  + +
                                                                                                                  + + 延保服务 + +
                                                                                                                  + +
                                                                                                                  + + 京东E卡 + +
                                                                                                                  + +
                                                                                                                  + + 京东通信 + +
                                                                                                                  + +
                                                                                                                  + + 京鱼座智能 + +
                                                                                                                  + +
                                                                                                                  + + + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + + + + + +
                                                                                                                  + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.py" index db568c3ca32e318b8379321de2ab9f5f5665a6e9..7454f77fe88fa013c4389240e5c2c4322a7c36c6 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/search.py" @@ -1,35 +1,35 @@ -# 解析器,写代码耗时最长的组件 -# 现在网页查找,然后复制到python - -from bs4 import BeautifulSoup -import json - -def parase_jd_item(html): - result = [] - soup = BeautifulSoup(html,'lxml') - item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") - for item in item_array: - sku_id = item.attrs["data-sku"] - img = item.select("img[data-img='1']") - price = item.select("div[class='p-price']") - title = item.select("div[class ='p-name p-name-type-2']") - shop = item.select("div[class='p-shop']") - icons = item.select("div[class='p-icons']") - - - img = img[0].attrs['data-lazy-img'] if img else "" - price = price[0].strong.i.text if price else "" # 一层一层获取属性值 - title = title[0].text.strip() if title else "" - shop = shop[0].span.a.attrs['title'] if shop else "" - icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else "[]" - - result.append((sku_id, img, price, title, shop, icons)) - return result - #print(soup) # 无实际意义,debug 用 - - -if __name__ == "__main__": - with open(r"D:\code\jd_code\test\search.html","r",encoding="utf-8") as f: - html = f.read() - result = parase_jd_item(html) +# 解析器,写代码耗时最长的组件 +# 现在网页查找,然后复制到python + +from bs4 import BeautifulSoup +import json + +def parase_jd_item(html): + result = [] + soup = BeautifulSoup(html,'lxml') + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class ='p-name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" # 一层一层获取属性值 + title = title[0].text.strip() if title else "" + shop = shop[0].span.a.attrs['title'] if shop else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else "[]" + + result.append((sku_id, img, price, title, shop, icons)) + return result + #print(soup) # 无实际意义,debug 用 + + +if __name__ == "__main__": + with open(r"D:\code\jd_code\test\search.html","r",encoding="utf-8") as f: + html = f.read() + result = parase_jd_item(html) print(result) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/settings.py" index 9fbdf98b5ef219fe936022c5afd1f5e3ef18b1df..ac029665611ca77c89f8999a4e27ed273e458588 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/settings.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\271\235\345\221\250 2.22-2.28/\347\254\254\344\272\214\344\270\211\350\212\202/settings.py" @@ -1,12 +1,12 @@ -# 配置文件 -MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "zxy961231", - "db": "zxy" -} - -HEADERS = { - "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36", - "upgrade-insecure-requests":"1" +# 配置文件 +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "zxy961231", + "db": "zxy" +} + +HEADERS = { + "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36", + "upgrade-insecure-requests":"1" } \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232 \350\277\220\347\256\227\347\254\246/my calculate.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232 \350\277\220\347\256\227\347\254\246/my calculate.py" index 94b4028f65b2db60529743a76d69e4c3e2f2e638..13eec53d381dc5d5bd09a76a7acb6f4a1dae70d1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232 \350\277\220\347\256\227\347\254\246/my calculate.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\200\350\212\202\344\275\234\344\270\232 \350\277\220\347\256\227\347\254\246/my calculate.py" @@ -1,60 +1,60 @@ -def bb(*args): - result = 1+1, 3-2, 2*2, 10/2, 10//3, 10 % 3, 8**(1/2) - return result - -result = bb(1+1, 3-2, 2*2, 10/2, 10//3, 10 % 3, 8**(1/2)) -print(result) - - -a = 10 -b = 21 -def plus(arg): #加法 - result = a+b - return result - -result =plus(a+b) -print(result) - -def minus(arg): #减法 - result = b-a - return result - -result = minus(b-a) -print(result) - -def asterisk(arg): #乘法 - result = a*b - return result - -result = asterisk(a*b) -print(result) - -def slash(arg): #除法 - result = b/a - return result - -result = slash(b/a) -print(result) - -def zhengchu(arg): #整除 - result = b//a - return result - -result = zhengchu(b//a) -print(result) - -def quyu(arg): #取余 - result = a % b - return result - -result = quyu(a % b) -print(result) - -def kaifang(arg): #开方 - result = a**(1/b) - return result - -result = kaifang(a**(1/b)) -print(result) - - +def bb(*args): + result = 1+1, 3-2, 2*2, 10/2, 10//3, 10 % 3, 8**(1/2) + return result + +result = bb(1+1, 3-2, 2*2, 10/2, 10//3, 10 % 3, 8**(1/2)) +print(result) + + +a = 10 +b = 21 +def plus(arg): #加法 + result = a+b + return result + +result =plus(a+b) +print(result) + +def minus(arg): #减法 + result = b-a + return result + +result = minus(b-a) +print(result) + +def asterisk(arg): #乘法 + result = a*b + return result + +result = asterisk(a*b) +print(result) + +def slash(arg): #除法 + result = b/a + return result + +result = slash(b/a) +print(result) + +def zhengchu(arg): #整除 + result = b//a + return result + +result = zhengchu(b//a) +print(result) + +def quyu(arg): #取余 + result = a % b + return result + +result = quyu(a % b) +print(result) + +def kaifang(arg): #开方 + result = a**(1/b) + return result + +result = kaifang(a**(1/b)) +print(result) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 CRUD\346\223\215\344\275\234/zuoye.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 CRUD\346\223\215\344\275\234/zuoye.txt" index 04351e977c5c396c86aca51990942108f1dfda94..99cbb89da53fb66edaadc94abe7f6b304c7f394a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 CRUD\346\223\215\344\275\234/zuoye.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\270\211\350\212\202\344\275\234\344\270\232 CRUD\346\223\215\344\275\234/zuoye.txt" @@ -1,437 +1,437 @@ - -#编码 ->>> '第二周第二节课'.encode("utf-8") -b'第二周第二节课' - -#解码 ->>> a = '第二周第二节课'.encode("utf-8") ->>> a.decode("utf") -'第二周第二节课' - -#检索字符串 ->>> b = '第二周第二节课' ->>> b[2] -'周' ->>> b[2:5] -'周第二' - -#获取目标字符的索引值 ->>> b.find('二周') -1 ->>> b.find('三') --1 ->>> b.find('二') -1 ->>> b.index('二') -1 ->>> b.index('四') -Traceback (most recent call last): - File "", line 1, in -ValueError: substring not found - -#替换 replace ->>> c = '第二周第二节课' ->>> c.replace('二节课', '针不戳') -'第二周第针不戳' ->>> c.replace('节课', '牛逼') -'第二周第二牛逼' - -#分割 split ->>> d = '第二周第二节课' ->>> d.split(',') -['第二周第二节课'] - -#拼接 join ->>> e = ['第二周第二节课'] ->>> ','.join(e) -'第二周第二节课' - -#删除 delete ->>> f = ' wodetianla ' ->>> f.strip() -'wodetianla' ->>> f.lstrip() -'wodetianla ' ->>> f.rstrip() -' wodetianla' - -#格式化 - a = 'big mom' ->>> b = 'kaiduo' - -#按变量 ->>> print(f'海贼王里的人物: {a}, {b}') -海贼王里的人物: big mom, kaiduo - -#按传入参数默认顺序 ->>> print('one piece: {}, {}'.format(b, a)) -one piece: kaiduo, big mom - -#按指定参数索引 ->>> print('one piece:{0}, {1}'.format(a, b)) -one piece:big mom, kaiduo ->>> print('one piece:{0}, {1}, {0}, {1}'.format(b, a)) -one piece:kaiduo, big mom, kaiduo, big mom - -#小数表示 ->>> print("{:.2f}".format(2.165946)) -2.17 ->>> print('{:.1f}'.format(1.22568)) -1.2 -jinzhe - -还是可以" - -# 列表的 CRUD - -#添加元素 create ->>> list1 = ['a', 'b', 'c', 'd'] ->>> list1.append('good') # 在末尾增加元素(append) ->>> list1 -['a', 'b', 'c', 'd', 'good'] - ->>> list2 = ['bad'] ->>> list3 = list1 + list2 # 拼接两个列表 + ->>> list3 -['a', 'b', 'c', 'd', 'good', 'bad'] - ->>> list3 += ['really'] # += 的运用 ->>> list3 -['a', 'b', 'c', 'd', 'good', 'bad', 'really'] - ->>> list4 = 'a' ->>> list4 = [list4]*10 # *的运用 ->>> list4 -['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - ->>> list4 *= 2 ->>> list4 -['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - - ->>> list3 -['a', 'b', 'c', 'd', 'good', 'bad', 'really'] ->>> list3.insert(1, 'haha') # 在位置 1 添加 'haha' ->>> list3 -['a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] ->>> list3.insert(0, 'wo') # 在位置 0 添加 'wo' ->>> list3 -['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] - -#检索元素 (retrieve) - ->>> list3 -['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] ->>> list3[::2] #在偶数位置的元素 -['wo', 'haha', 'c', 'good', 'really'] - ->>> list3[1::2] #在奇数位置的元素 -['a', 'b', 'd', 'bad'] - ->>> list3[:8:2] # 在位置 8 之前的元素 -['wo', 'haha', 'c', 'good'] ->>> list3[1:7:2] #在位置 7 之前的元素 -['a', 'b', 'd'] - ->>> list3[1:6] #取 位置 1 到位置 5 的元素 -['a', 'haha', 'b', 'c', 'd'] ->>> list3[0] # 取第一个元素 -'wo' ->>> list3[-1] # 取最后一个元素 -'really' - ->>> list3 -['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] ->>> list3.index('haha') # 元素 'haha' 在哪个位置 -2 - ->>> list3.insert(list3.index('b'), 'lala') # 在元素 'b', 的位置添加元素 'lala' ->>> list3 -['wo', 'a', 'haha', 'lala', 'b', 'c', 'd', 'good', 'bad', 'really'] - ->>> list3[5] = 'cao' #将位置 5 的元素替换成 'cao' ->>> list3 -['wo', 'a', 'haha', 'lala', 'b', 'cao', 'd', 'good', 'bad', 'really'] - ->>> list3[list3.index('b')] = 'niu' # 将元素'b' 替换成 'niu' ->>> list3 -['wo', 'a', 'haha', 'lala', 'niu', 'cao', 'd', 'good', 'bad', 'really'] - -#切片赋值 ->>> list3[0:3] = 'B' 将位置 0 到位置 2 的元素,替换成元素 'B' ->>> list3 -['B', 'lala', 'niu', 'cao', 'd', 'good', 'bad', 'really'] - -#删除 delete - ->>> list3.pop() #删除末尾元素并返回 -'really' ->>> list3 -['B', 'lala', 'niu', 'cao', 'd', 'good', 'bad'] - ->>> a = list3.pop() #删除末尾元素并返回 ->>> list3 -['B', 'lala', 'niu', 'cao', 'd', 'good'] ->>> a #被删除的元素 -'bad' - ->>> id(list3) -2457839095296 ->>> list3.clear() #清空列表中的元素, 不会改变列表的库存地址 ->>> list3 -[] ->>> id(list3) -2457839095296 - -# 排序 ->>> list4 = [2, 1, 5, 3, 7, 6] ->>> list4 -[2, 1, 5, 3, 7, 6] ->>> id(list4) -2457839095744 ->>> list4.sort() # 排序,正序, 内存地址不变 ->>> list4 -[1, 2, 3, 5, 6, 7] ->>> id(list4) -2457839095744 - ->>> list5 = [5, 2, 6, 4, 9] ->>> list5 -[5, 2, 6, 4, 9] ->>> id(list5) -2457839093760 ->>> sorted(list5) #排序之后,返回一个新的列表, 内存地址改变 -[2, 4, 5, 6, 9] ->>> a = sorted(list5) ->>> a -[2, 4, 5, 6, 9] ->>> id(a) -2457839095488 - -#倒序 reverse ->>> list6 = [1, 2, 3, 4, 5, 6] ->>> id(list6) -2457839094656 ->>> list6.reverse() #倒序, 内存地址不变 ->>> list6 -[6, 5, 4, 3, 2, 1] ->>> id(list6) -2457839094656 - ->>> list7 = [7, 8, 9] ->>> id(list7) -2457839095424 ->>> list(reversed(list7)) #倒序后返回新列表 -[9, 8, 7] ->>> a = list(reversed(list7)) ->>> id(a) -2457839122368 -" - -元组的 CRUD -元组无法更改, 因此无 Create, Update, Delete操作 - -检索Retrieve - ->>> tuple1 = ('a', 'b', 'c', 'd') ->>> tuple1[0] #位置 0 的元素 -'a' ->>> tuple1[1:2] #位置 1 到位置2的元素 -('b',) ->>> tuple1[1:3] #位置 1 到位置 3的元素 -('b', 'c') ->>> tuple[-1] ->>> tuple1[-1] -'d' -tuple1.index('a') # 元素 'a' 在哪个位置 -0 ->>> tuple1[0] #位置 0 是哪个字符 -'a' - ->>> 'a' in tuple1 # 元素是否在元组里 -True ->>> 'm' in tuple1 -False - - -CREATE ->>> dict1 = {} ->>> id(dict1) -2457839093120 ->>> dict1['a'] = 1 #键对值赋值, 不会改变内存地址 ->>> dict1 -{'a': 1} ->>> id(dict1) -2457839093120 ->>> dict2 = {'b':2, 'c':3} ->>> dict1.update(dict2) # 合并列表,不会改变内存地址 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3} ->>> id(dict1) -2457839093120 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3} - -# setdefault 有key就返回, 没有就添加默认值, 可以指定 ->>> dict1.setdefault('b',0) -2 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3} - ->>> dict1.setdefault('d',0) -0 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0} ->>> dict1.setdefault('e', 1) -1 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} - -# retrieve 检索 -键对值访问 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1['e'] -1 ->>> dict1['c'] -3 - -键对值访问缺失key会报错, 而get可以指定默认值 ->>> dict1['f'] -Traceback (most recent call last): - File "", line 1, in -KeyError: 'f' ->>> dict1.get('f') ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1.get('f',0) -0 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} - -#keys() -返回所有key ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1.keys() -dict_keys(['a', 'b', 'c', 'd', 'e']) ->>> list(dict1.keys()) # 转换成列表 -['a', 'b', 'c', 'd', 'e'] - -#values() -返回所有value ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1.values() -dict_values([1, 2, 3, 0, 1]) ->>> list(dict1.values()) #转换为列表 -[1, 2, 3, 0, 1] - -#items() -返回所有键对值 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1.items() -dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 0), ('e', 1)]) ->>> list(dict1.items()) -[('a', 1), ('b', 2), ('c', 3), ('d', 0), ('e', 1)] - -UPDATE -键对值赋值 ->>> dict1 -{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} ->>> dict1['a'] = 100 #将 key a 的 value替换成 100 ->>> dict1 -{'a': 100, 'b': 2, 'c': 3, 'd': 0, 'e': 1} - ->>> dict1.update({'b':200, 'c':300, 'd':400}) #替换更新 ->>> dict1 -{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 1} - -DELETE ->>> dict1 -{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 1} ->>> dict1.pop('a') #删除 元素 'a'并返回 -100 ->>> dict1 -{'b': 200, 'c': 300, 'd': 400, 'e': 1} - ->>> dict1.popitem() #随机删除, 字典是无序的 -('e', 1) ->>> dict1 -{'b': 200, 'c': 300, 'd': 400} - ->>> dict1.clear() #清空字典, 内存地址不变 ->>> dict1 -{} - -SET集合的 CRUD - -# Create -add - ->>> set1 = set() ->>> id(set1) -2457839085600 ->>> set1.add('a') #添加元素 'a' 不改变内存地址 ->>> set1 -{'a'} ->>> id(set1) -2457839085600 - -# update 添加元素 ->>> set1.update('b', 'c', 'd') ->>> set1 -{'c', 'a', 'b', 'd'} ->>> id(set1) - -#Retrive - -in成员检测 ->>> set1 -{'c', 'a', 'b', 'd'} ->>> 'c' in set1 -True ->>> 'e' in set1 -False - -update ->>> set1.update({'e','f'}) # 添加元素 'e' 'f' ->>> set1 -{'e', 'a', 'c', 'd', 'f', 'b'} - -union合并两个 set并返回新set ->>> set2 = {'g', 'h', 'i'} ->>> set1.union(set2) -{'d', 'i', 'f', 'e', 'g', 'a', 'c', 'h', 'b'} #新的set ->>> set1 -{'e', 'a', 'c', 'd', 'f', 'b'} ->>> a = set1.union(set2) ->>> a -{'d', 'i', 'f', 'e', 'g', 'a', 'c', 'h', 'b'} - -Delete 删除 - ->>> set1 -{'e', 'a', 'c', 'd', 'f', 'b'} ->>> set1.remove('e') #移除元素 'e' ->>> set1 -{'a', 'c', 'd', 'f', 'b'} - ->>> set1 -{'a', 'c', 'd', 'f', 'b'} ->>> set1.discard('o') #不会报错 ->>> set1.remove('o') #会报错 -Traceback (most recent call last): - File "", line 1, in -KeyError: 'o' - ->>> set1 -{'a', 'c', 'd', 'f', 'b'} ->>> set1.pop() # 随机删除元素, 并返回删除的元素 -'a' ->>> set1.pop() -'c' - -以上 list, tuple, dict, set的 CRUD基础操作, 还需要多练习 -熟练使用 + +#编码 +>>> '第二周第二节课'.encode("utf-8") +b'第二周第二节课' + +#解码 +>>> a = '第二周第二节课'.encode("utf-8") +>>> a.decode("utf") +'第二周第二节课' + +#检索字符串 +>>> b = '第二周第二节课' +>>> b[2] +'周' +>>> b[2:5] +'周第二' + +#获取目标字符的索引值 +>>> b.find('二周') +1 +>>> b.find('三') +-1 +>>> b.find('二') +1 +>>> b.index('二') +1 +>>> b.index('四') +Traceback (most recent call last): + File "", line 1, in +ValueError: substring not found + +#替换 replace +>>> c = '第二周第二节课' +>>> c.replace('二节课', '针不戳') +'第二周第针不戳' +>>> c.replace('节课', '牛逼') +'第二周第二牛逼' + +#分割 split +>>> d = '第二周第二节课' +>>> d.split(',') +['第二周第二节课'] + +#拼接 join +>>> e = ['第二周第二节课'] +>>> ','.join(e) +'第二周第二节课' + +#删除 delete +>>> f = ' wodetianla ' +>>> f.strip() +'wodetianla' +>>> f.lstrip() +'wodetianla ' +>>> f.rstrip() +' wodetianla' + +#格式化 + a = 'big mom' +>>> b = 'kaiduo' + +#按变量 +>>> print(f'海贼王里的人物: {a}, {b}') +海贼王里的人物: big mom, kaiduo + +#按传入参数默认顺序 +>>> print('one piece: {}, {}'.format(b, a)) +one piece: kaiduo, big mom + +#按指定参数索引 +>>> print('one piece:{0}, {1}'.format(a, b)) +one piece:big mom, kaiduo +>>> print('one piece:{0}, {1}, {0}, {1}'.format(b, a)) +one piece:kaiduo, big mom, kaiduo, big mom + +#小数表示 +>>> print("{:.2f}".format(2.165946)) +2.17 +>>> print('{:.1f}'.format(1.22568)) +1.2 +jinzhe + +还是可以" + +# 列表的 CRUD + +#添加元素 create +>>> list1 = ['a', 'b', 'c', 'd'] +>>> list1.append('good') # 在末尾增加元素(append) +>>> list1 +['a', 'b', 'c', 'd', 'good'] + +>>> list2 = ['bad'] +>>> list3 = list1 + list2 # 拼接两个列表 + +>>> list3 +['a', 'b', 'c', 'd', 'good', 'bad'] + +>>> list3 += ['really'] # += 的运用 +>>> list3 +['a', 'b', 'c', 'd', 'good', 'bad', 'really'] + +>>> list4 = 'a' +>>> list4 = [list4]*10 # *的运用 +>>> list4 +['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + +>>> list4 *= 2 +>>> list4 +['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + + +>>> list3 +['a', 'b', 'c', 'd', 'good', 'bad', 'really'] +>>> list3.insert(1, 'haha') # 在位置 1 添加 'haha' +>>> list3 +['a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] +>>> list3.insert(0, 'wo') # 在位置 0 添加 'wo' +>>> list3 +['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] + +#检索元素 (retrieve) + +>>> list3 +['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] +>>> list3[::2] #在偶数位置的元素 +['wo', 'haha', 'c', 'good', 'really'] + +>>> list3[1::2] #在奇数位置的元素 +['a', 'b', 'd', 'bad'] + +>>> list3[:8:2] # 在位置 8 之前的元素 +['wo', 'haha', 'c', 'good'] +>>> list3[1:7:2] #在位置 7 之前的元素 +['a', 'b', 'd'] + +>>> list3[1:6] #取 位置 1 到位置 5 的元素 +['a', 'haha', 'b', 'c', 'd'] +>>> list3[0] # 取第一个元素 +'wo' +>>> list3[-1] # 取最后一个元素 +'really' + +>>> list3 +['wo', 'a', 'haha', 'b', 'c', 'd', 'good', 'bad', 'really'] +>>> list3.index('haha') # 元素 'haha' 在哪个位置 +2 + +>>> list3.insert(list3.index('b'), 'lala') # 在元素 'b', 的位置添加元素 'lala' +>>> list3 +['wo', 'a', 'haha', 'lala', 'b', 'c', 'd', 'good', 'bad', 'really'] + +>>> list3[5] = 'cao' #将位置 5 的元素替换成 'cao' +>>> list3 +['wo', 'a', 'haha', 'lala', 'b', 'cao', 'd', 'good', 'bad', 'really'] + +>>> list3[list3.index('b')] = 'niu' # 将元素'b' 替换成 'niu' +>>> list3 +['wo', 'a', 'haha', 'lala', 'niu', 'cao', 'd', 'good', 'bad', 'really'] + +#切片赋值 +>>> list3[0:3] = 'B' 将位置 0 到位置 2 的元素,替换成元素 'B' +>>> list3 +['B', 'lala', 'niu', 'cao', 'd', 'good', 'bad', 'really'] + +#删除 delete + +>>> list3.pop() #删除末尾元素并返回 +'really' +>>> list3 +['B', 'lala', 'niu', 'cao', 'd', 'good', 'bad'] + +>>> a = list3.pop() #删除末尾元素并返回 +>>> list3 +['B', 'lala', 'niu', 'cao', 'd', 'good'] +>>> a #被删除的元素 +'bad' + +>>> id(list3) +2457839095296 +>>> list3.clear() #清空列表中的元素, 不会改变列表的库存地址 +>>> list3 +[] +>>> id(list3) +2457839095296 + +# 排序 +>>> list4 = [2, 1, 5, 3, 7, 6] +>>> list4 +[2, 1, 5, 3, 7, 6] +>>> id(list4) +2457839095744 +>>> list4.sort() # 排序,正序, 内存地址不变 +>>> list4 +[1, 2, 3, 5, 6, 7] +>>> id(list4) +2457839095744 + +>>> list5 = [5, 2, 6, 4, 9] +>>> list5 +[5, 2, 6, 4, 9] +>>> id(list5) +2457839093760 +>>> sorted(list5) #排序之后,返回一个新的列表, 内存地址改变 +[2, 4, 5, 6, 9] +>>> a = sorted(list5) +>>> a +[2, 4, 5, 6, 9] +>>> id(a) +2457839095488 + +#倒序 reverse +>>> list6 = [1, 2, 3, 4, 5, 6] +>>> id(list6) +2457839094656 +>>> list6.reverse() #倒序, 内存地址不变 +>>> list6 +[6, 5, 4, 3, 2, 1] +>>> id(list6) +2457839094656 + +>>> list7 = [7, 8, 9] +>>> id(list7) +2457839095424 +>>> list(reversed(list7)) #倒序后返回新列表 +[9, 8, 7] +>>> a = list(reversed(list7)) +>>> id(a) +2457839122368 +" + +元组的 CRUD +元组无法更改, 因此无 Create, Update, Delete操作 + +检索Retrieve + +>>> tuple1 = ('a', 'b', 'c', 'd') +>>> tuple1[0] #位置 0 的元素 +'a' +>>> tuple1[1:2] #位置 1 到位置2的元素 +('b',) +>>> tuple1[1:3] #位置 1 到位置 3的元素 +('b', 'c') +>>> tuple[-1] +>>> tuple1[-1] +'d' +tuple1.index('a') # 元素 'a' 在哪个位置 +0 +>>> tuple1[0] #位置 0 是哪个字符 +'a' + +>>> 'a' in tuple1 # 元素是否在元组里 +True +>>> 'm' in tuple1 +False + + +CREATE +>>> dict1 = {} +>>> id(dict1) +2457839093120 +>>> dict1['a'] = 1 #键对值赋值, 不会改变内存地址 +>>> dict1 +{'a': 1} +>>> id(dict1) +2457839093120 +>>> dict2 = {'b':2, 'c':3} +>>> dict1.update(dict2) # 合并列表,不会改变内存地址 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3} +>>> id(dict1) +2457839093120 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3} + +# setdefault 有key就返回, 没有就添加默认值, 可以指定 +>>> dict1.setdefault('b',0) +2 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3} + +>>> dict1.setdefault('d',0) +0 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0} +>>> dict1.setdefault('e', 1) +1 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} + +# retrieve 检索 +键对值访问 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1['e'] +1 +>>> dict1['c'] +3 + +键对值访问缺失key会报错, 而get可以指定默认值 +>>> dict1['f'] +Traceback (most recent call last): + File "", line 1, in +KeyError: 'f' +>>> dict1.get('f') +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1.get('f',0) +0 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} + +#keys() +返回所有key +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1.keys() +dict_keys(['a', 'b', 'c', 'd', 'e']) +>>> list(dict1.keys()) # 转换成列表 +['a', 'b', 'c', 'd', 'e'] + +#values() +返回所有value +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1.values() +dict_values([1, 2, 3, 0, 1]) +>>> list(dict1.values()) #转换为列表 +[1, 2, 3, 0, 1] + +#items() +返回所有键对值 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1.items() +dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 0), ('e', 1)]) +>>> list(dict1.items()) +[('a', 1), ('b', 2), ('c', 3), ('d', 0), ('e', 1)] + +UPDATE +键对值赋值 +>>> dict1 +{'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 1} +>>> dict1['a'] = 100 #将 key a 的 value替换成 100 +>>> dict1 +{'a': 100, 'b': 2, 'c': 3, 'd': 0, 'e': 1} + +>>> dict1.update({'b':200, 'c':300, 'd':400}) #替换更新 +>>> dict1 +{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 1} + +DELETE +>>> dict1 +{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 1} +>>> dict1.pop('a') #删除 元素 'a'并返回 +100 +>>> dict1 +{'b': 200, 'c': 300, 'd': 400, 'e': 1} + +>>> dict1.popitem() #随机删除, 字典是无序的 +('e', 1) +>>> dict1 +{'b': 200, 'c': 300, 'd': 400} + +>>> dict1.clear() #清空字典, 内存地址不变 +>>> dict1 +{} + +SET集合的 CRUD + +# Create +add + +>>> set1 = set() +>>> id(set1) +2457839085600 +>>> set1.add('a') #添加元素 'a' 不改变内存地址 +>>> set1 +{'a'} +>>> id(set1) +2457839085600 + +# update 添加元素 +>>> set1.update('b', 'c', 'd') +>>> set1 +{'c', 'a', 'b', 'd'} +>>> id(set1) + +#Retrive + +in成员检测 +>>> set1 +{'c', 'a', 'b', 'd'} +>>> 'c' in set1 +True +>>> 'e' in set1 +False + +update +>>> set1.update({'e','f'}) # 添加元素 'e' 'f' +>>> set1 +{'e', 'a', 'c', 'd', 'f', 'b'} + +union合并两个 set并返回新set +>>> set2 = {'g', 'h', 'i'} +>>> set1.union(set2) +{'d', 'i', 'f', 'e', 'g', 'a', 'c', 'h', 'b'} #新的set +>>> set1 +{'e', 'a', 'c', 'd', 'f', 'b'} +>>> a = set1.union(set2) +>>> a +{'d', 'i', 'f', 'e', 'g', 'a', 'c', 'h', 'b'} + +Delete 删除 + +>>> set1 +{'e', 'a', 'c', 'd', 'f', 'b'} +>>> set1.remove('e') #移除元素 'e' +>>> set1 +{'a', 'c', 'd', 'f', 'b'} + +>>> set1 +{'a', 'c', 'd', 'f', 'b'} +>>> set1.discard('o') #不会报错 +>>> set1.remove('o') #会报错 +Traceback (most recent call last): + File "", line 1, in +KeyError: 'o' + +>>> set1 +{'a', 'c', 'd', 'f', 'b'} +>>> set1.pop() # 随机删除元素, 并返回删除的元素 +'a' +>>> set1.pop() +'c' + +以上 list, tuple, dict, set的 CRUD基础操作, 还需要多练习 +熟练使用 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\344\275\234\344\270\232 \347\274\226\347\240\201\350\247\243\347\240\201/zuoye.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\344\275\234\344\270\232 \347\274\226\347\240\201\350\247\243\347\240\201/zuoye.txt" index 51bdb2cc03d262d1c5c44157ec62ca3a90a44527..14997eba1a29952dfc9700031f6383c294653c40 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\344\275\234\344\270\232 \347\274\226\347\240\201\350\247\243\347\240\201/zuoye.txt" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232 12.21-12.27/\347\254\254\344\272\214\345\221\250 \347\254\254\344\272\214\350\212\202\344\275\234\344\270\232 \347\274\226\347\240\201\350\247\243\347\240\201/zuoye.txt" @@ -1,80 +1,80 @@ - -#编码 ->>> '第二周第二节课'.encode("utf-8") -b'第二周第二节课' - -#解码 ->>> a = '第二周第二节课'.encode("utf-8") ->>> a.decode("utf") -'第二周第二节课' - -#检索字符串 ->>> b = '第二周第二节课' ->>> b[2] -'周' ->>> b[2:5] -'周第二' - -#获取目标字符的索引值 ->>> b.find('二周') -1 ->>> b.find('三') --1 ->>> b.find('二') -1 ->>> b.index('二') -1 ->>> b.index('四') -Traceback (most recent call last): - File "", line 1, in -ValueError: substring not found - -#替换 replace ->>> c = '第二周第二节课' ->>> c.replace('二节课', '针不戳') -'第二周第针不戳' ->>> c.replace('节课', '牛逼') -'第二周第二牛逼' - -#分割 split ->>> d = '第二周第二节课' ->>> d.split(',') -['第二周第二节课'] - -#拼接 join ->>> e = ['第二周第二节课'] ->>> ','.join(e) -'第二周第二节课' - -#删除 delete ->>> f = ' wodetianla ' ->>> f.strip() -'wodetianla' ->>> f.lstrip() -'wodetianla ' ->>> f.rstrip() -' wodetianla' - -#格式化 - a = 'big mom' ->>> b = 'kaiduo' - -#按变量 ->>> print(f'海贼王里的人物: {a}, {b}') -海贼王里的人物: big mom, kaiduo - -#按传入参数默认顺序 ->>> print('one piece: {}, {}'.format(b, a)) -one piece: kaiduo, big mom - -#按指定参数索引 ->>> print('one piece:{0}, {1}'.format(a, b)) -one piece:big mom, kaiduo ->>> print('one piece:{0}, {1}, {0}, {1}'.format(b, a)) -one piece:kaiduo, big mom, kaiduo, big mom - -#小数表示 ->>> print("{:.2f}".format(2.165946)) -2.17 ->>> print('{:.1f}'.format(1.22568)) -1.2 + +#编码 +>>> '第二周第二节课'.encode("utf-8") +b'第二周第二节课' + +#解码 +>>> a = '第二周第二节课'.encode("utf-8") +>>> a.decode("utf") +'第二周第二节课' + +#检索字符串 +>>> b = '第二周第二节课' +>>> b[2] +'周' +>>> b[2:5] +'周第二' + +#获取目标字符的索引值 +>>> b.find('二周') +1 +>>> b.find('三') +-1 +>>> b.find('二') +1 +>>> b.index('二') +1 +>>> b.index('四') +Traceback (most recent call last): + File "", line 1, in +ValueError: substring not found + +#替换 replace +>>> c = '第二周第二节课' +>>> c.replace('二节课', '针不戳') +'第二周第针不戳' +>>> c.replace('节课', '牛逼') +'第二周第二牛逼' + +#分割 split +>>> d = '第二周第二节课' +>>> d.split(',') +['第二周第二节课'] + +#拼接 join +>>> e = ['第二周第二节课'] +>>> ','.join(e) +'第二周第二节课' + +#删除 delete +>>> f = ' wodetianla ' +>>> f.strip() +'wodetianla' +>>> f.lstrip() +'wodetianla ' +>>> f.rstrip() +' wodetianla' + +#格式化 + a = 'big mom' +>>> b = 'kaiduo' + +#按变量 +>>> print(f'海贼王里的人物: {a}, {b}') +海贼王里的人物: big mom, kaiduo + +#按传入参数默认顺序 +>>> print('one piece: {}, {}'.format(b, a)) +one piece: kaiduo, big mom + +#按指定参数索引 +>>> print('one piece:{0}, {1}'.format(a, b)) +one piece:big mom, kaiduo +>>> print('one piece:{0}, {1}, {0}, {1}'.format(b, a)) +one piece:kaiduo, big mom, kaiduo, big mom + +#小数表示 +>>> print("{:.2f}".format(2.165946)) +2.17 +>>> print('{:.1f}'.format(1.22568)) +1.2 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\345\244\232\350\277\233\347\250\213/\345\244\232\347\272\277\347\250\213.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\345\244\232\350\277\233\347\250\213/\345\244\232\347\272\277\347\250\213.py" index 56a0d665fbdd251f2a913dab0dda895db6234738..f4d9dd736042993c57ad921ce19953fcb8fa6b21 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\345\244\232\350\277\233\347\250\213/\345\244\232\347\272\277\347\250\213.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\345\244\232\350\277\233\347\250\213/\345\244\232\347\272\277\347\250\213.py" @@ -1,24 +1,24 @@ -# 实现一个多线程程序 -import requests -import requests -from threading import Thread -from multiprocessing import Process -def request_bilibili(): - url = "https://www.bilibili.com/v/douga/?spm_id_from=333.851.b_7072696d6172794368616e6e656c4d656e75.1" - body = "" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" - } - response = requests.get(url=url, headers=headers) - print(response) - -if __name__ == "__main__": - for i in range(10): - t = Thread(target=request_bilibili) - t.start() - -#转换为多进程 -if __name__ == "__main__": - for i in range(10): - p = Process(target=request_bilibili) - p.start() +# 实现一个多线程程序 +import requests +import requests +from threading import Thread +from multiprocessing import Process +def request_bilibili(): + url = "https://www.bilibili.com/v/douga/?spm_id_from=333.851.b_7072696d6172794368616e6e656c4d656e75.1" + body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" + } + response = requests.get(url=url, headers=headers) + print(response) + +if __name__ == "__main__": + for i in range(10): + t = Thread(target=request_bilibili) + t.start() + +#转换为多进程 +if __name__ == "__main__": + for i in range(10): + p = Process(target=request_bilibili) + p.start() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\211\350\212\202/\344\275\234\344\270\232" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\211\350\212\202/\344\275\234\344\270\232" index 501f2a9439c01553ca2cc8783322d3fdb11de8ae..a52ff41cd084acd5f2950462879f240704241a38 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\211\350\212\202/\344\275\234\344\270\232" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\211\350\212\202/\344\275\234\344\270\232" @@ -1,61 +1,61 @@ -""" -笔记 -https://blog.csdn.net/weixin_53815762/article/details/112754992 - -什么是迭代器? -迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有调用 next 方法才能返回值) - -什么是生成器? -生成器是一个特殊的迭代器,在迭代器的数据的惰性返回功能基础上,提供了额外的功能,实现了程序的暂停 - -迭代器和生成器的异同点 -都提供了惰性的返回功能,迭代器侧重于提供数据的惰性返回功能, 生成器侧重提供指令的惰性返回功能 - -协程的实现原理 -协程的实现原理就是生成器的实现原理,在生成器的基础上,又提供了传递值得功能 - -asyncio的实现原理 -自动维护了一个事件队列,然后循环访问事件来完成异步的消息维护 - -用协程实现一个计算平均数的函数 - -编写一个 asyncio 异步程序 - -扩展:了解 aiohttp 异步请求网址 - -""" -# 用协程实现一个计算平均数的函数 -def avg(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - -my_avg = avg() -print(next(my_avg)) -print(my_avg.send(2)) -print(my_avg.send(3)) - -# 编写一个 asyncio 异步程序 -import asyncio -import time - -async def time_now(): - await asyncio.sleep(1) - print(f'now time is: {time.time()}') - -loop = asyncio.get_event_loop() -task_array = [] -for i in range(5): - task_array.append(time_now()) - -loop.run_until_complete(asyncio.wait(task_array)) -loop.close() - - - +""" +笔记 +https://blog.csdn.net/weixin_53815762/article/details/112754992 + +什么是迭代器? +迭代器可以用来表示一个数据流,提供了数据的惰性返回功能(只有调用 next 方法才能返回值) + +什么是生成器? +生成器是一个特殊的迭代器,在迭代器的数据的惰性返回功能基础上,提供了额外的功能,实现了程序的暂停 + +迭代器和生成器的异同点 +都提供了惰性的返回功能,迭代器侧重于提供数据的惰性返回功能, 生成器侧重提供指令的惰性返回功能 + +协程的实现原理 +协程的实现原理就是生成器的实现原理,在生成器的基础上,又提供了传递值得功能 + +asyncio的实现原理 +自动维护了一个事件队列,然后循环访问事件来完成异步的消息维护 + +用协程实现一个计算平均数的函数 + +编写一个 asyncio 异步程序 + +扩展:了解 aiohttp 异步请求网址 + +""" +# 用协程实现一个计算平均数的函数 +def avg(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + +my_avg = avg() +print(next(my_avg)) +print(my_avg.send(2)) +print(my_avg.send(3)) + +# 编写一个 asyncio 异步程序 +import asyncio +import time + +async def time_now(): + await asyncio.sleep(1) + print(f'now time is: {time.time()}') + +loop = asyncio.get_event_loop() +task_array = [] +for i in range(5): + task_array.append(time_now()) + +loop.run_until_complete(asyncio.wait(task_array)) +loop.close() + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\351\224\201.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\351\224\201.py" index 98f4607c89a78889d722fb1367dc1db728c82228..7392bd50afce3696a40f1c6548ccc883e6b30432 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\351\224\201.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\351\224\201.py" @@ -1,61 +1,61 @@ -from threading import Thread, Lock -from multiprocessing import Process, Lock -from multiprocessing import Queue, Array, Value - - -#多进程锁 - -def save_to_pfile(index, lock): - with lock: - with open("ex2.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - -if __name__ =="__main__": - process_array=[] - lock = Lock() - for i in range(10): - p = Process(target=save_to_pfile, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("done!") - -# 多线程锁 - -zero = 0 -lock = Lock() -def save_to_tfile(): - global zero - for i in range(10**7): - zero += 1 - zero -= 1 - -if __name__ == "__main__": - thread_array = [] - for i in range(10): - t = Thread(target=save_to_tfile) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - print("done!") - print(zero) - -# 消息队列 -def save_to_queue(index, my_queue): - my_queue.put(index) - -if __name__ == "__main__": - process_array = [] - my_queue = Queue() - for i in range(10): - p = Process(target=save_to_queue, args=(i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - while True: - print(my_queue.get()) - +from threading import Thread, Lock +from multiprocessing import Process, Lock +from multiprocessing import Queue, Array, Value + + +#多进程锁 + +def save_to_pfile(index, lock): + with lock: + with open("ex2.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + +if __name__ =="__main__": + process_array=[] + lock = Lock() + for i in range(10): + p = Process(target=save_to_pfile, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!") + +# 多线程锁 + +zero = 0 +lock = Lock() +def save_to_tfile(): + global zero + for i in range(10**7): + zero += 1 + zero -= 1 + +if __name__ == "__main__": + thread_array = [] + for i in range(10): + t = Thread(target=save_to_tfile) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print("done!") + print(zero) + +# 消息队列 +def save_to_queue(index, my_queue): + my_queue.put(index) + +if __name__ == "__main__": + process_array = [] + my_queue = Queue() + for i in range(10): + p = Process(target=save_to_queue, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + while True: + print(my_queue.get()) + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\205\253\345\221\250 2.1-2.7/\347\254\254\344\270\200\350\212\202/\347\272\246\346\235\237 \345\210\206\347\273\204\346\237\245\350\257\242" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\205\253\345\221\250 2.1-2.7/\347\254\254\344\270\200\350\212\202/\347\272\246\346\235\237 \345\210\206\347\273\204\346\237\245\350\257\242" index 5ee071bf508a46930b968c44c3bdf4dd0110c129..ec2e9406d4ebd5513f0fb8381d611aa530a81130 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\205\253\345\221\250 2.1-2.7/\347\254\254\344\270\200\350\212\202/\347\272\246\346\235\237 \345\210\206\347\273\204\346\237\245\350\257\242" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\205\253\345\221\250 2.1-2.7/\347\254\254\344\270\200\350\212\202/\347\272\246\346\235\237 \345\210\206\347\273\204\346\237\245\350\257\242" @@ -1,12 +1,12 @@ -约束 -主键约束 - -分组查询 -SELECT count(*) as 店铺数, -sum(amount) as 总业绩, -format(avg(amount),2) as 平均业绩, -max(amount) as 最大业绩, -min(amount) as 最小业绩, -department as 部门 -from store_perf GROUP BY department - +约束 +主键约束 + +分组查询 +SELECT count(*) as 店铺数, +sum(amount) as 总业绩, +format(avg(amount),2) as 平均业绩, +max(amount) as 最大业绩, +min(amount) as 最小业绩, +department as 部门 +from store_perf GROUP BY department + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/jd_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/jd_search.py" index 8e5f1ba1234b62967cc8e615f7fb05b0ef3fc0f1..b44f8d4139ef08f4159e11c704d8d7a97e707e5a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/jd_search.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/jd_search.py" @@ -1,23 +1,23 @@ -import scrapy - -class JdSearch(scrapy.Spider): - name = "jd_search" - - def start_requests(self): - for keyword in ['鼠标','键盘','手机','电脑']: - for page_num in range(1,11): - url = f"https://search.jd.com/Search?keyword={keyword}$page={page_num}" - - # 通过生成器作为任务生产者 - # 使用FormRequest,是因为他既既可以发送 GET 请求, 也可以发送 POST请求 - yield scrapy.FormRequest( - url=url, - method='GET', - #formdata=data #如果是 POST 请求,携带数据使用 body - callback=self.parse_search # 指定回调函数处理 response 对象 - ) - # 解析器 - def parse_search(self,response): - print(response) - - +import scrapy + +class JdSearch(scrapy.Spider): + name = "jd_search" + + def start_requests(self): + for keyword in ['鼠标','键盘','手机','电脑']: + for page_num in range(1,11): + url = f"https://search.jd.com/Search?keyword={keyword}$page={page_num}" + + # 通过生成器作为任务生产者 + # 使用FormRequest,是因为他既既可以发送 GET 请求, 也可以发送 POST请求 + yield scrapy.FormRequest( + url=url, + method='GET', + #formdata=data #如果是 POST 请求,携带数据使用 body + callback=self.parse_search # 指定回调函数处理 response 对象 + ) + # 解析器 + def parse_search(self,response): + print(response) + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202.md" index bfa7e105c195107cc460cadc947e66f26f4c64c3..4c0ec222f07ceb6c883f852dd63036483372176e 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\345\221\250 3.1-3.7/\344\270\200\344\272\214\350\212\202\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202.md" @@ -1,13 +1,13 @@ - -``` -#scrapy 组件运作流程 -#1.ENGINE 从 SPIDERS 获取初始请求 REQUESTS -#2.ENGINE 得到 REQUESTS 后,发送给 SCHEDULER, SCHEDULER 对 REQUESTS 调度后产出任务 -#3.SCHEDULER 返回下一个请求任务给 ENGINE -#4.ENGINE 将请求任务发送给 DOWNLOADER 完成下载任务, 途径下载器中间件 -#5.一旦 DOWNLOADER 完成下载任务, 返回 RESPONSE 给 ENGINGE, 途径下载器中间件 -#6.ENGINE 得到 RESPONSE 后,发送 RESPONSE 对象给 SPIDERS 进行解析和处理, 途径爬虫中间件 -#7.SPIDERS 处理完成之后,将解析结果 ITEMS 返回给 ENGINGE, 发送一个新的 REQUESTS 给 ENGINE -#8.ENGINGE 将 解析结果 ITEMS 发送给 PIPLINES 进行处理存储数据,拿到 REQUESTS 发送给 SCHEDULER 处理 -#9.继续以上循环,直到没有新的任务产出 -``` + +``` +#scrapy 组件运作流程 +#1.ENGINE 从 SPIDERS 获取初始请求 REQUESTS +#2.ENGINE 得到 REQUESTS 后,发送给 SCHEDULER, SCHEDULER 对 REQUESTS 调度后产出任务 +#3.SCHEDULER 返回下一个请求任务给 ENGINE +#4.ENGINE 将请求任务发送给 DOWNLOADER 完成下载任务, 途径下载器中间件 +#5.一旦 DOWNLOADER 完成下载任务, 返回 RESPONSE 给 ENGINGE, 途径下载器中间件 +#6.ENGINE 得到 RESPONSE 后,发送 RESPONSE 对象给 SPIDERS 进行解析和处理, 途径爬虫中间件 +#7.SPIDERS 处理完成之后,将解析结果 ITEMS 返回给 ENGINGE, 发送一个新的 REQUESTS 给 ENGINE +#8.ENGINGE 将 解析结果 ITEMS 发送给 PIPLINES 进行处理存储数据,拿到 REQUESTS 发送给 SCHEDULER 处理 +#9.继续以上循环,直到没有新的任务产出 +``` diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\200\350\212\202/\346\227\266\351\227\264\346\250\241\345\235\227" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\200\350\212\202/\346\227\266\351\227\264\346\250\241\345\235\227" index 1bdea504616ce8e8629e48fd0bedd47fbb6c0e2e..2b471fd96cd4461de1b3934201646ac7a49ce505 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\200\350\212\202/\346\227\266\351\227\264\346\250\241\345\235\227" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\200\350\212\202/\346\227\266\351\227\264\346\250\241\345\235\227" @@ -1,51 +1,51 @@ -import time -import datetime -from datetime import timedelta - - -#datetime.datetime 转换为格式化字符串 - -today = datetime.datetime.now(tz=None) -today = today.strftime("%Y-%m-%d %H:%M:%S") -print(today) - -# str -> datetime.datetime -a = datetime.datetime.strptime(today,"%Y-%m-%d %H:%M:%S") -# 和终端打印出来的结果不一样阿 -print(a) - -# datime.datetime -> timestamp -today = datetime.datetime.now(tz=None) -print(today.timestamp()) - -#timestamp -> datetime.datetime - -ts = today.timestamp() -print(datetime.datetime.fromtimestamp(ts, tz=None)) - -# 封装一个函数get_date(day_delta)如果传入的是-1, 输出就是字符串日期 2021-01-06 - -today = datetime.datetime.now(tz=None) -today = today.strftime("%Y-%m-%d") # 转格式化 -a = datetime.datetime.strptime(today,"%Y-%m-%d") # 转datetime.datetime -today1 = a+timedelta(days=1) #运算 -today1_1 = today1.strftime("%Y-%m-%d") # 格式化 -print(today1_1) - -#下面的是用终端走的 -""">>> today = datetime.datetime.now(tz=None) ->>> today = today.strftime("%Y-%m-%d") ->>> today -'2021-01-06' ->>> a = datetime.datetime.strptime(today,"%Y-%m-%d") ->>> a -datetime.datetime(2021, 1, 6, 0, 0) ->>> today1 = a+timedelta(days=1) ->>> today1 -datetime.datetime(2021, 1, 7, 0, 0) ->>> today1_1 = today1.strftime("%Y-%m-%d") ->>> today1_1 -'2021-01-07' ->>> -""" - +import time +import datetime +from datetime import timedelta + + +#datetime.datetime 转换为格式化字符串 + +today = datetime.datetime.now(tz=None) +today = today.strftime("%Y-%m-%d %H:%M:%S") +print(today) + +# str -> datetime.datetime +a = datetime.datetime.strptime(today,"%Y-%m-%d %H:%M:%S") +# 和终端打印出来的结果不一样阿 +print(a) + +# datime.datetime -> timestamp +today = datetime.datetime.now(tz=None) +print(today.timestamp()) + +#timestamp -> datetime.datetime + +ts = today.timestamp() +print(datetime.datetime.fromtimestamp(ts, tz=None)) + +# 封装一个函数get_date(day_delta)如果传入的是-1, 输出就是字符串日期 2021-01-06 + +today = datetime.datetime.now(tz=None) +today = today.strftime("%Y-%m-%d") # 转格式化 +a = datetime.datetime.strptime(today,"%Y-%m-%d") # 转datetime.datetime +today1 = a+timedelta(days=1) #运算 +today1_1 = today1.strftime("%Y-%m-%d") # 格式化 +print(today1_1) + +#下面的是用终端走的 +""">>> today = datetime.datetime.now(tz=None) +>>> today = today.strftime("%Y-%m-%d") +>>> today +'2021-01-06' +>>> a = datetime.datetime.strptime(today,"%Y-%m-%d") +>>> a +datetime.datetime(2021, 1, 6, 0, 0) +>>> today1 = a+timedelta(days=1) +>>> today1 +datetime.datetime(2021, 1, 7, 0, 0) +>>> today1_1 = today1.strftime("%Y-%m-%d") +>>> today1_1 +'2021-01-07' +>>> +""" + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202/\345\261\236\346\200\247\345\222\214\345\256\236\344\276\213\345\261\236\346\200\247\357\274\214\347\261\273\346\226\271\346\263\225\357\274\214\351\235\231\346\200\201\346\226\271\346\263\225\357\274\214\345\256\236\344\276\213\346\226\271\346\263\225\357\274\214\346\216\245\345\217\243\357\274\214\345\215\217\350\256\256\345\220\216\346\212\275\350\261\241\345\237\272\347\261\273" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202/\345\261\236\346\200\247\345\222\214\345\256\236\344\276\213\345\261\236\346\200\247\357\274\214\347\261\273\346\226\271\346\263\225\357\274\214\351\235\231\346\200\201\346\226\271\346\263\225\357\274\214\345\256\236\344\276\213\346\226\271\346\263\225\357\274\214\346\216\245\345\217\243\357\274\214\345\215\217\350\256\256\345\220\216\346\212\275\350\261\241\345\237\272\347\261\273" index aaa6dbcf81bd8320d5ce3d17d220a62459a6c0ec..994add79af7bdc8500acd823fc36af8ed873bb78 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202/\345\261\236\346\200\247\345\222\214\345\256\236\344\276\213\345\261\236\346\200\247\357\274\214\347\261\273\346\226\271\346\263\225\357\274\214\351\235\231\346\200\201\346\226\271\346\263\225\357\274\214\345\256\236\344\276\213\346\226\271\346\263\225\357\274\214\346\216\245\345\217\243\357\274\214\345\215\217\350\256\256\345\220\216\346\212\275\350\261\241\345\237\272\347\261\273" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202/\345\261\236\346\200\247\345\222\214\345\256\236\344\276\213\345\261\236\346\200\247\357\274\214\347\261\273\346\226\271\346\263\225\357\274\214\351\235\231\346\200\201\346\226\271\346\263\225\357\274\214\345\256\236\344\276\213\346\226\271\346\263\225\357\274\214\346\216\245\345\217\243\357\274\214\345\215\217\350\256\256\345\220\216\346\212\275\350\261\241\345\237\272\347\261\273" @@ -1,59 +1,59 @@ -# 实例改为静态方法 - -class MyMath: - @staticmethod - def add(a, b): - return a + b - def sub(a, b): - return a - b - def mul(a, b): - return a * b - def div(a, b): - return a / b - def mi(a, b): - return a ** b - def sqrt(a, b): - return a**(1 / 2) - -print(MyMath.add(1,2)) - - -#添加属性 -class movie(): - nation = "China" #添加类属性 - __ticket = 30 # 添加类私有属性 - - def __init__(self,act): - self.p = act - -金刚川 = movie("动作") -print(f"《金刚川》是一部{金刚川.p}电影") - -哪吒 = movie("动漫") -print(f"《哪吒》是一部{哪吒.p}电影") - -# 添加类方法 -print("-------------------------") -class movie(): - def __init__(self,act): - self.p = act - - @classmethod - def __new__(cls, *args, **kwargs): - return super().__new__(cls) - -金刚川 = movie("动作") -print(金刚川.p) - -print("-------------------------") -#在__init__方法中初始化实例属性 -#在__init__方法中绑定私有实例属性 - -class movie(): - def __init__(self,act): - self.act = act - __act = "电影类型" - -金刚川 = movie("动作") -print(f"《金刚川》是一部{金刚川.act}电影") - +# 实例改为静态方法 + +class MyMath: + @staticmethod + def add(a, b): + return a + b + def sub(a, b): + return a - b + def mul(a, b): + return a * b + def div(a, b): + return a / b + def mi(a, b): + return a ** b + def sqrt(a, b): + return a**(1 / 2) + +print(MyMath.add(1,2)) + + +#添加属性 +class movie(): + nation = "China" #添加类属性 + __ticket = 30 # 添加类私有属性 + + def __init__(self,act): + self.p = act + +金刚川 = movie("动作") +print(f"《金刚川》是一部{金刚川.p}电影") + +哪吒 = movie("动漫") +print(f"《哪吒》是一部{哪吒.p}电影") + +# 添加类方法 +print("-------------------------") +class movie(): + def __init__(self,act): + self.p = act + + @classmethod + def __new__(cls, *args, **kwargs): + return super().__new__(cls) + +金刚川 = movie("动作") +print(金刚川.p) + +print("-------------------------") +#在__init__方法中初始化实例属性 +#在__init__方法中绑定私有实例属性 + +class movie(): + def __init__(self,act): + self.act = act + __act = "电影类型" + +金刚川 = movie("动作") +print(f"《金刚川》是一部{金刚川.act}电影") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232" index aaa6dbcf81bd8320d5ce3d17d220a62459a6c0ec..994add79af7bdc8500acd823fc36af8ed873bb78 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\270\211\350\212\202\344\275\234\344\270\232" @@ -1,59 +1,59 @@ -# 实例改为静态方法 - -class MyMath: - @staticmethod - def add(a, b): - return a + b - def sub(a, b): - return a - b - def mul(a, b): - return a * b - def div(a, b): - return a / b - def mi(a, b): - return a ** b - def sqrt(a, b): - return a**(1 / 2) - -print(MyMath.add(1,2)) - - -#添加属性 -class movie(): - nation = "China" #添加类属性 - __ticket = 30 # 添加类私有属性 - - def __init__(self,act): - self.p = act - -金刚川 = movie("动作") -print(f"《金刚川》是一部{金刚川.p}电影") - -哪吒 = movie("动漫") -print(f"《哪吒》是一部{哪吒.p}电影") - -# 添加类方法 -print("-------------------------") -class movie(): - def __init__(self,act): - self.p = act - - @classmethod - def __new__(cls, *args, **kwargs): - return super().__new__(cls) - -金刚川 = movie("动作") -print(金刚川.p) - -print("-------------------------") -#在__init__方法中初始化实例属性 -#在__init__方法中绑定私有实例属性 - -class movie(): - def __init__(self,act): - self.act = act - __act = "电影类型" - -金刚川 = movie("动作") -print(f"《金刚川》是一部{金刚川.act}电影") - +# 实例改为静态方法 + +class MyMath: + @staticmethod + def add(a, b): + return a + b + def sub(a, b): + return a - b + def mul(a, b): + return a * b + def div(a, b): + return a / b + def mi(a, b): + return a ** b + def sqrt(a, b): + return a**(1 / 2) + +print(MyMath.add(1,2)) + + +#添加属性 +class movie(): + nation = "China" #添加类属性 + __ticket = 30 # 添加类私有属性 + + def __init__(self,act): + self.p = act + +金刚川 = movie("动作") +print(f"《金刚川》是一部{金刚川.p}电影") + +哪吒 = movie("动漫") +print(f"《哪吒》是一部{哪吒.p}电影") + +# 添加类方法 +print("-------------------------") +class movie(): + def __init__(self,act): + self.p = act + + @classmethod + def __new__(cls, *args, **kwargs): + return super().__new__(cls) + +金刚川 = movie("动作") +print(金刚川.p) + +print("-------------------------") +#在__init__方法中初始化实例属性 +#在__init__方法中绑定私有实例属性 + +class movie(): + def __init__(self,act): + self.act = act + __act = "电影类型" + +金刚川 = movie("动作") +print(f"《金刚川》是一部{金刚川.act}电影") + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\272\214\350\212\202/\347\261\273\347\232\204\345\210\233\345\273\272 \345\256\236\344\276\213 \345\210\235\345\247\213\345\214\226" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\272\214\350\212\202/\347\261\273\347\232\204\345\210\233\345\273\272 \345\256\236\344\276\213 \345\210\235\345\247\213\345\214\226" index 3d82351bd2cd9dcf04a521bcc9868863e1ebcfc7..4a24040b4154fdec7ff2f176070858eb2fc3793d 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\272\214\350\212\202/\347\261\273\347\232\204\345\210\233\345\273\272 \345\256\236\344\276\213 \345\210\235\345\247\213\345\214\226" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\233\233\345\221\250\344\275\234\344\270\232.01.04-01.10/\347\254\254\344\272\214\350\212\202/\347\261\273\347\232\204\345\210\233\345\273\272 \345\256\236\344\276\213 \345\210\235\345\247\213\345\214\226" @@ -1,42 +1,42 @@ -# 封装MyMath类 -class MyMath: - def add(self, a, b): - return a + b - def sub(self, a, b): - return a - b - def mul(self, a, b): - return a * b - def div(self, a, b): - return a / b - def mi(self, a, b): - return a ** b - def sqrt(self, a, b): - return a**(1 / 2) - -a = MyMath() -a.add(10, 2) -print(a) - -# 定义类 -class movie(): - def __init__(self,act): - self.p = act - -金刚川 = movie("动作") -print(f"《金刚川》是一部{金刚川.p}电影") - -哪吒 = movie("动漫") -print(f"《哪吒》是一部{哪吒.p}电影") - -# 创建子类 -class color: - def __init__(self, yellow): - self.y = yellow - -class nation(color): - guojia = 'Chinese' - -we = nation("YELLOW") -print(we.y) -print(we.guojia) -print(f"we are {we.guojia} and with {we.y} skin") +# 封装MyMath类 +class MyMath: + def add(self, a, b): + return a + b + def sub(self, a, b): + return a - b + def mul(self, a, b): + return a * b + def div(self, a, b): + return a / b + def mi(self, a, b): + return a ** b + def sqrt(self, a, b): + return a**(1 / 2) + +a = MyMath() +a.add(10, 2) +print(a) + +# 定义类 +class movie(): + def __init__(self,act): + self.p = act + +金刚川 = movie("动作") +print(f"《金刚川》是一部{金刚川.p}电影") + +哪吒 = movie("动漫") +print(f"《哪吒》是一部{哪吒.p}电影") + +# 创建子类 +class color: + def __init__(self, yellow): + self.y = yellow + +class nation(color): + guojia = 'Chinese' + +we = nation("YELLOW") +print(we.y) +print(we.guojia) +print(f"we are {we.guojia} and with {we.y} skin") diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/ \347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.28\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/ \347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.28\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" index e9179f8dac3be63c20172eed8b8d2634c3d6be5e..ad67799aa12ac3922eb4fde3c077062dcb616016 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/ \347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.28\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/ \347\254\254\344\270\211\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.28\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202-\344\275\234\344\270\232.py" @@ -1,109 +1,109 @@ -# 第一问 用for循环和while来完成简单的计数 - -# 采用for循环 计算 1+2+3+...+100的总和 -def for_use(): - sum = 0 - for i in range(1, 101): - sum += i - return sum - - -# 采用while循环 计算 1+2+3+...+100的总和 -def while_use(): - sum = 0 - num = 1 - while num < 101: - sum += num - num += 1 - return sum - - -# 第二问 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 - -# for循环实现斐波那契函数 -def fib_for(): - # f(1) - a = 1 - # f(2) - b = 1 - # f(0) - c = 0 - print(c) - print(a) - print(b) - for i in range(3, 101): - # f(n) = f(n-1) + f(n-2) - c = a + b - # 交换变量 - a = b - b = c - print(c) - - -# while循环实现斐波那契函数 -def fib_while(): - # f(1) - a = 1 - # f(2) - b = 1 - # f(0) - c = 0 - i = 0 - print(c) - print(a) - print(b) - while i <= 100: - # f(n) = f(n-1) + f(n-2) - c = a + b - # 交换变量 - a = b - b = c - print(c) - i += 1 - - -# 第三问 自定义异常ParamsError -class ParamsError(Exception): - pass - - -def add(a, b): - return a + b - - -def sub(a, b): - return a - b - - -# 乘法 -def mul(a, b): - return a * b - - -# 除法 -def divide(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - -# 整除 -def edivide(a, b): - try: - return a // b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - - -# 取余 -def getremainder(a, b): - try: - return a % b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - - -def sqrt(a, b): - return a ** (1/b) +# 第一问 用for循环和while来完成简单的计数 + +# 采用for循环 计算 1+2+3+...+100的总和 +def for_use(): + sum = 0 + for i in range(1, 101): + sum += i + return sum + + +# 采用while循环 计算 1+2+3+...+100的总和 +def while_use(): + sum = 0 + num = 1 + while num < 101: + sum += num + num += 1 + return sum + + +# 第二问 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 + +# for循环实现斐波那契函数 +def fib_for(): + # f(1) + a = 1 + # f(2) + b = 1 + # f(0) + c = 0 + print(c) + print(a) + print(b) + for i in range(3, 101): + # f(n) = f(n-1) + f(n-2) + c = a + b + # 交换变量 + a = b + b = c + print(c) + + +# while循环实现斐波那契函数 +def fib_while(): + # f(1) + a = 1 + # f(2) + b = 1 + # f(0) + c = 0 + i = 0 + print(c) + print(a) + print(b) + while i <= 100: + # f(n) = f(n-1) + f(n-2) + c = a + b + # 交换变量 + a = b + b = c + print(c) + i += 1 + + +# 第三问 自定义异常ParamsError +class ParamsError(Exception): + pass + + +def add(a, b): + return a + b + + +def sub(a, b): + return a - b + + +# 乘法 +def mul(a, b): + return a * b + + +# 除法 +def divide(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + +# 整除 +def edivide(a, b): + try: + return a // b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + + +# 取余 +def getremainder(a, b): + try: + return a % b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + + +def sqrt(a, b): + return a ** (1/b) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 5feaefceac9883aa3f3348010f7d07c2ebd118eb..7561885af49dcc790706875646025dc3a820bee4 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,90 +1,90 @@ -# 第一周-第一节课-随堂笔记 - -#### 养成良好的学习习惯 - -- 做好笔记和文档 - - - typora - - - 创建标题 - - ``` - ctrl + 数字 - ``` - - - 创建代码块 - - ``` - ctrl + shift +k - ``` - -- 科学的探索习惯 - - 官方文档和GitHub库 - - StackOverflow - - 简书和知乎 - - Goole和百度 -- 良好的学习心态 - - 面向需求学习 - - 需要什么学什么 - - 有效率地学习 - - 自己搜索10分钟 - - 及时提问 - -#### 编程语言的基本概述 - -- 编程语言有哪些分类? - - ``` - c - c++ - java - python - javascript - ``` - - - 编译型语言,解释性语言和混合型语言 - - 动态语言和静态语言 - - 强类型语言和弱类型语言 - -- 什么是动态语言?什么是静态语言? - - 编译时不知道变量类型的叫做动态语言,反之,知道变量类型的就叫静态语言 - - - 动态语言 - - python - - javascript - - - 静态语言 - - c - - c++ - - java - -- 什么是强类型语言?什么是弱类型语言? - - 在使用变量时,不会自动地改变变量的类型,反之,弱类型语言就会隐式帮你转换成变量类型 - - - 弱类型语言 - - javaScript - - - 强类型语言 - - - Python -- java - - - C -- C++ - -#### 运行我们第一个Python程序 - -- 使用Pycharm新建第一个项目 -- 运行我们的第一个python程序 -- 编辑模式和交互模式 - - 就是在编辑器中写好代码再运行 - - 交互模式会立刻打印当前对象的值 - -1. - -![image-20201216145611584](C:\Users\dk\AppData\Roaming\Typora\typora-user-images\image-20201216145611584.png) - -2. - +# 第一周-第一节课-随堂笔记 + +#### 养成良好的学习习惯 + +- 做好笔记和文档 + + - typora + + - 创建标题 + + ``` + ctrl + 数字 + ``` + + - 创建代码块 + + ``` + ctrl + shift +k + ``` + +- 科学的探索习惯 + - 官方文档和GitHub库 + - StackOverflow + - 简书和知乎 + - Goole和百度 +- 良好的学习心态 + - 面向需求学习 + - 需要什么学什么 + - 有效率地学习 + - 自己搜索10分钟 + - 及时提问 + +#### 编程语言的基本概述 + +- 编程语言有哪些分类? + + ``` + c + c++ + java + python + javascript + ``` + + - 编译型语言,解释性语言和混合型语言 + - 动态语言和静态语言 + - 强类型语言和弱类型语言 + +- 什么是动态语言?什么是静态语言? + + 编译时不知道变量类型的叫做动态语言,反之,知道变量类型的就叫静态语言 + + - 动态语言 + - python + - javascript + + - 静态语言 + - c + - c++ + - java + +- 什么是强类型语言?什么是弱类型语言? + + 在使用变量时,不会自动地改变变量的类型,反之,弱类型语言就会隐式帮你转换成变量类型 + + - 弱类型语言 + - javaScript + + - 强类型语言 + + - Python +- java + + - C +- C++ + +#### 运行我们第一个Python程序 + +- 使用Pycharm新建第一个项目 +- 运行我们的第一个python程序 +- 编辑模式和交互模式 + - 就是在编辑器中写好代码再运行 + - 交互模式会立刻打印当前对象的值 + +1. + +![image-20201216145611584](C:\Users\dk\AppData\Roaming\Typora\typora-user-images\image-20201216145611584.png) + +2. + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/main.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/main.py" index b9c81e8817d8c407941b5ae3e2c270db07bf8a9c..5af4b94cd40708382d640b802cd267be5edf862b 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/main.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/main.py" @@ -1,15 +1,15 @@ -a = 1 -b = 1.2 -c = "str" -d = True -e = b'123' -f = None - -aList = [a, b, c, d, e, f] # 列表有序,可更改 -aTuple = (a, b, c, d, e, f) # 元组有序,不可更改 -aDict = {"int": a, "float": b, "string": c, "boolean": d, "bytes": e, "None": f} # 字典无序,可更改 -aSet = {a, b, c, d, e, f} # 集合无序,可更改 -print(aList) -print(aTuple) -print(aDict) -print(aSet) +a = 1 +b = 1.2 +c = "str" +d = True +e = b'123' +f = None + +aList = [a, b, c, d, e, f] # 列表有序,可更改 +aTuple = (a, b, c, d, e, f) # 元组有序,不可更改 +aDict = {"int": a, "float": b, "string": c, "boolean": d, "bytes": e, "None": f} # 字典无序,可更改 +aSet = {a, b, c, d, e, f} # 集合无序,可更改 +print(aList) +print(aTuple) +print(aDict) +print(aSet) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 558c4c3a2b28080f2e98ffcad1232aa101c8d33f..fd21e37c984130ce5d3de3c4ef086123454d38c9 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.19\357\274\211/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,237 +1,237 @@ -## 第一周-第三节课-随堂笔记 - -## 变量和赋值 - -- 什么是变量 - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可重新赋值 - -- 为变量赋值 - - - 通过`=`来赋值 - - ``` - x = 3 - ``` - - - 被重新赋值之后的值去哪了? - - - 被系统回收了. - -- Python的常量 - - - python没有常量这个数据类型 - - 程序员之间的约定: 如果这个变量的命名都是大写字母, 那么就视为一个常量 - -## Python的六大基本类型 - -``` -*强调基本的原因数据类型和数据结构指向的范围更加广泛, 不要产生错误的认知, 形成思维定式 -``` - -- 通过`type()`函数来查看当前变量的数据类型 - -- `int` (整数) - - ``` - int('1') - ``` - -- `float`(浮点数) - - ``` - float('1.0') - float('INF') - ``` - - - 因为计算机内部只认识1和0, 所以浮点数强调的时小数的表现形式 - -- `string`(字符串, 字符序列) - - ``` - str(2) - ``` - - - 在有些语言中, 单个字符也是一个基本的数据类型(`Char`) - - - 有序的 - - - 如何表示字符串 - - - `''` - - `""` - - `''''''` - - `""""""` - - - 转义字符 - - 告诉python解释器, 我们当前要表示的是一个字符或者是特殊字符 - - - 通过`\`来转义 - - ``` - "2\"" - "2\n" - ``` - -- `boolean`(布尔值) - - ``` - bool(2) - bool(0) - ``` - - 用来表示`True`或者`False` - - - `True` 等价于1 - - `False`等价于0 - -- `bytes`(二进制序列) - - 二进制的表示形式 - -- `None`(空) - - - 有了`False`和`0` 为什么还要有`None` - - 因为`False`和`0`有时候也代表了一种结果 - -## Python的四大基本数据结构 - -- `list`(列表) - - - 什么是列表? - - 用来装载**不同数据类型**的数据集结构 - - - 列表的特点 - - - 有序的 - - 可以装载任意数据类型 - - 可以更改的 - - - 如何表示`list` - - - 通过`list()`新建一个列表 - - ``` - list("hello world") - ``` - - - 通过`[]`声明一个列表 - - ``` - a = [1, 2, 3] - ``` - -- `tuple`(元组) - - - 什么是元组? - - 可以简单地认为, 元组就是不可修改的列表, 常用来表示记录. - - - 元组的特点? - - - 有序的 - - 可以装载任意数据类型 - - 不可更改 - - - 如何表示`tuple` - - - 通过`tuple()`新建一个元组 - - ``` - tuple("hello") - ``` - - - 通过`(,)`来声明一个元组 - - ``` - a = (1, 2, 3) - - #声明单个元素的元组, 要添加逗号 - a = (1, ) - ``` - -- `dict`(字典) - - - 什么是字典? - - 字典也叫`hashtable`, 通过`hash`(散列)函数将传入的`key`值生成地址来查找`value` - - `key` -> `hash`函数 -> 返回了`value`的地址 -> 通过地址返回`value`值 - - - 字典的特点? - - - 无序的 - - `python3.6`是有序的, 无视这一点. - - - 字典中的`key`必须是可`hash`的, 也就是不可更改的, 唯一的 - - - 可以更改的 - - - 如何表示字典 - - - 通过`dict()`来创建字典 - - ``` - dict(a=2) - ``` - - - 通过`{}`来声明一个字典 - - ``` - a = {"a": 2} - ``` - -- `set`(集合) - - - 什么是`set` - - `set`其实是没有`value`的字典 - - - 集合的特点 - - - 无序的 - - 集合中的`key`必须是可`hash`的 - - 可以更改的 - - 元素是唯一的 - - - 如何表示`set` - - - 通过`set()`来创建集合 - - ``` - set([1,2,2]) - ``` - - - 通过`{}`来表示 - - ``` - {1, 2, 3} - ``` - -## 课后作业 - -- 四大基本数据结构中哪些是可变的, 哪些是不可变的? - - tuple不可变的。 - - list,dict,set 可变的。 - -- 四大基本数据结构中哪些是有序的, 哪些是无序的? - - list,tuple有序的 - - set,dict无序的 - +## 第一周-第三节课-随堂笔记 + +## 变量和赋值 + +- 什么是变量 + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可重新赋值 + +- 为变量赋值 + + - 通过`=`来赋值 + + ``` + x = 3 + ``` + + - 被重新赋值之后的值去哪了? + + - 被系统回收了. + +- Python的常量 + + - python没有常量这个数据类型 + - 程序员之间的约定: 如果这个变量的命名都是大写字母, 那么就视为一个常量 + +## Python的六大基本类型 + +``` +*强调基本的原因数据类型和数据结构指向的范围更加广泛, 不要产生错误的认知, 形成思维定式 +``` + +- 通过`type()`函数来查看当前变量的数据类型 + +- `int` (整数) + + ``` + int('1') + ``` + +- `float`(浮点数) + + ``` + float('1.0') + float('INF') + ``` + + - 因为计算机内部只认识1和0, 所以浮点数强调的时小数的表现形式 + +- `string`(字符串, 字符序列) + + ``` + str(2) + ``` + + - 在有些语言中, 单个字符也是一个基本的数据类型(`Char`) + + - 有序的 + + - 如何表示字符串 + + - `''` + - `""` + - `''''''` + - `""""""` + + - 转义字符 + + 告诉python解释器, 我们当前要表示的是一个字符或者是特殊字符 + + - 通过`\`来转义 + + ``` + "2\"" + "2\n" + ``` + +- `boolean`(布尔值) + + ``` + bool(2) + bool(0) + ``` + + 用来表示`True`或者`False` + + - `True` 等价于1 + - `False`等价于0 + +- `bytes`(二进制序列) + + 二进制的表示形式 + +- `None`(空) + + - 有了`False`和`0` 为什么还要有`None` + + 因为`False`和`0`有时候也代表了一种结果 + +## Python的四大基本数据结构 + +- `list`(列表) + + - 什么是列表? + + 用来装载**不同数据类型**的数据集结构 + + - 列表的特点 + + - 有序的 + - 可以装载任意数据类型 + - 可以更改的 + + - 如何表示`list` + + - 通过`list()`新建一个列表 + + ``` + list("hello world") + ``` + + - 通过`[]`声明一个列表 + + ``` + a = [1, 2, 3] + ``` + +- `tuple`(元组) + + - 什么是元组? + + 可以简单地认为, 元组就是不可修改的列表, 常用来表示记录. + + - 元组的特点? + + - 有序的 + - 可以装载任意数据类型 + - 不可更改 + + - 如何表示`tuple` + + - 通过`tuple()`新建一个元组 + + ``` + tuple("hello") + ``` + + - 通过`(,)`来声明一个元组 + + ``` + a = (1, 2, 3) + + #声明单个元素的元组, 要添加逗号 + a = (1, ) + ``` + +- `dict`(字典) + + - 什么是字典? + + 字典也叫`hashtable`, 通过`hash`(散列)函数将传入的`key`值生成地址来查找`value` + + `key` -> `hash`函数 -> 返回了`value`的地址 -> 通过地址返回`value`值 + + - 字典的特点? + + - 无序的 + + `python3.6`是有序的, 无视这一点. + + - 字典中的`key`必须是可`hash`的, 也就是不可更改的, 唯一的 + + - 可以更改的 + + - 如何表示字典 + + - 通过`dict()`来创建字典 + + ``` + dict(a=2) + ``` + + - 通过`{}`来声明一个字典 + + ``` + a = {"a": 2} + ``` + +- `set`(集合) + + - 什么是`set` + + `set`其实是没有`value`的字典 + + - 集合的特点 + + - 无序的 + - 集合中的`key`必须是可`hash`的 + - 可以更改的 + - 元素是唯一的 + + - 如何表示`set` + + - 通过`set()`来创建集合 + + ``` + set([1,2,2]) + ``` + + - 通过`{}`来表示 + + ``` + {1, 2, 3} + ``` + +## 课后作业 + +- 四大基本数据结构中哪些是可变的, 哪些是不可变的? + + tuple不可变的。 + + list,dict,set 可变的。 + +- 四大基本数据结构中哪些是有序的, 哪些是无序的? + + list,tuple有序的 + + set,dict无序的 + - 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\2101.2\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\2101.2\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" index ee2e0d0fc12c4d85162ed9b1ab63eac47f19da2c..9556a7850017b2f7b41deac7a4dc7a08c24005e1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\2101.2\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\2101.2\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232.py" @@ -1,86 +1,86 @@ -from time import time - -# 作用域之间的转换 -# 将局部变量变成全局变量 -a = 1 - - -def foo(): - global a - a = 2 - print(a) - - -foo() -print(a) - - -# 将局部变量变成自由变量 - - -def make_averager(): - total = 0 - count = 0 - - def averager(value): - nonlocal total, count - total += value - count += 1 - return total / count - - return averager - - -my_avg = make_averager() -print(my_avg(1)) -print(my_avg(2)) - - -# 输出函数执行时间装饰器 -def clock_it_deco(fun): - def wrapper(*args, **kwargs): - start_time = time() - result = fun(*args, **kwargs) - end_time = time() - print(f"{fun.__name__} 执行时间:{format(end_time - start_time, '.2f')} 秒") - return result - - return wrapper - - -@clock_it_deco -def foo(a, b): - count = 1 - while True: - if count > a ** b: - break - count += 1 - - -foo(10, 5) - -# fibo缓存 -a = {} - - -def cache_deco(func): - global a - - def wrap(n): - if n not in a: - a[n] = func(n) - return a[n] - - return wrap - - -@cache_deco -def fib(n): - if n < 2: - return n - else: - return fib(n - 2) + fib(n - 1) - - -print(fib(10)) -print(a) +from time import time + +# 作用域之间的转换 +# 将局部变量变成全局变量 +a = 1 + + +def foo(): + global a + a = 2 + print(a) + + +foo() +print(a) + + +# 将局部变量变成自由变量 + + +def make_averager(): + total = 0 + count = 0 + + def averager(value): + nonlocal total, count + total += value + count += 1 + return total / count + + return averager + + +my_avg = make_averager() +print(my_avg(1)) +print(my_avg(2)) + + +# 输出函数执行时间装饰器 +def clock_it_deco(fun): + def wrapper(*args, **kwargs): + start_time = time() + result = fun(*args, **kwargs) + end_time = time() + print(f"{fun.__name__} 执行时间:{format(end_time - start_time, '.2f')} 秒") + return result + + return wrapper + + +@clock_it_deco +def foo(a, b): + count = 1 + while True: + if count > a ** b: + break + count += 1 + + +foo(10, 5) + +# fibo缓存 +a = {} + + +def cache_deco(func): + global a + + def wrap(n): + if n not in a: + a[n] = func(n) + return a[n] + + return wrap + + +@cache_deco +def fib(n): + if n < 2: + return n + else: + return fib(n - 2) + fib(n - 1) + + +print(fib(10)) +print(a) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\2101.1\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\2101.1\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" index 07de476ee035d08bfe5685b192f444dca1e2c1a2..3f05acbac404e1720386632c27972e30655dd754 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\2101.1\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\2101.1\357\274\211/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202-\344\275\234\344\270\232.py" @@ -1,49 +1,49 @@ -from pprint import pprint - -# 第一问 -classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, -] -# l = sorted(classes,key=lambda x:x['grade']) -# 根据grade进行排序 -classes.sort(key=lambda x: x['grade']) -pprint(classes) -print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") - -# 通过filter语句来筛选出Grade为A的同学 -f = filter(lambda x: True if x["grade"] == "A" else False, classes) -pprint(list(f)) -print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") - - -# 第三问 age加1 -def add(n): - n["age"] += 1 - return n - - -m = map(add, classes) -pprint(list(m)) -print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") - - -# 递归函数构造斐波那契数列 - - -def f(n): - if n == 0: - return 0 - elif n == 1: - return 1 - else: - return f(n - 2) + f(n - 1) - - -for n in range(10): - print(f(n)) +from pprint import pprint + +# 第一问 +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] +# l = sorted(classes,key=lambda x:x['grade']) +# 根据grade进行排序 +classes.sort(key=lambda x: x['grade']) +pprint(classes) +print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + +# 通过filter语句来筛选出Grade为A的同学 +f = filter(lambda x: True if x["grade"] == "A" else False, classes) +pprint(list(f)) +print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + + +# 第三问 age加1 +def add(n): + n["age"] += 1 + return n + + +m = map(add, classes) +pprint(list(m)) +print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + + +# 递归函数构造斐波那契数列 + + +def f(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return f(n - 2) + f(n - 1) + + +for n in range(10): + print(f(n)) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.22\357\274\211/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.22\357\274\211/my_calculator.py" index 8a3bd13eeaa6d89738ef1ba880dde755269e65f9..b591da29beb6b2d2413bc23852e1f9e0ceeacd87 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.22\357\274\211/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.22\357\274\211/my_calculator.py" @@ -1,26 +1,26 @@ -def add(a, b): - return a + b - - -def sub(a, b): - return a - b - - -def mul(a, b): - return a * b - - -def divide(a, b): - return a / b - - -def edivide(a, b): - return a // b - - -def getremainder(a, b): - return a % b - - -def sqrt(a, b): - return a ** (1/b) +def add(a, b): + return a + b + + +def sub(a, b): + return a - b + + +def mul(a, b): + return a * b + + +def divide(a, b): + return a / b + + +def edivide(a, b): + return a // b + + +def getremainder(a, b): + return a % b + + +def sqrt(a, b): + return a ** (1/b) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.26\357\274\211/Oerator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.26\357\274\211/Oerator.py" index 615574e3894f35874d7be4561a9f243e8775d368..a4d8e468a76faffe76bed04d4b8908736477615f 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.26\357\274\211/Oerator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\211\350\212\202_\344\275\234\344\270\232\357\274\21012.26\357\274\211/Oerator.py" @@ -1,84 +1,84 @@ -# List(列表) -# create -print("~~~~~~~~~~~~create~~~~~~~~~~~~~~~~") -l = [] -l.append("a") -print(l) -l += ['b'] -print(l) -l *= 2 -print(l) -l.insert(0, 'e') -print(l) - -# retrieve -print("~~~~~~~~~~~~~retrieve~~~~~~~~~~~~~") -print(l[0]) -# 取一段区间 -print(l[0:3]) -# 取最后一个值 -print(l[-1]) -# 间隔问题 -print(l[0::2]) - -# index -print("~~~~~~~~~~~~~index~~~~~~~~~~~~~") -print(l.index('a')) - -# Update(更新) -print("~~~~~~~~~~~~~Update~~~~~~~~~~~~~") -l[0] = 'a_1' -print(l) -# 切片赋值 -l[0:2] = 'a' -print(l) - -# DELETE -print("~~~~~~~~~~~~~DELETE~~~~~~~~~~~~~") -x = l.pop() -print(l) - -# SORT -l2 = [2, 1, 4, 3] -l2.sort() -print(l2) -l2.reverse() -print(l2) - -# dict -print("~~~~~~~~~~~~~dict~~~~~~~~~~~~~") -d = {} -d['a'] = 1 -print(d) -d2 = {"b": 2, "c": 3} -d.update(d2) -print(d) -d.setdefault('d', 0) -print(d) -print(d.get('c', 0)) -print(d.keys()) -print(d.values()) -print(d.items()) -# update -d.update({"b": 200, "c": 300}) -print(d) -# delete -d.pop("a") -print(d) - -# set -print("~~~~~~~~~~~~~set~~~~~~~~~~~~~") -s = set() -s.add("a") -print(s) -# Retrieve -print("a" in s) -# update -s2 = {"b", "c"} -s3 =s.union(s2) -print(s3) -# delete -s3.remove("a") -print(s3) -s3.pop() +# List(列表) +# create +print("~~~~~~~~~~~~create~~~~~~~~~~~~~~~~") +l = [] +l.append("a") +print(l) +l += ['b'] +print(l) +l *= 2 +print(l) +l.insert(0, 'e') +print(l) + +# retrieve +print("~~~~~~~~~~~~~retrieve~~~~~~~~~~~~~") +print(l[0]) +# 取一段区间 +print(l[0:3]) +# 取最后一个值 +print(l[-1]) +# 间隔问题 +print(l[0::2]) + +# index +print("~~~~~~~~~~~~~index~~~~~~~~~~~~~") +print(l.index('a')) + +# Update(更新) +print("~~~~~~~~~~~~~Update~~~~~~~~~~~~~") +l[0] = 'a_1' +print(l) +# 切片赋值 +l[0:2] = 'a' +print(l) + +# DELETE +print("~~~~~~~~~~~~~DELETE~~~~~~~~~~~~~") +x = l.pop() +print(l) + +# SORT +l2 = [2, 1, 4, 3] +l2.sort() +print(l2) +l2.reverse() +print(l2) + +# dict +print("~~~~~~~~~~~~~dict~~~~~~~~~~~~~") +d = {} +d['a'] = 1 +print(d) +d2 = {"b": 2, "c": 3} +d.update(d2) +print(d) +d.setdefault('d', 0) +print(d) +print(d.get('c', 0)) +print(d.keys()) +print(d.values()) +print(d.items()) +# update +d.update({"b": 200, "c": 300}) +print(d) +# delete +d.pop("a") +print(d) + +# set +print("~~~~~~~~~~~~~set~~~~~~~~~~~~~") +s = set() +s.add("a") +print(s) +# Retrieve +print("a" in s) +# update +s2 = {"b", "c"} +s3 =s.union(s2) +print(s3) +# delete +s3.remove("a") +print(s3) +s3.pop() print(s3) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\21012.24\357\274\211/test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\21012.24\357\274\211/test.py" index 7fb600ce3db8a027915810bd810c0e0c9b83de59..7e4822c612b94222414932bfd13916bad088b9f1 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\21012.24\357\274\211/test.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\346\213\206\346\213\206\346\213\206/\347\254\254\344\272\214\345\221\250_\347\254\254\344\272\214\350\212\202_\344\275\234\344\270\232\357\274\21012.24\357\274\211/test.py" @@ -1,75 +1,75 @@ -# 字符串的编码 -a = "你好" -b = a.encode("utf-8") -print(f"你好的编码是:{b}") -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# 字符串的解码 -c = b.decode() -print(f"{b}的解码是:" + c) -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# 字符串的CRUD - -# Create(创建) -str1 = " hello" -str1 += ', world ' -print(str1) -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# Retrieve(检索) -# 根据索引获取字符 -print(str1[4]) -# find和index(获取目标字符的索引值) -print(str1.find("e")) -print(str1.index("l")) -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# UPDATE(更新) -# replace(替换) -str2 = str1.replace("wor", "wer") -print(str2) -# split(分割) -str3 = str2.split(",") -print(str3) -# join(拼接) -str4 = '*'.join(str3) -print(str4) -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# DELETE(删除) -# strip -str5 = str1.strip() -print(str5) - -# 保存到文件 -output = open("out.txt", "w", encoding="utf-8") -content = "hello" -output.write(content) -output.close() - -# 读取文件 -input = open("out.txt", "r", encoding="utf-8") -content = input.read() -print(content) - -# 追加文件 -output = open("output.txt", "a", encoding="utf-8") -content = "\nhello, world" -output.write(content) -output.close() -print("~~~~~~~~~~~~~~~~~~~~~~~") - -# format -a1 = "ping" -b1 = "pong" -# 按传入参数默认顺序 -print("play pingpong: {}, {}".format(a1, b1)) -# 按指定参数索引 -print("play pingpong: {0}, {1}, {0}, {1}".format(a1, b1)) -# 按变量 -print(f"playing pingpong: {a1}, {b1}") -# 小数的表示 -print("{:.2f}".format(3.1415926)) -# % +# 字符串的编码 +a = "你好" +b = a.encode("utf-8") +print(f"你好的编码是:{b}") +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# 字符串的解码 +c = b.decode() +print(f"{b}的解码是:" + c) +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# 字符串的CRUD + +# Create(创建) +str1 = " hello" +str1 += ', world ' +print(str1) +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# Retrieve(检索) +# 根据索引获取字符 +print(str1[4]) +# find和index(获取目标字符的索引值) +print(str1.find("e")) +print(str1.index("l")) +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# UPDATE(更新) +# replace(替换) +str2 = str1.replace("wor", "wer") +print(str2) +# split(分割) +str3 = str2.split(",") +print(str3) +# join(拼接) +str4 = '*'.join(str3) +print(str4) +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# DELETE(删除) +# strip +str5 = str1.strip() +print(str5) + +# 保存到文件 +output = open("out.txt", "w", encoding="utf-8") +content = "hello" +output.write(content) +output.close() + +# 读取文件 +input = open("out.txt", "r", encoding="utf-8") +content = input.read() +print(content) + +# 追加文件 +output = open("output.txt", "a", encoding="utf-8") +content = "\nhello, world" +output.write(content) +output.close() +print("~~~~~~~~~~~~~~~~~~~~~~~") + +# format +a1 = "ping" +b1 = "pong" +# 按传入参数默认顺序 +print("play pingpong: {}, {}".format(a1, b1)) +# 按指定参数索引 +print("play pingpong: {0}, {1}, {0}, {1}".format(a1, b1)) +# 按变量 +print(f"playing pingpong: {a1}, {b1}") +# 小数的表示 +print("{:.2f}".format(3.1415926)) +# % print("playing %s %s" % ("ping", "pong")) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\351\231\210\347\245\216\347\245\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232.12.21-12.28/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_calculator.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\351\231\210\347\245\216\347\245\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232.12.21-12.28/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_calculator.py" index 4e06cc4d7e221fe15b5019f6e359cd6373160762..522c092ae3f5ee839a973c4c5c9efc39a5f7415a 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\351\231\210\347\245\216\347\245\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232.12.21-12.28/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_calculator.py" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\351\231\210\347\245\216\347\245\272/\347\254\254\344\272\214\345\221\250\344\275\234\344\270\232.12.21-12.28/\347\254\254\344\272\214\345\221\250_\347\254\254\344\270\200\350\212\202\344\275\234\344\270\232/my_calculator.py" @@ -1,14 +1,14 @@ -def add(a, b): - return a+b -def min(a, b): - return a-b -def mul(a, b): - return a*b -def div(a, b): - return a/b -def ZC(a, b): - return a%b -def QY(a, b): - return a//b -def sqrt(a, b): +def add(a, b): + return a+b +def min(a, b): + return a-b +def mul(a, b): + return a*b +def div(a, b): + return a/b +def ZC(a, b): + return a%b +def QY(a, b): + return a//b +def sqrt(a, b): return a**(1/b) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/\346\241\210\344\276\213\357\274\2325\347\217\255_\346\234\261\345\205\210\346\243\256/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.15\357\274\211.assets/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\347\254\224\350\256\260\357\274\2101215\357\274\211.md" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/\346\241\210\344\276\213\357\274\2325\347\217\255_\346\234\261\345\205\210\346\243\256/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.15\357\274\211.assets/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\347\254\224\350\256\260\357\274\2101215\357\274\211.md" index 44f0518e458c771be83f2c4d8d212ba44106d549..b68790caf0b32054ffcf9629db24e06422a6ba89 100644 --- "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/\346\241\210\344\276\213\357\274\2325\347\217\255_\346\234\261\345\205\210\346\243\256/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.15\357\274\211.assets/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\347\254\224\350\256\260\357\274\2101215\357\274\211.md" +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/\346\241\210\344\276\213\357\274\2325\347\217\255_\346\234\261\345\205\210\346\243\256/\347\254\254\344\270\200\345\221\250\344\275\234\344\270\232.12.14 - 12.20/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\344\275\234\344\270\232\357\274\21012.15\357\274\211.assets/\347\254\254\344\270\200\345\221\250_\347\254\254\344\270\200\350\212\202_\347\254\224\350\256\260\357\274\2101215\357\274\211.md" @@ -1,49 +1,49 @@ -# 第一周_第一节(1215) - -## typora - -``` -typora软件的下载、安装、简单实用; -创建标题、创建代码块的常用快捷键; -``` - -## python学习:常用网址 - -``` -python官方文档 -https://stackoverflow.com/ -github -简书、知乎、百度、csdn -学习心态:面向需求、独立思考; -``` - -## 插件: - -``` -阻挡广告的插件: -https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm -训练营使用手册:https://docs.qq.com/doc/DWVFMRVNmZld4VUFw?_t=1608042640106 -``` - -## 编程语言 - -- ### 编程语言分类 - -``` -编译型、解释型、混合型; -动态和静态语言: -静态语言:编译时变量类型是已知的;java、c、c++ -动态语言:编译时变量类型是未知的;python、js -强类型语言和弱类型语言: -强类型语言:使用变量时不会自动改变变量类型;python、java、c、c++ -弱类型语言:使用变量时会自改变变量类型;js -``` - -## python环境搭建 - -## 课后作业 - -1、添加环境变量; -2、python安装; -3、phpstorm打印数据; - +# 第一周_第一节(1215) + +## typora + +``` +typora软件的下载、安装、简单实用; +创建标题、创建代码块的常用快捷键; +``` + +## python学习:常用网址 + +``` +python官方文档 +https://stackoverflow.com/ +github +简书、知乎、百度、csdn +学习心态:面向需求、独立思考; +``` + +## 插件: + +``` +阻挡广告的插件: +https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm +训练营使用手册:https://docs.qq.com/doc/DWVFMRVNmZld4VUFw?_t=1608042640106 +``` + +## 编程语言 + +- ### 编程语言分类 + +``` +编译型、解释型、混合型; +动态和静态语言: +静态语言:编译时变量类型是已知的;java、c、c++ +动态语言:编译时变量类型是未知的;python、js +强类型语言和弱类型语言: +强类型语言:使用变量时不会自动改变变量类型;python、java、c、c++ +弱类型语言:使用变量时会自改变变量类型;js +``` + +## python环境搭建 + +## 课后作业 + +1、添加环境变量; +2、python安装; +3、phpstorm打印数据; + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 29d166e8c2c7aea2818111c863799b885c55a18e..fa12e8753348aa6db68d9b9c43980eb3bb0218a2 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,172 +1,172 @@ -# 第一周-第一节课-随堂笔记 - -## 养成良好的学习习惯 - -- 不要相信自己的记忆力, 做好笔记和文档 - - - `typora` - - ``` - https://typora.io/ - ``` - - - 创建标题 - - ``` - ctrl + 数字 - ``` - - - 创建目录列表结构 - - ``` - - + 空格 - ``` - - - 创建代码块 - - ``` - ctrl+shift+k - ``` - -- 科学的搜索习惯 - - - 官方文档和`github`库 - - ``` - https://docs.python.org/zh-cn/3.6/tutorial/index.html - https://github.com/ - ``` - - - StackOverflow(英语比较好的同学) - - ``` - https://stackoverflow.com/ - ``` - - - 简书和知乎 - - - 百度搜索 - -- 良好的学习心态 - - - 面向需求学习 - - 有效率地学习 - - 自己思索10分钟 - - 不要担心自己的问题太小白, 要及时地询问 - - 尽量在大群中讨论 - - - -## 编程语言的基本概述 - -- 什么是编程语言? - - 相对于人与人之间的沟通, 编程语言是人与计算机之间交互的媒介. - -- 代码的执行流程 - - 代码 -> 机器码 -> 由计算机的处理器来执行 - - - 把代码翻译为机器的翻译就是编译器, 在Python中也可以叫Python解释器 - - 编程语言Python是我们与解释器之间的翻译 - - 解释器是Python与计算机之间的翻译 - -- 编程语言有哪些分类? - - ``` - C - C++ - Java - Python - JavaScript - ``` - - - 编译型语言, 解释性语言和混合型语言 - - 动态语言和静态语言 - - 强类型语言和弱类型语言 - -- 什么是动态语言?什么是静态语言? - - 编译时不知道变量类型的叫做动态语言, 反之, 编译时知道变量类型的就叫做静态语言. - - - 动态语言 - - Python - - javascript - - 静态语言 - - C - - C++ - - Java - -- 什么是强类型语言? 什么是弱类型语言? - - 在使用变量时, 不会自动地改变变量的类型, 反之, 弱类型语言就会隐式帮你转换变量类型 - - - 弱类型语言 - - javascript - - 强类型语言 - - Python - - Java - - C - - C++ - -## Python环境的搭建 - -- Python下载 - - ``` - https://www.python.org/downloads/ - ``` - -- Python的安装 - - - 务必记住自己安装的目录 - - 环境变量的设置 - -- IDE的下载 - - ``` - https://www.jetbrains.com/pycharm/download/#section=windows - ``` - -- IDE的安装 - -## 运行我们第一个Python程序 - -- 使用Pycharm新建第一个项目 - -- 运行我们的第一个python程序 - -- 编辑模式和交互模式 - - - 就是在编辑器中写好代码再运行 - - 交互模式会立刻打印当前对象的值 - -- 可能会遇到的问题 - - - 无法运行, 找不到python - - Pycharm添加Python解释器环境 - - - `SyntaxError: EOL while scanning string literal` - - 单引号和双引号没有正确的关闭 - - - `SyntaxError: invalid character in identifier` - - Python关键词中使用了中文字符 - - - 缩进问题 - - ``` - 一般都是使用tab进行缩进的 - ``` - - ``` - IndentationError: unexpected indent - IndentationError: expected an indented block - ``` - -## 课后作业 - -- Python环境的搭建 +# 第一周-第一节课-随堂笔记 + +## 养成良好的学习习惯 + +- 不要相信自己的记忆力, 做好笔记和文档 + + - `typora` + + ``` + https://typora.io/ + ``` + + - 创建标题 + + ``` + ctrl + 数字 + ``` + + - 创建目录列表结构 + + ``` + - + 空格 + ``` + + - 创建代码块 + + ``` + ctrl+shift+k + ``` + +- 科学的搜索习惯 + + - 官方文档和`github`库 + + ``` + https://docs.python.org/zh-cn/3.6/tutorial/index.html + https://github.com/ + ``` + + - StackOverflow(英语比较好的同学) + + ``` + https://stackoverflow.com/ + ``` + + - 简书和知乎 + + - 百度搜索 + +- 良好的学习心态 + + - 面向需求学习 + - 有效率地学习 + - 自己思索10分钟 + - 不要担心自己的问题太小白, 要及时地询问 + - 尽量在大群中讨论 + + + +## 编程语言的基本概述 + +- 什么是编程语言? + + 相对于人与人之间的沟通, 编程语言是人与计算机之间交互的媒介. + +- 代码的执行流程 + + 代码 -> 机器码 -> 由计算机的处理器来执行 + + - 把代码翻译为机器的翻译就是编译器, 在Python中也可以叫Python解释器 + - 编程语言Python是我们与解释器之间的翻译 + - 解释器是Python与计算机之间的翻译 + +- 编程语言有哪些分类? + + ``` + C + C++ + Java + Python + JavaScript + ``` + + - 编译型语言, 解释性语言和混合型语言 + - 动态语言和静态语言 + - 强类型语言和弱类型语言 + +- 什么是动态语言?什么是静态语言? + + 编译时不知道变量类型的叫做动态语言, 反之, 编译时知道变量类型的就叫做静态语言. + + - 动态语言 + - Python + - javascript + - 静态语言 + - C + - C++ + - Java + +- 什么是强类型语言? 什么是弱类型语言? + + 在使用变量时, 不会自动地改变变量的类型, 反之, 弱类型语言就会隐式帮你转换变量类型 + + - 弱类型语言 + - javascript + - 强类型语言 + - Python + - Java + - C + - C++ + +## Python环境的搭建 + +- Python下载 + + ``` + https://www.python.org/downloads/ + ``` + +- Python的安装 + + - 务必记住自己安装的目录 + - 环境变量的设置 + +- IDE的下载 + + ``` + https://www.jetbrains.com/pycharm/download/#section=windows + ``` + +- IDE的安装 + +## 运行我们第一个Python程序 + +- 使用Pycharm新建第一个项目 + +- 运行我们的第一个python程序 + +- 编辑模式和交互模式 + + - 就是在编辑器中写好代码再运行 + - 交互模式会立刻打印当前对象的值 + +- 可能会遇到的问题 + + - 无法运行, 找不到python + + Pycharm添加Python解释器环境 + + - `SyntaxError: EOL while scanning string literal` + + 单引号和双引号没有正确的关闭 + + - `SyntaxError: invalid character in identifier` + + Python关键词中使用了中文字符 + + - 缩进问题 + + ``` + 一般都是使用tab进行缩进的 + ``` + + ``` + IndentationError: unexpected indent + IndentationError: expected an indented block + ``` + +## 课后作业 + +- Python环境的搭建 - 练习添加环境变量 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 1bc7198b04f464428da473d96f7a50c32327b076..d4082f9ade9e85693087179a669285b6229cf0fe 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,227 +1,227 @@ -## 第一周-第三节课-随堂笔记 - -## 变量和赋值 - -- 什么是变量 - - - 一个实体的指代 - - - 查看变量的内存地址 - - ``` - id(x) - ``` - - - 可重新赋值 - -- 为变量赋值 - - - 通过`=`来赋值 - - ``` - x = 3 - ``` - - - 被重新赋值之后的值去哪了? - - - 被系统回收了. - -- Python的常量 - - - python没有常量这个数据类型 - - 程序员之间的约定: 如果这个变量的命名都是大写字母, 那么就视为一个常量 - -## Python的六大基本类型 - -``` -*强调基本的原因数据类型和数据结构指向的范围更加广泛, 不要产生错误的认知, 形成思维定式 -``` - -- 通过`type()`函数来查看当前变量的数据类型 - -- `int` (整数) - - ``` - int('1') - ``` - -- `float`(浮点数) - - ``` - float('1.0') - float('INF') - ``` - - - 因为计算机内部只认识1和0, 所以浮点数强调的时小数的表现形式 - -- `string`(字符串, 字符序列) - - ``` - str(2) - ``` - - - 在有些语言中, 单个字符也是一个基本的数据类型(`Char`) - - - 有序的 - - - 如何表示字符串 - - - `''` - - `""` - - `''''''` - - `""""""` - - - 转义字符 - - 告诉python解释器, 我们当前要表示的是一个字符或者是特殊字符 - - - 通过`\`来转义 - - ``` - "2\"" - "2\n" - ``` - -- `boolean`(布尔值) - - ``` - bool(2) - bool(0) - ``` - - 用来表示`True`或者`False` - - - `True` 等价于1 - - `False`等价于0 - -- `bytes`(二进制序列) - - 二进制的表示形式 - -- `None`(空) - - - 有了`False`和`0` 为什么还要有`None` - - 因为`False`和`0`有时候也代表了一种结果 - -## Python的四大基本数据结构 - -- `list`(列表) - - - 什么是列表? - - 用来装载**不同数据类型**的数据集结构 - - - 列表的特点 - - - 有序的 - - 可以装载任意数据类型 - - 可以更改的 - - - 如何表示`list` - - - 通过`list()`新建一个列表 - - ``` - list("hello world") - ``` - - - 通过`[]`声明一个列表 - - ``` - a = [1, 2, 3] - ``` - -- `tuple`(元组) - - - 什么是元组? - - 可以简单地认为, 元组就是不可修改的列表, 常用来表示记录. - - - 元组的特点? - - - 有序的 - - 可以装载任意数据类型 - - 不可更改 - - - 如何表示`tuple` - - - 通过`tuple()`新建一个元组 - - ``` - tuple("hello") - ``` - - - 通过`(,)`来声明一个元组 - - ``` - a = (1, 2, 3) - - #声明单个元素的元组, 要添加逗号 - a = (1, ) - ``` - -- `dict`(字典) - - - 什么是字典? - - 字典也叫`hashtable`, 通过`hash`(散列)函数将传入的`key`值生成地址来查找`value` - - `key` -> `hash`函数 -> 返回了`value`的地址 -> 通过地址返回`value`值 - - - 字典的特点? - - - 无序的 - - `python3.6`是有序的, 无视这一点. - - - 字典中的`key`必须是可`hash`的, 也就是不可更改的, 唯一的 - - - 可以更改的 - - - 如何表示字典 - - - 通过`dict()`来创建字典 - - ``` - dict(a=2) - ``` - - - 通过`{}`来声明一个字典 - - ``` - a = {"a": 2} - ``` - -- `set`(集合) - - - 什么是`set` - - `set`其实是没有`value`的字典 - - - 集合的特点 - - - 无序的 - - 集合中的`key`必须是可`hash`的 - - 可以更改的 - - 元素是唯一的 - - - 如何表示`set` - - - 通过`set()`来创建集合 - - ``` - set([1,2,2]) - ``` - - - 通过`{}`来表示 - - ``` - {1, 2, 3} - ``` - -## 课后作业 - -- 四大基本数据结构中哪些是可变的, 哪些是不可变的? -- 四大基本数据结构中哪些是有序的, 哪些是无序的? +## 第一周-第三节课-随堂笔记 + +## 变量和赋值 + +- 什么是变量 + + - 一个实体的指代 + + - 查看变量的内存地址 + + ``` + id(x) + ``` + + - 可重新赋值 + +- 为变量赋值 + + - 通过`=`来赋值 + + ``` + x = 3 + ``` + + - 被重新赋值之后的值去哪了? + + - 被系统回收了. + +- Python的常量 + + - python没有常量这个数据类型 + - 程序员之间的约定: 如果这个变量的命名都是大写字母, 那么就视为一个常量 + +## Python的六大基本类型 + +``` +*强调基本的原因数据类型和数据结构指向的范围更加广泛, 不要产生错误的认知, 形成思维定式 +``` + +- 通过`type()`函数来查看当前变量的数据类型 + +- `int` (整数) + + ``` + int('1') + ``` + +- `float`(浮点数) + + ``` + float('1.0') + float('INF') + ``` + + - 因为计算机内部只认识1和0, 所以浮点数强调的时小数的表现形式 + +- `string`(字符串, 字符序列) + + ``` + str(2) + ``` + + - 在有些语言中, 单个字符也是一个基本的数据类型(`Char`) + + - 有序的 + + - 如何表示字符串 + + - `''` + - `""` + - `''''''` + - `""""""` + + - 转义字符 + + 告诉python解释器, 我们当前要表示的是一个字符或者是特殊字符 + + - 通过`\`来转义 + + ``` + "2\"" + "2\n" + ``` + +- `boolean`(布尔值) + + ``` + bool(2) + bool(0) + ``` + + 用来表示`True`或者`False` + + - `True` 等价于1 + - `False`等价于0 + +- `bytes`(二进制序列) + + 二进制的表示形式 + +- `None`(空) + + - 有了`False`和`0` 为什么还要有`None` + + 因为`False`和`0`有时候也代表了一种结果 + +## Python的四大基本数据结构 + +- `list`(列表) + + - 什么是列表? + + 用来装载**不同数据类型**的数据集结构 + + - 列表的特点 + + - 有序的 + - 可以装载任意数据类型 + - 可以更改的 + + - 如何表示`list` + + - 通过`list()`新建一个列表 + + ``` + list("hello world") + ``` + + - 通过`[]`声明一个列表 + + ``` + a = [1, 2, 3] + ``` + +- `tuple`(元组) + + - 什么是元组? + + 可以简单地认为, 元组就是不可修改的列表, 常用来表示记录. + + - 元组的特点? + + - 有序的 + - 可以装载任意数据类型 + - 不可更改 + + - 如何表示`tuple` + + - 通过`tuple()`新建一个元组 + + ``` + tuple("hello") + ``` + + - 通过`(,)`来声明一个元组 + + ``` + a = (1, 2, 3) + + #声明单个元素的元组, 要添加逗号 + a = (1, ) + ``` + +- `dict`(字典) + + - 什么是字典? + + 字典也叫`hashtable`, 通过`hash`(散列)函数将传入的`key`值生成地址来查找`value` + + `key` -> `hash`函数 -> 返回了`value`的地址 -> 通过地址返回`value`值 + + - 字典的特点? + + - 无序的 + + `python3.6`是有序的, 无视这一点. + + - 字典中的`key`必须是可`hash`的, 也就是不可更改的, 唯一的 + + - 可以更改的 + + - 如何表示字典 + + - 通过`dict()`来创建字典 + + ``` + dict(a=2) + ``` + + - 通过`{}`来声明一个字典 + + ``` + a = {"a": 2} + ``` + +- `set`(集合) + + - 什么是`set` + + `set`其实是没有`value`的字典 + + - 集合的特点 + + - 无序的 + - 集合中的`key`必须是可`hash`的 + - 可以更改的 + - 元素是唯一的 + + - 如何表示`set` + + - 通过`set()`来创建集合 + + ``` + set([1,2,2]) + ``` + + - 通过`{}`来表示 + + ``` + {1, 2, 3} + ``` + +## 课后作业 + +- 四大基本数据结构中哪些是可变的, 哪些是不可变的? +- 四大基本数据结构中哪些是有序的, 哪些是无序的? - 创建`set`, `list`, `dict`, `tuple`实例, 每个数据结构的实例需要包括六大基本类型. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 72baa9dfb66ceebd3a959867725f0d2e9c301267..6c495431405ffdcd034502f7030ceb461a68b116 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\200\345\221\250-Python\345\237\272\347\241\200/\347\254\254\344\270\200\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,175 +1,175 @@ -# 第一周-第二节课-随堂笔记 - -## 我们如何通过GIT来提交作业 - -### 什么是GIT? - -最强大的**分布式****版本控制**系统 - -- 分布式 - - 分布式的意思就是大家fork之后的库, 就像细胞分裂一样, 彼此之间是平等, 可以互相合并代码. - - 我们`fork`远程库之后, 当前这个库就已经属于我们自己了. - - ``` - * 为了教学方便, 我们人为地设置了码育谷远程库作为我们的主库. - ``` - -- 版本控制 - - 通过分支切换, 来完成对不同版本的代码控制 - -### 我们日常工作中如何使用GIT? - -- 安装git - - ``` - https://git-scm.com/download - ``` - -- 将git添加到环境变量 - - ``` - xxx\Git\cmd - ``` - -- 如何在`Pycharm`中配置git - - ``` - https://jingyan.baidu.com/article/ff42efa9c7bd12c19e22028a.html - ``` - - - 查看安装的路径 - - ``` - - where git - - which git - ``` - -- 如何使用git - - - 本地上传到远程库 - - - 在代码托管平台新建远程库 - - - 配置用户(一个环境只用配置一次) - - - 初始化一个git仓库(本地代码仓库) - - ``` - git init - ``` - - - 配置远程仓库(远程代码仓库) - - ``` - git remote add origin https://gitee.com/tunangit/git_test.git - ``` - - - 新建`.gitignore`文件 - - 用来屏蔽不需要提交到项目的文件和文件夹 - - - 默认要屏蔽的文件和文件夹 - - `.idea` - - `.git` - - `/venv/` - - `/test` - - `*/__pycache__/` - - - 选择要提交的项目文件 - - - 批量全部添加(不建议) - - ``` - git add ./* - ``` - - - 添加单个文件 - - ``` - git add xx/xx - ``` - - - 通过Pycharm手动添加 - - - 提交项目 - - - commit - - 提交到你的本地库 - - - push - - 提交到远程库 - - - commit and push - - 二合一, 提交到本地库和远程库 - - - 远程库同步到本地库 - - ``` - https://gitee.com/xxx/xxxx.git - ``` - - - 更新代码 - - ``` - git pull - ``` - - - 解决代码冲突 - - 当本地代码更新时发现和远程代码有冲突 - - - 左边是本地当前的代码 - - 右边是远程库的代码 - - 中间是最后选取的结果 - - - 历史回滚 - - - 右键目标文件或者文件夹, 点击history - - 回滚部分代码 -> 在弹出矿口右侧进行修改 - - 整个文件回滚 -> 右键revert - - - **注意事项** - - - 一定要先新建`.gitigonre` - - 不要在服务器/生产环境下直接修改代码 - -## python的虚拟环境 - -``` -*新建一个新项目的时候, 一定要先新建一个虚拟环境 -``` - -一个与系统环境隔离的空间 - -- 虚拟环境的好处 - - - 与系统环境隔离, 不会污染正式环境 - - 更新项目方便简洁 - - 通过`requirements.txt`解决不同平台, 不同环境下的环境同步问题 - -- 新建虚拟环境 - - ``` - python -m venv venv - ``` - -- 激活虚拟环境 - - ``` - # windows - venv\Scripts\Activate.bat - - # unix (mac, ubuntu, centos) - source venv/bin/activate - ``` - -## 课后作业 - -- 新建一个项目, 建立虚拟环境, 在Pycharm配置虚拟环境. +# 第一周-第二节课-随堂笔记 + +## 我们如何通过GIT来提交作业 + +### 什么是GIT? + +最强大的**分布式****版本控制**系统 + +- 分布式 + + 分布式的意思就是大家fork之后的库, 就像细胞分裂一样, 彼此之间是平等, 可以互相合并代码. + + 我们`fork`远程库之后, 当前这个库就已经属于我们自己了. + + ``` + * 为了教学方便, 我们人为地设置了码育谷远程库作为我们的主库. + ``` + +- 版本控制 + + 通过分支切换, 来完成对不同版本的代码控制 + +### 我们日常工作中如何使用GIT? + +- 安装git + + ``` + https://git-scm.com/download + ``` + +- 将git添加到环境变量 + + ``` + xxx\Git\cmd + ``` + +- 如何在`Pycharm`中配置git + + ``` + https://jingyan.baidu.com/article/ff42efa9c7bd12c19e22028a.html + ``` + + - 查看安装的路径 + + ``` + - where git + - which git + ``` + +- 如何使用git + + - 本地上传到远程库 + + - 在代码托管平台新建远程库 + + - 配置用户(一个环境只用配置一次) + + - 初始化一个git仓库(本地代码仓库) + + ``` + git init + ``` + + - 配置远程仓库(远程代码仓库) + + ``` + git remote add origin https://gitee.com/tunangit/git_test.git + ``` + + - 新建`.gitignore`文件 + + 用来屏蔽不需要提交到项目的文件和文件夹 + + - 默认要屏蔽的文件和文件夹 + - `.idea` + - `.git` + - `/venv/` + - `/test` + - `*/__pycache__/` + + - 选择要提交的项目文件 + + - 批量全部添加(不建议) + + ``` + git add ./* + ``` + + - 添加单个文件 + + ``` + git add xx/xx + ``` + + - 通过Pycharm手动添加 + + - 提交项目 + + - commit + + 提交到你的本地库 + + - push + + 提交到远程库 + + - commit and push + + 二合一, 提交到本地库和远程库 + + - 远程库同步到本地库 + + ``` + https://gitee.com/xxx/xxxx.git + ``` + + - 更新代码 + + ``` + git pull + ``` + + - 解决代码冲突 + + 当本地代码更新时发现和远程代码有冲突 + + - 左边是本地当前的代码 + - 右边是远程库的代码 + - 中间是最后选取的结果 + + - 历史回滚 + + - 右键目标文件或者文件夹, 点击history + - 回滚部分代码 -> 在弹出矿口右侧进行修改 + - 整个文件回滚 -> 右键revert + + - **注意事项** + + - 一定要先新建`.gitigonre` + - 不要在服务器/生产环境下直接修改代码 + +## python的虚拟环境 + +``` +*新建一个新项目的时候, 一定要先新建一个虚拟环境 +``` + +一个与系统环境隔离的空间 + +- 虚拟环境的好处 + + - 与系统环境隔离, 不会污染正式环境 + - 更新项目方便简洁 + - 通过`requirements.txt`解决不同平台, 不同环境下的环境同步问题 + +- 新建虚拟环境 + + ``` + python -m venv venv + ``` + +- 激活虚拟环境 + + ``` + # windows + venv\Scripts\Activate.bat + + # unix (mac, ubuntu, centos) + source venv/bin/activate + ``` + +## 课后作业 + +- 新建一个项目, 建立虚拟环境, 在Pycharm配置虚拟环境. - 建立git仓库, 并同步到码云. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 74344723d6e0faffebba28ee59424c9406d3d97e..1bc5f2ee084460c5b4a4a7930c31e278377192d0 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,209 +1,209 @@ -# 第七周-第一节课 - -## 数据库的基本介绍 - -- 关系型数据库 - - 创建在**关系模型基础上**的数据库, 用来存储和管理结构化的数据. - - - 关系模型 - - ``` - 类似python中类 - class Student: - def __init__(self, name, classes ...): - self.name = name - self.classes = classes - - def borrow(self, book): - print(f"student {self.name} borrow {book.name}") - - class Book: - pass - ``` - - > 在关系型数据库当中, 可以用三张数据表来表示 - > - > 1. 学生表 - > 2. 图书表 - > 3. 借阅表(记录行为) - - ![QmLj4.jpg](https://i.im5i.com/2021/01/24/QmLj4.jpg) - - - 关系型数据库的特点(也就是事务的特点) - - - ACID - - - Atomic(原子性) - - 指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 - - ``` - A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. - ``` - - - Consistence(一致性) - - 事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. - - ``` - 集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. - 一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. - ``` - - - Isolation(隔离性) - - 解决多个事务**同时**对数据进行读写和修改的能力. - - - Duration(持久性) - - 当某个事务一旦提交, 无论数据库崩溃还是其他原因, 该事务的结果都能够被持久化地保存下来. - - ``` - 事务的所有操作都是有记录的, 即使数据库中途崩溃, 仍然可以通过记录恢复 - ``` - - - 适用场景 - - 考虑到事务和日志 - - - 对数据完整性有要求. - - - 存储的数据结构化完整. - - - **单个**数据库服务实例可以满足需求. - - > 建立集群方案, 大多需要适用企业版, 企业版收费高昂. - - - 读表操作远远大于写表操作. - -- 非关系型数据库(`Nosql, not noly sql`) - - 创建在`Nosql`系统存储(键对值)基础上的数据库, 既可以存储结构化的数据, 也可以存储非结构化的数据. - -## Mysql数据库的安装(服务端) - -> 数据库分为服务端和客户端 - -- windows - - ``` - https://jingyan.baidu.com/article/9f7e7ec0ebac9a6f281554dd.html - ``` - -- ubuntu - - ``` - apt-get install mysql-server - # 登录 - mysql -u root -p - ``` - -- mac - - ``` - https://jingyan.baidu.com/article/b7001fe1c7cc260e7382dd66.html - ``` - -## Navicat的安装和使用(客户端) - -- windows&ubuntu - - ``` - http://www.navicat.com.cn/ - ``` - -- mac - - ``` - SequelPro - ``` - -## Mysql数据库的基本使用 - -- 连接 - - - localhost - - > 填写主机的时候就是填写ip地址 - - localhost对应的地址约等于`127.0.0.1` - -- 数据库(database) - - - Create - - ``` - create database tunan_class_2; - ``` - - - 设置字符集 - - - `utf8`和`utf8mb4` - - `mysql`中`utf8`字符是不全的, `utf8mb4`才是和我们python中的`utf-8`字符集一致. - - - 排序规则 - - 选择默认的`utf8mb4_general_ci` - - - Retrieve - - ``` - show databases; - ``` - - - Update - - ``` - ALTER database tunan_class_2 DEFAULT CHARACTER SET 'utf8mb4' - ``` - - - Delete - - ``` - drop database 库名 - ``` - -- 数据表(table) - - - Create - - ``` - use tunan_class; - CREATE TABLE class_2( - id int PRIMARY KEY auto_increment, - student_name varchar(255) - )DEFAULT charset=utf8mb4; - ``` - - - Retrieve - - ``` - show tables; - ``` - - - Update - - ``` - ALTER TABLE class_2 RENAME class_3; - ``` - - - Delete - - ``` - drop table 表名 - ``` - - - 只删除数据, 不删除表 - - ``` - truncate 表名 - ``` - -## 课后作业 - -- 什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. -- 什么是事务, 事务的特点. -- 完成Mysql服务端和Navicat的安装. +# 第七周-第一节课 + +## 数据库的基本介绍 + +- 关系型数据库 + + 创建在**关系模型基础上**的数据库, 用来存储和管理结构化的数据. + + - 关系模型 + + ``` + 类似python中类 + class Student: + def __init__(self, name, classes ...): + self.name = name + self.classes = classes + + def borrow(self, book): + print(f"student {self.name} borrow {book.name}") + + class Book: + pass + ``` + + > 在关系型数据库当中, 可以用三张数据表来表示 + > + > 1. 学生表 + > 2. 图书表 + > 3. 借阅表(记录行为) + + ![QmLj4.jpg](https://i.im5i.com/2021/01/24/QmLj4.jpg) + + - 关系型数据库的特点(也就是事务的特点) + + - ACID + + - Atomic(原子性) + + 指事务的操作是不可分割的, 要么完成, 要么不完成. 不存在其他的中间态 + + ``` + A -> B 转账, 如果中途中断, 那么整个银行系统就会崩溃. + ``` + + - Consistence(一致性) + + 事务A和事务B同时运行, 无论谁先结束, 数据库都会到达一致. + + ``` + 集合点在东方明珠, 同学A从静安出发, 同学B从黄埔出发. + 一致性不关心A和B谁先到达, 只关心最终两者都在东方明珠汇合. + ``` + + - Isolation(隔离性) + + 解决多个事务**同时**对数据进行读写和修改的能力. + + - Duration(持久性) + + 当某个事务一旦提交, 无论数据库崩溃还是其他原因, 该事务的结果都能够被持久化地保存下来. + + ``` + 事务的所有操作都是有记录的, 即使数据库中途崩溃, 仍然可以通过记录恢复 + ``` + + - 适用场景 + + 考虑到事务和日志 + + - 对数据完整性有要求. + + - 存储的数据结构化完整. + + - **单个**数据库服务实例可以满足需求. + + > 建立集群方案, 大多需要适用企业版, 企业版收费高昂. + + - 读表操作远远大于写表操作. + +- 非关系型数据库(`Nosql, not noly sql`) + + 创建在`Nosql`系统存储(键对值)基础上的数据库, 既可以存储结构化的数据, 也可以存储非结构化的数据. + +## Mysql数据库的安装(服务端) + +> 数据库分为服务端和客户端 + +- windows + + ``` + https://jingyan.baidu.com/article/9f7e7ec0ebac9a6f281554dd.html + ``` + +- ubuntu + + ``` + apt-get install mysql-server + # 登录 + mysql -u root -p + ``` + +- mac + + ``` + https://jingyan.baidu.com/article/b7001fe1c7cc260e7382dd66.html + ``` + +## Navicat的安装和使用(客户端) + +- windows&ubuntu + + ``` + http://www.navicat.com.cn/ + ``` + +- mac + + ``` + SequelPro + ``` + +## Mysql数据库的基本使用 + +- 连接 + + - localhost + + > 填写主机的时候就是填写ip地址 + + localhost对应的地址约等于`127.0.0.1` + +- 数据库(database) + + - Create + + ``` + create database tunan_class_2; + ``` + + - 设置字符集 + + - `utf8`和`utf8mb4` + + `mysql`中`utf8`字符是不全的, `utf8mb4`才是和我们python中的`utf-8`字符集一致. + + - 排序规则 + + 选择默认的`utf8mb4_general_ci` + + - Retrieve + + ``` + show databases; + ``` + + - Update + + ``` + ALTER database tunan_class_2 DEFAULT CHARACTER SET 'utf8mb4' + ``` + + - Delete + + ``` + drop database 库名 + ``` + +- 数据表(table) + + - Create + + ``` + use tunan_class; + CREATE TABLE class_2( + id int PRIMARY KEY auto_increment, + student_name varchar(255) + )DEFAULT charset=utf8mb4; + ``` + + - Retrieve + + ``` + show tables; + ``` + + - Update + + ``` + ALTER TABLE class_2 RENAME class_3; + ``` + + - Delete + + ``` + drop table 表名 + ``` + + - 只删除数据, 不删除表 + + ``` + truncate 表名 + ``` + +## 课后作业 + +- 什么是关系型数据表, 什么是非关系型数据表, 他们有什么区别, 各有什么应用场景. +- 什么是事务, 事务的特点. +- 完成Mysql服务端和Navicat的安装. - 完成数据库和数据表的基础操作. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 68cd95feb7b9c442f52801ec3157fdb65526adf1..2938f5ca43df57a5728a0c8ee14d7808511cc9e4 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,187 +1,187 @@ -# 第七周-第三节课 - -> 创建表的时候尽量加上create_time字段, 为create_time设置默认值CURRENT_TIMESTAMP - -## CRUD操作 - -- Create(增) - - - 单条插入 - - ``` - INSERT INTO 表名(字段1, 字段2..) VALUES(值1, 值2) - - INSERT INTO class_1(name) VALUES('name_1') - ``` - - - 多条插入 - - ``` - INSERT INTO 表名(字段1, 字段2..) VALUES(值1, 值2), (值1, 值2) - ``` - -- Retrieve(查) - - - 获取所有记录 - - ``` - SELECT 字段1, 字段2 FROM 表名 - - SELECT name FROM class_1 - SELECT * FROM class_1 - ``` - - - 条件查询(`WHERE`, `AND` , `OR`) - - ``` - SELECT 字段1, 字段2 FROM 表名 WHERE 表达式 - - SELECT * FROM class_1 WHERE name="name_1" AND id=8 - ``` - - - 模糊匹配(`LIKE`, `%`) - - > 模糊匹配有性能问题, 表记录如果比较多, 查询速度很慢 - - ``` - SELECT 字段1, 字段2 FROM 表名 WHERE 表达式 - - SELECT * FROM class_1 WHERE name LIKE "%m%" - ``` - - - 限制返回条数(`LIMIT`) - - ``` - 查询表达式 LIMIT 数量 - ``` - - - 过滤重复值(`DISTINCT`) - - 对查询的结果进行过滤. - - > 如果指定多个字段, 会对多个字段联合进行过滤 - - ``` - SELECT DISTINCT 字段1, 字段2 FROM 表名 [条件语句] - - SELECT distinct name, create_time FROM class_1 WHERE name like '%m%' - ``` - - - 排序问题 - - 对查询的结果进行排序 - - - 升序(`ASC`) - - 数据库默认是升序的 - - ``` - 查询表达式 ORDER BY 字段 ASC - ``` - - - 降序(`DESC`) - - ``` - 查询表达式 ORDER BY 字段 DESC - ``` - - - 获取查询结果的条数(`COUNT`) - - ``` - SELECT COUNT(*) FROM 表名 [条件语句] - ``` - -- Update(更新) - - ``` - UPDATE 表名 SET 字段1=新值, 字段2=新值 WHERE 表达式 - - UPDATE class_1 SET name='name_0' WHERE id=8 - ``` - -- Delete(删除) - - ``` - DELETE FROM 表名 WHERE 表达式 - - DELETE FROM class_1 WHERE name='name_0' - ``` - -## 集合操作 - -![](https://book.itheima.net/uploads/course/python/images/Python_Basics/1.5.3.2/clip_image002.png) - -- 并集`UNION` - - 子语句SELECT 必须拥有相同数量的列(字段), 且列的数据类型也相同 - - ``` - SELECT name from class_1 WHERE name is not NULL - UNION - SELECT name from class_2 WHERE name is not NULL - ``` - -- 交集(`JOIN`, `INNER JOIN`) - - ``` - SELECT s1.name FROM - (SELECT name from class_1 WHERE name is not NULL) as s1 - JOIN - (SELECT name from class_2 WHERE name is not NULL) as s2 - ON s1.name=s2.name - ``` - -- 差集(`LEFT JOIN`, `RIGHT JOIN`) - - - A对B的差集(`LEFT JOIN`) - - ``` - SELECT * FROM // s1对s2的差集, select就可以使用s1.name - (SELECT name from class_1 WHERE name is not NULL) as s1 - LEFT JOIN - (SELECT name from class_2 WHERE name is not NULL) as s2 - ON s1.name=s2.name - WHERE s2.name is NULL // 限定s1有, s2没有的记录 - ``` - - - B对A的差集(`RIGHT JOIN`) - - ``` - SELECT * FROM - (SELECT name from class_1 WHERE name is not NULL) as s1 - RIGHT JOIN - (SELECT name from class_2 WHERE name is not NULL) as s2 - ON s1.name=s2.name - WHERE s1.name is NULL - ``` - -- 补集 - - > A与B的补集 = A与B的并集 - A与B的交集 - > - > A与B的补集 = A对B的差集 + B对A的差集 √ - - ``` - SELECT s1.name FROM - (SELECT name from class_1 WHERE name is not NULL) as s1 - LEFT JOIN - (SELECT name from class_2 WHERE name is not NULL) as s2 - ON s1.name=s2.name - WHERE s2.name is NULL - - UNION - - SELECT s2.name FROM - (SELECT name from class_1 WHERE name is not NULL) as s1 - RIGHT JOIN - (SELECT name from class_2 WHERE name is not NULL) as s2 - ON s1.name=s2.name - WHERE s1.name is NULL - ``` - -## 课后作业 - -- 练习CRUD操作 - -- 练习集合操作 - +# 第七周-第三节课 + +> 创建表的时候尽量加上create_time字段, 为create_time设置默认值CURRENT_TIMESTAMP + +## CRUD操作 + +- Create(增) + + - 单条插入 + + ``` + INSERT INTO 表名(字段1, 字段2..) VALUES(值1, 值2) + + INSERT INTO class_1(name) VALUES('name_1') + ``` + + - 多条插入 + + ``` + INSERT INTO 表名(字段1, 字段2..) VALUES(值1, 值2), (值1, 值2) + ``` + +- Retrieve(查) + + - 获取所有记录 + + ``` + SELECT 字段1, 字段2 FROM 表名 + + SELECT name FROM class_1 + SELECT * FROM class_1 + ``` + + - 条件查询(`WHERE`, `AND` , `OR`) + + ``` + SELECT 字段1, 字段2 FROM 表名 WHERE 表达式 + + SELECT * FROM class_1 WHERE name="name_1" AND id=8 + ``` + + - 模糊匹配(`LIKE`, `%`) + + > 模糊匹配有性能问题, 表记录如果比较多, 查询速度很慢 + + ``` + SELECT 字段1, 字段2 FROM 表名 WHERE 表达式 + + SELECT * FROM class_1 WHERE name LIKE "%m%" + ``` + + - 限制返回条数(`LIMIT`) + + ``` + 查询表达式 LIMIT 数量 + ``` + + - 过滤重复值(`DISTINCT`) + + 对查询的结果进行过滤. + + > 如果指定多个字段, 会对多个字段联合进行过滤 + + ``` + SELECT DISTINCT 字段1, 字段2 FROM 表名 [条件语句] + + SELECT distinct name, create_time FROM class_1 WHERE name like '%m%' + ``` + + - 排序问题 + + 对查询的结果进行排序 + + - 升序(`ASC`) + + 数据库默认是升序的 + + ``` + 查询表达式 ORDER BY 字段 ASC + ``` + + - 降序(`DESC`) + + ``` + 查询表达式 ORDER BY 字段 DESC + ``` + + - 获取查询结果的条数(`COUNT`) + + ``` + SELECT COUNT(*) FROM 表名 [条件语句] + ``` + +- Update(更新) + + ``` + UPDATE 表名 SET 字段1=新值, 字段2=新值 WHERE 表达式 + + UPDATE class_1 SET name='name_0' WHERE id=8 + ``` + +- Delete(删除) + + ``` + DELETE FROM 表名 WHERE 表达式 + + DELETE FROM class_1 WHERE name='name_0' + ``` + +## 集合操作 + +![](https://book.itheima.net/uploads/course/python/images/Python_Basics/1.5.3.2/clip_image002.png) + +- 并集`UNION` + + 子语句SELECT 必须拥有相同数量的列(字段), 且列的数据类型也相同 + + ``` + SELECT name from class_1 WHERE name is not NULL + UNION + SELECT name from class_2 WHERE name is not NULL + ``` + +- 交集(`JOIN`, `INNER JOIN`) + + ``` + SELECT s1.name FROM + (SELECT name from class_1 WHERE name is not NULL) as s1 + JOIN + (SELECT name from class_2 WHERE name is not NULL) as s2 + ON s1.name=s2.name + ``` + +- 差集(`LEFT JOIN`, `RIGHT JOIN`) + + - A对B的差集(`LEFT JOIN`) + + ``` + SELECT * FROM // s1对s2的差集, select就可以使用s1.name + (SELECT name from class_1 WHERE name is not NULL) as s1 + LEFT JOIN + (SELECT name from class_2 WHERE name is not NULL) as s2 + ON s1.name=s2.name + WHERE s2.name is NULL // 限定s1有, s2没有的记录 + ``` + + - B对A的差集(`RIGHT JOIN`) + + ``` + SELECT * FROM + (SELECT name from class_1 WHERE name is not NULL) as s1 + RIGHT JOIN + (SELECT name from class_2 WHERE name is not NULL) as s2 + ON s1.name=s2.name + WHERE s1.name is NULL + ``` + +- 补集 + + > A与B的补集 = A与B的并集 - A与B的交集 + > + > A与B的补集 = A对B的差集 + B对A的差集 √ + + ``` + SELECT s1.name FROM + (SELECT name from class_1 WHERE name is not NULL) as s1 + LEFT JOIN + (SELECT name from class_2 WHERE name is not NULL) as s2 + ON s1.name=s2.name + WHERE s2.name is NULL + + UNION + + SELECT s2.name FROM + (SELECT name from class_1 WHERE name is not NULL) as s1 + RIGHT JOIN + (SELECT name from class_2 WHERE name is not NULL) as s2 + ON s1.name=s2.name + WHERE s1.name is NULL + ``` + +## 课后作业 + +- 练习CRUD操作 + +- 练习集合操作 + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index a5a7aa203f2e3c413c754b91f146d8a1ea2e4c80..bb3e31cd5c7c2896700bcfc8d79eb9ef9a11718b 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\203\345\221\250-Mysql\345\237\272\347\241\200/\347\254\254\344\270\203\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,193 +1,193 @@ -# 第七周-第二节课 - -## 常用的数据类型 - -- int - - 数字范围`-2**32 ~ 2**32-1` - -- bigint - - 数字范围`-2**63 ~ 2 ** 63-1` - -- float - - ``` - float(m,d), 其中m表示的是有效位, d表示小数位 - 有效位就是把当前的小数: 12345.12 转变成科学计数法: 1.234512 * 10**5 - m最大值为7 - ``` - -- double - - ``` - double(m, d), 其中m表示的是有效位, d表示小数位 - m的最大值为15 - ``` - -- decimal - - 涉及金额的时候使用decimal. - - ``` - double(m, d), 其中m表示的是有效位, d表示小数位 - m的最大值为65 - - 不会产生精度问题, 因为decimal没有精度损失的本质是因为它存的是字符串. - ``` - - --- - -- char - - 表示固定长度的字符串, 长度为255个字节 - - > 中文字符占据3~4个字节 - -- varchar - - 表示不定长的字符串, 长度为`0~65535`个字节 - -- TEXT - - 长文本类型, 最大长度占据`64kb` - - --- - -- datetime - - 如果当前时区发生更改, datetime类型不会发生更改, 与存入的日期保持一致. - -- timestamp - - 如果当前时区发生更改, timestamp类型会跟着时区更改. - -## 常用的运算符 - -- 算术运算符 - - `+` - - - `-` - - - `*` - - - `/` - - - div - - 取商 - - ``` - SELECT 5 div 3 - ``` - - - mod - - 取余 - - ``` - SELECT 5 mod 3 - ``` - -- 比较运算符 - - - `=` - - ``` - 类似python中的 == - - SELECT 1 =1 - ``` - - - `!=` - - - `>` 与`>=` - - - `<`与`<=` - - - `between` 与`not between` - - ``` - SELECT 2 not between 1 and 3 - ``` - - - `is null` 与 `is not null` - - 用来判断当前是否有记录 - -- 逻辑运算符 - - - NOT - - - AND - - - OR - - - XOR(了解) - - 异或, 两个值一个True, 一个为False, 当前表达式才为True - -## 常用的函数 - -- 算术运算 - - - SUM - - 和 - - - AVG - - 平均数 - - - MAX和MIN - - ``` - 对字符串进行操作时, 类似python的排序, 是根据ascii码来排序的. - ``` - - - COUNT - - ``` - 计算当前记录数 - SELECT count(*) from test - ``` - -- 字符处理 - - - CHAR_LENGTH - - ``` - SELECT CHAR_LENGTH("test") - ``` - - - FORMAT - - 格式化 - - ``` - SELECT FORMAT(0.333333,2) - ``` - - - LEFT和RIGHT - - ``` - SELECT right("abcdefg", 2) - ``` - - - TRIM - - ``` - SELECT trim("abcdefg ") - ``` - -## 课后作业 - -- 通过navicat建表, 包含当前常用的数据类型. - - ``` - INSERT INTO test(float_field, double_field) values(123.22, 123123.22) - ``` - -- 练习常用的运算符 - +# 第七周-第二节课 + +## 常用的数据类型 + +- int + + 数字范围`-2**32 ~ 2**32-1` + +- bigint + + 数字范围`-2**63 ~ 2 ** 63-1` + +- float + + ``` + float(m,d), 其中m表示的是有效位, d表示小数位 + 有效位就是把当前的小数: 12345.12 转变成科学计数法: 1.234512 * 10**5 + m最大值为7 + ``` + +- double + + ``` + double(m, d), 其中m表示的是有效位, d表示小数位 + m的最大值为15 + ``` + +- decimal + + 涉及金额的时候使用decimal. + + ``` + double(m, d), 其中m表示的是有效位, d表示小数位 + m的最大值为65 + + 不会产生精度问题, 因为decimal没有精度损失的本质是因为它存的是字符串. + ``` + + --- + +- char + + 表示固定长度的字符串, 长度为255个字节 + + > 中文字符占据3~4个字节 + +- varchar + + 表示不定长的字符串, 长度为`0~65535`个字节 + +- TEXT + + 长文本类型, 最大长度占据`64kb` + + --- + +- datetime + + 如果当前时区发生更改, datetime类型不会发生更改, 与存入的日期保持一致. + +- timestamp + + 如果当前时区发生更改, timestamp类型会跟着时区更改. + +## 常用的运算符 + +- 算术运算符 + - `+` + + - `-` + + - `*` + + - `/` + + - div + + 取商 + + ``` + SELECT 5 div 3 + ``` + + - mod + + 取余 + + ``` + SELECT 5 mod 3 + ``` + +- 比较运算符 + + - `=` + + ``` + 类似python中的 == + + SELECT 1 =1 + ``` + + - `!=` + + - `>` 与`>=` + + - `<`与`<=` + + - `between` 与`not between` + + ``` + SELECT 2 not between 1 and 3 + ``` + + - `is null` 与 `is not null` + + 用来判断当前是否有记录 + +- 逻辑运算符 + + - NOT + + - AND + + - OR + + - XOR(了解) + + 异或, 两个值一个True, 一个为False, 当前表达式才为True + +## 常用的函数 + +- 算术运算 + + - SUM + + 和 + + - AVG + + 平均数 + + - MAX和MIN + + ``` + 对字符串进行操作时, 类似python的排序, 是根据ascii码来排序的. + ``` + + - COUNT + + ``` + 计算当前记录数 + SELECT count(*) from test + ``` + +- 字符处理 + + - CHAR_LENGTH + + ``` + SELECT CHAR_LENGTH("test") + ``` + + - FORMAT + + 格式化 + + ``` + SELECT FORMAT(0.333333,2) + ``` + + - LEFT和RIGHT + + ``` + SELECT right("abcdefg", 2) + ``` + + - TRIM + + ``` + SELECT trim("abcdefg ") + ``` + +## 课后作业 + +- 通过navicat建表, 包含当前常用的数据类型. + + ``` + INSERT INTO test(float_field, double_field) values(123.22, 123123.22) + ``` + +- 练习常用的运算符 + - 练习常用的函数 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 9bba152bf0023fb7abaf3ce9b1708bbf436336c1..bee866c1be6ab04d3e17db0d37030e79862f13c3 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,255 +1,255 @@ -# 第三周-第一节课 - -## Python的逻辑控制语句 - -- 条件判断语句 - - ![](https://ss.im5i.com/2020/12/26/-2.png) - - `if` - - - `elif` - - - `else` - - ``` - a = 50 - if a > 100: - print("a 超过阈值") - elif a == 50: - print("a 只有阈值的一半") - else: - print("a 小于阈值") - ``` - - - -- 循环语句 - - - `for` - - 遍历一个可迭代对象(暂时理解为list), 会影响相同作用域当中的变量 - - ``` - l = [1, 2, 3, 4, 5, 6] - e = 0 - - - for e in l: - print(e) - - print(f"final e value: {e}") - ``` - - - 获取索引值和值 - - ``` - l = [1, 2, 3, 4, 5, 6] - - - for i, e in enumerate(l): - print(f"index: {i}, value: {e}") - ``` - - - `while`循环 - - 一定要有逻辑判断语句来退出`while`循环 - - ``` - while 判断语句: - 表达式 - - while True: - 判断语句 - 表达式 - ``` - - - 跳出循环 - - - `break` - - 停止当前循环 - - - `continue` - - 跳过当前的执行逻辑, 立即执行下一个循环语句单元; - - - `pass` - - 跳过当前条件判断中的执行语句, 后续语句继续执行; - - - -## Python的异常与处理 - -- 异常 - - 程序遇到严重错误时, 会终止程序的运行并抛出异常 - - ``` - def my_sub(a, b): - return a / b - - my_sub(1, 0) - ``` - -- 捕获异常 - - ``` - try: - 表达式 - except [Exception] as e: - 表达式 - finnaly: - 表达式 - - - - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - # print(e) - print("分母不可为0") - return None - finally: - print("function my_sub end") - - my_sub(1, 0) - ``` - - - Exception - - 所有异常的基类, 所有的异常都是Exception的子类 - - - 处理异常颗粒度要细一点, 尽量不要捕获基类Exception, 尤其是数据处理的时候. - - - 常见的异常 - - - IndexError - - 索引值超过了列表长度 - - ``` - >>> l = [1] - >>> l[2] - Traceback (most recent call last): - File "", line 1, in - IndexError: list index out of range - - ``` - - - KeyError - - 找不到Key - - ``` - >>> d = {"a": 1} - >>> d["b"] - Traceback (most recent call last): - File "", line 1, in - KeyError: 'b' - ``` - - - ValueError - - 传入的参数错误 - - ``` - >>> int('a1') - Traceback (most recent call last): - File "", line 1, in - ValueError: invalid literal for int() with base 10: 'a1' - - ``` - - - TypeError - - 类型错误, 常见于运算 - - ``` - >>> 1 + '2' - Traceback (most recent call last): - File "", line 1, in - TypeError: unsupported operand type(s) for +: 'int' and 'str' - - ``` - - - SyntaxError - - 语法报错, 检查自己的语法有没有写错 - - - IndentationError - - 缩进错误 - - - 混用tab和space(空格) - - 缩进长度不对 - -- 如何处理异常 - - - 处理 - - - 抛出新异常 - - ``` - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - print("分母不可为0") - raise Exception("params error") - finally: - print("function my_sub end") - ``` - - - 重新抛出 - - ``` - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - print("分母不可为0") - raise ZeroDivisionError - finally: - print("function my_sub end") - ``` - - - 忽略(不推荐) - - `pass` - - 用来指示当前处理语句没有正式写完, 尽量不要忽略异常, 否则代码的健壮度会很差, 造成不可预知的bug. - -- 自定义异常 - - ``` - class ParamsError(Exception): - pass - - def my_sub(a, b): - try: - return a / b - except ZeroDivisionError: - raise ParamsError("分母不可以为0") - finally: - print("function my_sub end") - ``` - -## 课后作业 - -- 用for循环和while来完成简单的计数 - -- 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 - - - 斐波那契函数 - - 第N项是N-1, N-2的和 - - ``` - F(n)=F(n - 1)+F(n - 2) - - [0, 1, 1, 2, 3, 5, 8, 13, 21....] - ``` - +# 第三周-第一节课 + +## Python的逻辑控制语句 + +- 条件判断语句 + + ![](https://ss.im5i.com/2020/12/26/-2.png) + - `if` + + - `elif` + + - `else` + + ``` + a = 50 + if a > 100: + print("a 超过阈值") + elif a == 50: + print("a 只有阈值的一半") + else: + print("a 小于阈值") + ``` + + + +- 循环语句 + + - `for` + + 遍历一个可迭代对象(暂时理解为list), 会影响相同作用域当中的变量 + + ``` + l = [1, 2, 3, 4, 5, 6] + e = 0 + + + for e in l: + print(e) + + print(f"final e value: {e}") + ``` + + - 获取索引值和值 + + ``` + l = [1, 2, 3, 4, 5, 6] + + + for i, e in enumerate(l): + print(f"index: {i}, value: {e}") + ``` + + - `while`循环 + + 一定要有逻辑判断语句来退出`while`循环 + + ``` + while 判断语句: + 表达式 + + while True: + 判断语句 + 表达式 + ``` + + - 跳出循环 + + - `break` + + 停止当前循环 + + - `continue` + + 跳过当前的执行逻辑, 立即执行下一个循环语句单元; + + - `pass` + + 跳过当前条件判断中的执行语句, 后续语句继续执行; + + + +## Python的异常与处理 + +- 异常 + + 程序遇到严重错误时, 会终止程序的运行并抛出异常 + + ``` + def my_sub(a, b): + return a / b + + my_sub(1, 0) + ``` + +- 捕获异常 + + ``` + try: + 表达式 + except [Exception] as e: + 表达式 + finnaly: + 表达式 + + + + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + # print(e) + print("分母不可为0") + return None + finally: + print("function my_sub end") + + my_sub(1, 0) + ``` + + - Exception + + 所有异常的基类, 所有的异常都是Exception的子类 + + - 处理异常颗粒度要细一点, 尽量不要捕获基类Exception, 尤其是数据处理的时候. + + - 常见的异常 + + - IndexError + + 索引值超过了列表长度 + + ``` + >>> l = [1] + >>> l[2] + Traceback (most recent call last): + File "", line 1, in + IndexError: list index out of range + + ``` + + - KeyError + + 找不到Key + + ``` + >>> d = {"a": 1} + >>> d["b"] + Traceback (most recent call last): + File "", line 1, in + KeyError: 'b' + ``` + + - ValueError + + 传入的参数错误 + + ``` + >>> int('a1') + Traceback (most recent call last): + File "", line 1, in + ValueError: invalid literal for int() with base 10: 'a1' + + ``` + + - TypeError + + 类型错误, 常见于运算 + + ``` + >>> 1 + '2' + Traceback (most recent call last): + File "", line 1, in + TypeError: unsupported operand type(s) for +: 'int' and 'str' + + ``` + + - SyntaxError + + 语法报错, 检查自己的语法有没有写错 + + - IndentationError + + 缩进错误 + + - 混用tab和space(空格) + - 缩进长度不对 + +- 如何处理异常 + + - 处理 + + - 抛出新异常 + + ``` + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + print("分母不可为0") + raise Exception("params error") + finally: + print("function my_sub end") + ``` + + - 重新抛出 + + ``` + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + print("分母不可为0") + raise ZeroDivisionError + finally: + print("function my_sub end") + ``` + + - 忽略(不推荐) + + `pass` + + 用来指示当前处理语句没有正式写完, 尽量不要忽略异常, 否则代码的健壮度会很差, 造成不可预知的bug. + +- 自定义异常 + + ``` + class ParamsError(Exception): + pass + + def my_sub(a, b): + try: + return a / b + except ZeroDivisionError: + raise ParamsError("分母不可以为0") + finally: + print("function my_sub end") + ``` + +## 课后作业 + +- 用for循环和while来完成简单的计数 + +- 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内 + + - 斐波那契函数 + + 第N项是N-1, N-2的和 + + ``` + F(n)=F(n - 1)+F(n - 2) + + [0, 1, 1, 2, 3, 5, 8, 13, 21....] + ``` + - 在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常`ParamsError` \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 8172cf8fc58a3ece86de06a7b559ee78bb2d8c0f..1691ec308c323acd55579f6fc04e471f24009eea 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,180 +1,180 @@ -# 第三周-第三节课 - -## 作用域 - -程序创建, 访问, 改变一个变量时, 都是在一个保存该变量的空间内进行, 这个空间被称为命名空间, 即作用域 - -- `Built-in` 内置 - - - 可以在Python环境中的任何模块, 任意位置访问和调用 - -- `Global` 全局变量 - - - 只作用于当前模块(可以理解为当前文件) - - - 可以简单地理解为定以在函数外的变量就是全局变量, 如果在函数体定义那就时局部变量. - - - 如何将局部变量变成全局变量? - - - 使用`global`关键字 - - ``` - a = 1 - - def foo(): - global a - a = 2 - print(a) - - foo() - print(a) - ``` - -- `Enclosed(嵌套)` 自由变量 - - 在嵌套函数中, 访问函数体之外的非全局变量 - - - 只作用于嵌套函数体 - - - 最大的应用就是闭包 - - - 自由变量是个相对的概念 - - - 将局部变量变成自由变量 - - - 使用`nonlocal`关键字 - - ``` - def make_averager(): - total = 0 - count = 0 - def averager(value): - nonlocal total, count - total += value - count += 1 - return total / count - return averager - - my_avg = make_averager() - print(my_avg(1)) - print(my_avg(2)) - ``` - - - -- `Local`局部变量 - - - 只作用于当前函数体 - - - **一旦变量在函数体中赋值**, 那么该变量相对该函数来说就是局部变量 - - ``` - a = 1 - b = [] - - - def foo(): - a = 2 - b.append(2) - # 局部变量会在函数声明的时候就定义好 - # 不是按照我们逻辑思维上先执行全局变量b.append(2), 然后再声明一个局部变量b - # 而是再函数声明之初就已经定义了b为局部变量 - # b = 3 - return None - - foo() - print(a) - print(b) - ``` - - - -## 闭包和装饰器 - -- 闭包 - - 闭包指延申了作用域的函数, 也就是作用域中的`Enclosed`的概念 - - ``` - def make_averager(): - series = [] - def averager(value): - series.append(value) - total = sum(series) - return total / len(series) - return averager - - # my_avg就是延申了作用域的函数 - # series就是被延申作用域的变量 - my_avg = make_averager() - print(my_avg(1)) - print(my_avg(2)) - ``` - -- 装饰器 - - - 实现原理 - - 就是闭包, 延申了被装饰函数的作用域, 本质是将函数作为参数传递给一个可调用对象(函数或类) - - - 目的 - - 增加和扩展可调用对象(函数或类)的行为 - - - 实现一个装饰器 - - - 通过`@`关键字装饰函数 - - ``` - def clock_it_deco(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") - return result - return wrapper - - # @other_deco - @clock_it_deco - def foo(a, b): - count = 1 - while True: - if count > a ** b: - break - count += 1 - - foo(10, 5) - ``` - - - 等同于 - - ``` - foo = clock_it_deco(foo) - foo(10, 5) - ``` - -## 课后作业 - -- 背诵作用域的概念 - -- 练习作用域之间的转换 - -- 默写一个装饰器, 用来输出函数的执行时间. - -- 使用装饰器来为斐波那契函数添加缓存 - - ``` - def cache_deco(func): - # 保存n执行后的结果 - a = {} - # 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 - result = func(n) - return result - - @cache_deco - def fibo(n): - pass - ``` - +# 第三周-第三节课 + +## 作用域 + +程序创建, 访问, 改变一个变量时, 都是在一个保存该变量的空间内进行, 这个空间被称为命名空间, 即作用域 + +- `Built-in` 内置 + + - 可以在Python环境中的任何模块, 任意位置访问和调用 + +- `Global` 全局变量 + + - 只作用于当前模块(可以理解为当前文件) + + - 可以简单地理解为定以在函数外的变量就是全局变量, 如果在函数体定义那就时局部变量. + + - 如何将局部变量变成全局变量? + + - 使用`global`关键字 + + ``` + a = 1 + + def foo(): + global a + a = 2 + print(a) + + foo() + print(a) + ``` + +- `Enclosed(嵌套)` 自由变量 + + 在嵌套函数中, 访问函数体之外的非全局变量 + + - 只作用于嵌套函数体 + + - 最大的应用就是闭包 + + - 自由变量是个相对的概念 + + - 将局部变量变成自由变量 + + - 使用`nonlocal`关键字 + + ``` + def make_averager(): + total = 0 + count = 0 + def averager(value): + nonlocal total, count + total += value + count += 1 + return total / count + return averager + + my_avg = make_averager() + print(my_avg(1)) + print(my_avg(2)) + ``` + + + +- `Local`局部变量 + + - 只作用于当前函数体 + + - **一旦变量在函数体中赋值**, 那么该变量相对该函数来说就是局部变量 + + ``` + a = 1 + b = [] + + + def foo(): + a = 2 + b.append(2) + # 局部变量会在函数声明的时候就定义好 + # 不是按照我们逻辑思维上先执行全局变量b.append(2), 然后再声明一个局部变量b + # 而是再函数声明之初就已经定义了b为局部变量 + # b = 3 + return None + + foo() + print(a) + print(b) + ``` + + + +## 闭包和装饰器 + +- 闭包 + + 闭包指延申了作用域的函数, 也就是作用域中的`Enclosed`的概念 + + ``` + def make_averager(): + series = [] + def averager(value): + series.append(value) + total = sum(series) + return total / len(series) + return averager + + # my_avg就是延申了作用域的函数 + # series就是被延申作用域的变量 + my_avg = make_averager() + print(my_avg(1)) + print(my_avg(2)) + ``` + +- 装饰器 + + - 实现原理 + + 就是闭包, 延申了被装饰函数的作用域, 本质是将函数作为参数传递给一个可调用对象(函数或类) + + - 目的 + + 增加和扩展可调用对象(函数或类)的行为 + + - 实现一个装饰器 + + - 通过`@`关键字装饰函数 + + ``` + def clock_it_deco(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s") + return result + return wrapper + + # @other_deco + @clock_it_deco + def foo(a, b): + count = 1 + while True: + if count > a ** b: + break + count += 1 + + foo(10, 5) + ``` + + - 等同于 + + ``` + foo = clock_it_deco(foo) + foo(10, 5) + ``` + +## 课后作业 + +- 背诵作用域的概念 + +- 练习作用域之间的转换 + +- 默写一个装饰器, 用来输出函数的执行时间. + +- 使用装饰器来为斐波那契函数添加缓存 + + ``` + def cache_deco(func): + # 保存n执行后的结果 + a = {} + # 判断当前cache a中是否有结果, 有的话就直接返回, 没有就执行以下 + result = func(n) + return result + + @cache_deco + def fibo(n): + pass + ``` + \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 09fb250ecdfcbdc6d9d145c78dfcca70edeb2309..4a1dd84c5d37ef66c7dd609c69d976829d1c99e5 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\270\211\345\221\250-\345\207\275\346\225\260\345\222\214\346\265\201\347\250\213\346\216\247\345\210\266/\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,397 +1,397 @@ --# 第三周-第二节课 - -## 重新认识函数 - -- 内置函数 - - - 认识Python自带的, 可全局调用的函数, 避免我们命名冲突导致了函数性状发生改变 - - - 查看Python携带的内置函数 - - ``` - from pprint import pprint - # 格式化输出的库 - pprint(dir(__builtins__)) - ``` - - - 常见的内置函数 - - - `str` - - ``` - >>> str(1.0) - '1.0' - ``` - - - `int` - - ``` - >>> int(1.0) - 1 - >>> int("1.0") - Traceback (most recent call last): - File "", line 1, in - ValueError: invalid literal for int() with base 10: '1.0' - >>> int("1") - 1 - >>> - ``` - - - `float` - - ``` - >>> float("1.0") - 1.0 - >>> float(1) - 1.0 - >>> float('1') - 1.0 - ``` - - - `bytes` - - ``` - >>> bytes('a'.encode("utf-8")) - b'a' - ``` - - - `bool` - - ``` - >>> bool(0) - False - >>> bool(1) - True - >>> bool(2) - True - >>> bool('0') ***** - True - >>> bool(0.0) - False - ``` - - - `list` - - 只要是序列都可以转换成`list` - - ``` - >>> list("qwe") - ['q', 'w', 'e'] - ``` - - - `tuple` - - ``` - >>> tuple("qwe") - ('q', 'w', 'e') - >>> tuple([1,2]) - (1, 2) - ``` - - - `dict` - - ``` - >>> dict(a=1) - {'a': 1} - ``` - - - `set` - - ``` - >>> set([1,2,2]) - {1, 2} - >>> set("qweqweqwe") **** - {'q', 'w', 'e'} - ``` - - - `id` - - 查看当前对象的内存地址 - - ``` - >>> a = "1" - >>> id(a) - 26114944 - ``` - - - `dir` - - - 当前对象下的所有方法和属性 - - 在Python中一切皆为对象 - - ``` - dir(__builtins__) - ``` - - - `max` - - 返回一个序列中的最大值 - - ``` - >>> max([2, 4,67,1]) - 67 - ``` - - - `min` - - 返回一个序列中的最小值 - - ``` - >>> min([2, 4,67,1]) - 1 - ``` - - - `range` - - 返回一组数字区间的可迭代对象 - - ``` - >>> r = range(100) - >>> r - range(0, 100) - - >>> for i in range(10): - ... print(i) - ``` - -- 函数的形参和实参 - - - 形参 - - 形式参数, 简单地说就是还没接受到实际值的参数. 函数未调用时就是形参 - - ``` - def my_power(a, b): - return a ** b - ``` - - - 实参 - - 实际传入的参数, 函数调用时传入的值就叫实参 - - ``` - print(my_power(2, 3)) - ``` - -- 函数的返回值 - - - 返回值的类型 - - 任意类型, 包括函数本身 - - - 如何接受返回值 - - - 接收单个值 - - - 一个变量接受返回的多个值 - - 实际上返回的是个`tuple` - - ``` - >>> def foo(a, b): - ... return a*2, b*2 - ... - >>> result = foo(1, 2) - >>> result - (2, 4) - ``` - - - 多个变量按顺序接收 - - 实现原理是**元组解包**(unpack) - - ``` - >>> a,b = foo(1,2) - >>> a - 2 - >>> b - 4 - # 等同于 - >>> result = foo(1,2) - >>> a, b = result - ``` - - - 不定长变量接收 - - ``` - >>> result - (1, 2, 3, 4, 5, 6, 7) - >>> a, *b, c = result - >>> a - 1 - >>> c - 7 - >>> b - [2, 3, 4, 5, 6] - ``` - -## 匿名函数 - -顾名思义匿名函数就是没有名字的函数, 一般都是提供给高阶函数调用. - -- 通过`lambda`关键字来声明匿名函数 - - ``` - >>> lambda x: x **2 - # 返回的是一个匿名函数对象 - at 0x018BB660> - ``` - -- 函数体是纯表达式 - - - 不能有复杂的逻辑判断语句 - - - 唯一例外的例子: - - ``` - lambda x: 返回值 if 纯表达式 else 返回值 - - lambda x: True if x % 2==0 else False - ``` - - - - - 不能有循环语句 - - - 不能有异常捕获 - - - 不能有赋值语句 - - - 不能有`return` - - - 默认表达式运行的结果就是返回值 - - ``` - >>> lambda x: x **2 - 返回值就是 x**2 - ``` - -- 例子 - - ``` - l = [[1,2], [2,1], [6,4], [3,5]] - l.sort(key=lambda x: x[1]) - print(l) - ``` - -## 高阶函数 - -接受函数作为参数, 或者把函数作为结果返回 - -- map(映射) - - 对一个序列每个元素进行相同的操作, 这个过程就叫映射 - - ``` - >>> l = [1,2,3] - >>> m = map(lambda x: x**2, [1,2,3]) - - # 获得返回结果是一个map对象 - >>> m - - >>> l - [1, 2, 3] - - # map对象是一个可迭代对象, 需要驱动可迭代对象返回值, list就有这样的功能. 暂时不要太纠结 - >>> list(m) - [1, 4, 9] - >>> l - [1, 2, 3] - ``` - - - 等同于以下: - - ``` - def my_powser_2(a): - return a ** 2 - - # 匿名函数只是图方便, 所有的匿名都可以通过正常函数替换 - >>> m = map(my_powser_2, [1,2,3]) - >>> list(m) - [1, 4, 9] - ``` - - - 多用于和`math`库进行运算操作 - - ``` - >>> m = map(math.sqrt, [1, 4, 9, 16, 25]) - >>> list(m) - [1.0, 2.0, 3.0, 4.0, 5.0] - ``` - - - -- filter(过滤) - - ``` - filter(函数, 可迭代对象) - 函数中的表达式返回结果为False, 就会被过滤 - ``` - - ``` - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - # 过滤偶数 - >>> f = filter(lambda x: x%2, l) - >>> list(f) - [1, 3, 5, 7, 9] - - # 过滤奇数 - >>> f = filter(lambda x: False if x%2 == 1 else True, l) - >>> list(f) - [0, 2, 4, 6, 8] - ``` - -## 递归函数 - -在函数中调用自身的函数就叫递归函数 - -- 核心思想 - - **将大的任务拆分为子任务来解决复杂问题**, 只要大任务能拆分成子任务, 就可以使用递归 - - ``` - F(n) = F(F(n-1)) - ``` - -- 声明一个递归函数(阶乘) - - - **一定要有退出机制** - - ``` - F(n) = n * F(n-1) - - def fact(n): - if n == 1: - return 1 - return n * fact(n-1) - ``` - - - -## 课后作业 - -- 给定一个列表, 根据`grade`来排序 - - ``` - classes = [ - {"name": "n_1", "age": 24, "grade": "A"}, - {"name": "n_2", "age": 23, "grade": "B"}, - {"name": "n_3", "age": 28, "grade": "A"}, - {"name": "n_4", "age": 24, "grade": "A"}, - {"name": "n_5", "age": 25, "grade": "C"}, - {"name": "n_6", "age": 21, "grade": "D"}, - {"name": "n_7", "age": 27, "grade": "A"}, - ] - ``` - -- 通过`filter`语句来筛选出`Grade`为`A`的同学 - -- 通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda) - -- 使用递归函数重构斐波那契函数 - - ``` - f(n) = f(n-1) + f(n-2) - ``` - +-# 第三周-第二节课 + +## 重新认识函数 + +- 内置函数 + + - 认识Python自带的, 可全局调用的函数, 避免我们命名冲突导致了函数性状发生改变 + + - 查看Python携带的内置函数 + + ``` + from pprint import pprint + # 格式化输出的库 + pprint(dir(__builtins__)) + ``` + + - 常见的内置函数 + + - `str` + + ``` + >>> str(1.0) + '1.0' + ``` + + - `int` + + ``` + >>> int(1.0) + 1 + >>> int("1.0") + Traceback (most recent call last): + File "", line 1, in + ValueError: invalid literal for int() with base 10: '1.0' + >>> int("1") + 1 + >>> + ``` + + - `float` + + ``` + >>> float("1.0") + 1.0 + >>> float(1) + 1.0 + >>> float('1') + 1.0 + ``` + + - `bytes` + + ``` + >>> bytes('a'.encode("utf-8")) + b'a' + ``` + + - `bool` + + ``` + >>> bool(0) + False + >>> bool(1) + True + >>> bool(2) + True + >>> bool('0') ***** + True + >>> bool(0.0) + False + ``` + + - `list` + + 只要是序列都可以转换成`list` + + ``` + >>> list("qwe") + ['q', 'w', 'e'] + ``` + + - `tuple` + + ``` + >>> tuple("qwe") + ('q', 'w', 'e') + >>> tuple([1,2]) + (1, 2) + ``` + + - `dict` + + ``` + >>> dict(a=1) + {'a': 1} + ``` + + - `set` + + ``` + >>> set([1,2,2]) + {1, 2} + >>> set("qweqweqwe") **** + {'q', 'w', 'e'} + ``` + + - `id` + + 查看当前对象的内存地址 + + ``` + >>> a = "1" + >>> id(a) + 26114944 + ``` + + - `dir` + + - 当前对象下的所有方法和属性 + - 在Python中一切皆为对象 + + ``` + dir(__builtins__) + ``` + + - `max` + + 返回一个序列中的最大值 + + ``` + >>> max([2, 4,67,1]) + 67 + ``` + + - `min` + + 返回一个序列中的最小值 + + ``` + >>> min([2, 4,67,1]) + 1 + ``` + + - `range` + + 返回一组数字区间的可迭代对象 + + ``` + >>> r = range(100) + >>> r + range(0, 100) + + >>> for i in range(10): + ... print(i) + ``` + +- 函数的形参和实参 + + - 形参 + + 形式参数, 简单地说就是还没接受到实际值的参数. 函数未调用时就是形参 + + ``` + def my_power(a, b): + return a ** b + ``` + + - 实参 + + 实际传入的参数, 函数调用时传入的值就叫实参 + + ``` + print(my_power(2, 3)) + ``` + +- 函数的返回值 + + - 返回值的类型 + + 任意类型, 包括函数本身 + + - 如何接受返回值 + + - 接收单个值 + + - 一个变量接受返回的多个值 + + 实际上返回的是个`tuple` + + ``` + >>> def foo(a, b): + ... return a*2, b*2 + ... + >>> result = foo(1, 2) + >>> result + (2, 4) + ``` + + - 多个变量按顺序接收 + + 实现原理是**元组解包**(unpack) + + ``` + >>> a,b = foo(1,2) + >>> a + 2 + >>> b + 4 + # 等同于 + >>> result = foo(1,2) + >>> a, b = result + ``` + + - 不定长变量接收 + + ``` + >>> result + (1, 2, 3, 4, 5, 6, 7) + >>> a, *b, c = result + >>> a + 1 + >>> c + 7 + >>> b + [2, 3, 4, 5, 6] + ``` + +## 匿名函数 + +顾名思义匿名函数就是没有名字的函数, 一般都是提供给高阶函数调用. + +- 通过`lambda`关键字来声明匿名函数 + + ``` + >>> lambda x: x **2 + # 返回的是一个匿名函数对象 + at 0x018BB660> + ``` + +- 函数体是纯表达式 + + - 不能有复杂的逻辑判断语句 + + - 唯一例外的例子: + + ``` + lambda x: 返回值 if 纯表达式 else 返回值 + + lambda x: True if x % 2==0 else False + ``` + + + + - 不能有循环语句 + + - 不能有异常捕获 + + - 不能有赋值语句 + + - 不能有`return` + + - 默认表达式运行的结果就是返回值 + + ``` + >>> lambda x: x **2 + 返回值就是 x**2 + ``` + +- 例子 + + ``` + l = [[1,2], [2,1], [6,4], [3,5]] + l.sort(key=lambda x: x[1]) + print(l) + ``` + +## 高阶函数 + +接受函数作为参数, 或者把函数作为结果返回 + +- map(映射) + + 对一个序列每个元素进行相同的操作, 这个过程就叫映射 + + ``` + >>> l = [1,2,3] + >>> m = map(lambda x: x**2, [1,2,3]) + + # 获得返回结果是一个map对象 + >>> m + + >>> l + [1, 2, 3] + + # map对象是一个可迭代对象, 需要驱动可迭代对象返回值, list就有这样的功能. 暂时不要太纠结 + >>> list(m) + [1, 4, 9] + >>> l + [1, 2, 3] + ``` + + - 等同于以下: + + ``` + def my_powser_2(a): + return a ** 2 + + # 匿名函数只是图方便, 所有的匿名都可以通过正常函数替换 + >>> m = map(my_powser_2, [1,2,3]) + >>> list(m) + [1, 4, 9] + ``` + + - 多用于和`math`库进行运算操作 + + ``` + >>> m = map(math.sqrt, [1, 4, 9, 16, 25]) + >>> list(m) + [1.0, 2.0, 3.0, 4.0, 5.0] + ``` + + + +- filter(过滤) + + ``` + filter(函数, 可迭代对象) + 函数中的表达式返回结果为False, 就会被过滤 + ``` + + ``` + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + # 过滤偶数 + >>> f = filter(lambda x: x%2, l) + >>> list(f) + [1, 3, 5, 7, 9] + + # 过滤奇数 + >>> f = filter(lambda x: False if x%2 == 1 else True, l) + >>> list(f) + [0, 2, 4, 6, 8] + ``` + +## 递归函数 + +在函数中调用自身的函数就叫递归函数 + +- 核心思想 + + **将大的任务拆分为子任务来解决复杂问题**, 只要大任务能拆分成子任务, 就可以使用递归 + + ``` + F(n) = F(F(n-1)) + ``` + +- 声明一个递归函数(阶乘) + + - **一定要有退出机制** + + ``` + F(n) = n * F(n-1) + + def fact(n): + if n == 1: + return 1 + return n * fact(n-1) + ``` + + + +## 课后作业 + +- 给定一个列表, 根据`grade`来排序 + + ``` + classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, + ] + ``` + +- 通过`filter`语句来筛选出`Grade`为`A`的同学 + +- 通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda) + +- 使用递归函数重构斐波那契函数 + + ``` + f(n) = f(n-1) + f(n-2) + ``` + \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index e8a698b5e3f57b5f8045495bc2481b19660488fd..d16f3897b57427bc919d5148791c54fa3935f774 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,169 +1,169 @@ -# 第九周-第一节课 - -## 一个请求的组成 - -``` -def request_jd(keyword): - url = "https://search.jd.com/Search" - params = { - "keyword": keyword - } - headers = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, params=params, headers=headers) - response.text 获取str类型的响应内容 - response.content 获取bytes类型的响应内容 - response.json() 获取json格式数据 -``` - -- 请求行(request line) - - - URL - - 请求方法(method) - -- 请求头(headers) - - - user-agent - - 用来指示当前请求时从哪个终端发起的 - - - cookie - - 用来指示当前的用户信息和行为信息 - -- 请求体(body) - - - `params`(严格来说不算是请求体) - - 实际请求的时候会变成URL的一部分, 所以说post请求也可以用`params` - - - urlencode和urldecode - - 请求头中指定的编码格式只对请求体是有效的, 不对params有效. 所以urlencode来保证URL不会发生编码问题. - - ``` - from urllib.parse import quote, unquote - - print(quote("鼠标")) - print(unquote("%E9%BC%A0%E6%A0%87")) - ``` - - - `data` - - 携带额外的请求信息. - -## 静态页面和动态页面 - -- 静态页面 - - 纯粹的HTML文件, 简单地说当前的页面文件就存储在服务端, 我们请求的静态页面实际上就是请求对方服务器中的文件. 通过返回不同的HTML文件来完成不同请求的显示效果. - - - 动态页面和静态页面的区分绝不是指页面上的动画效果 - - > 最常见的就是各大企业网站 - -- 动态页面 - - 动态页面是指除了HTML以外, 通过`ajax`在不直接刷新页面的前提下, 完成了和服务端的数据交互. 并通过`javascript`回调函数完成对页面内容的修改, `ajax`和服务端交互的数据格式通常为`json` - - > 浏览商品 - > - > 视频网站的瀑布流 - - - `Ajax` - - > asynchronous JavaScript-XML 异步javascript和xml的缩写 - - 在不直接刷新页面的前提下, 完成了和服务端的数据交互. 并通过`javascript`回调函数完成对页面内容的修改, `ajax`和服务端交互的数据格式通常为`json`. - - - `json` - - js对象标记法, 用来表示对象关系 - - > js中的对象: {a: 1, b: null} - - - json的作用 - - 是一种跨平台跨语言的传输对象格式, 可以保留一些基础的数据类型信息. - - > 原来json只是作为前端和服务端传输数据的格式规范, 但是现在几乎所有热门语言都内置了json, 所以可以称之为跨语言的传输格式 - - ``` - import json - - test_dict = { - "a": 1, - "b": ["1", 2, None], - "c": {"d": 1} - } - - # json格式数据其实是个字符串 - # 将python字典转变为json数据格式 - json_data = json.dumps(test_dict) - print(type(json_data), json_data) - - # 将json数据格式转变为字典 - print(json.loads(json_data)) - ``` - -## HTML, CSS和JS - -> html和js决定了显示的内容, css决定了怎么显示. - -- HTML(HyperTextMarkup Language 超文本标记语言) - - - HTML的作用 - - 定义网页的内容的含义和结构. - - - tag(标签) - - `<标签名>` - - - `` - - 表示当前是一个HTML文档对象 - - - `` - - 提供一些基础信息 - - ``` - # 通过meta标签来表示当前页面的编码格式 - - ``` - - - `` - - 纯内容 - - - element(元素) - - `<标签名> xxxxxxxxxx` - -- CSS(Cascading Style Sheets 层叠样式表) - - 能对网页中的元素位置的排版进行像素级别的控制. 页面的渲染主要就是通过`css`来完成的. - -- JavaScript - - 通过``包裹, 主要完成数据的交互和对DOM树(HTML是一个结构化的数据文件, DOM就是将结构化的数据转变成对象)的修改. - -## 浏览器渲染的过程 - -- 接收到HTML文件后开始构建DOM(Doucment Object Model)树. -- CSS来计算DOM树各个节点的坐标, 大小等CSS属性, 开始布局. -- 开始加载媒体资源和页面渲染. - -## 课后作业 - -- 完成京东搜索页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) - - ``` - f = open("search_keyword.html", "w", encoding="utf-8") - ``` - -- 完成京东详情页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) - +# 第九周-第一节课 + +## 一个请求的组成 + +``` +def request_jd(keyword): + url = "https://search.jd.com/Search" + params = { + "keyword": keyword + } + headers = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, params=params, headers=headers) + response.text 获取str类型的响应内容 + response.content 获取bytes类型的响应内容 + response.json() 获取json格式数据 +``` + +- 请求行(request line) + + - URL + - 请求方法(method) + +- 请求头(headers) + + - user-agent + + 用来指示当前请求时从哪个终端发起的 + + - cookie + + 用来指示当前的用户信息和行为信息 + +- 请求体(body) + + - `params`(严格来说不算是请求体) + + 实际请求的时候会变成URL的一部分, 所以说post请求也可以用`params` + + - urlencode和urldecode + + 请求头中指定的编码格式只对请求体是有效的, 不对params有效. 所以urlencode来保证URL不会发生编码问题. + + ``` + from urllib.parse import quote, unquote + + print(quote("鼠标")) + print(unquote("%E9%BC%A0%E6%A0%87")) + ``` + + - `data` + + 携带额外的请求信息. + +## 静态页面和动态页面 + +- 静态页面 + + 纯粹的HTML文件, 简单地说当前的页面文件就存储在服务端, 我们请求的静态页面实际上就是请求对方服务器中的文件. 通过返回不同的HTML文件来完成不同请求的显示效果. + + - 动态页面和静态页面的区分绝不是指页面上的动画效果 + + > 最常见的就是各大企业网站 + +- 动态页面 + + 动态页面是指除了HTML以外, 通过`ajax`在不直接刷新页面的前提下, 完成了和服务端的数据交互. 并通过`javascript`回调函数完成对页面内容的修改, `ajax`和服务端交互的数据格式通常为`json` + + > 浏览商品 + > + > 视频网站的瀑布流 + + - `Ajax` + + > asynchronous JavaScript-XML 异步javascript和xml的缩写 + + 在不直接刷新页面的前提下, 完成了和服务端的数据交互. 并通过`javascript`回调函数完成对页面内容的修改, `ajax`和服务端交互的数据格式通常为`json`. + + - `json` + + js对象标记法, 用来表示对象关系 + + > js中的对象: {a: 1, b: null} + + - json的作用 + + 是一种跨平台跨语言的传输对象格式, 可以保留一些基础的数据类型信息. + + > 原来json只是作为前端和服务端传输数据的格式规范, 但是现在几乎所有热门语言都内置了json, 所以可以称之为跨语言的传输格式 + + ``` + import json + + test_dict = { + "a": 1, + "b": ["1", 2, None], + "c": {"d": 1} + } + + # json格式数据其实是个字符串 + # 将python字典转变为json数据格式 + json_data = json.dumps(test_dict) + print(type(json_data), json_data) + + # 将json数据格式转变为字典 + print(json.loads(json_data)) + ``` + +## HTML, CSS和JS + +> html和js决定了显示的内容, css决定了怎么显示. + +- HTML(HyperTextMarkup Language 超文本标记语言) + + - HTML的作用 + + 定义网页的内容的含义和结构. + + - tag(标签) + + `<标签名>` + + - `` + + 表示当前是一个HTML文档对象 + + - `` + + 提供一些基础信息 + + ``` + # 通过meta标签来表示当前页面的编码格式 + + ``` + + - `` + + 纯内容 + + - element(元素) + + `<标签名> xxxxxxxxxx` + +- CSS(Cascading Style Sheets 层叠样式表) + + 能对网页中的元素位置的排版进行像素级别的控制. 页面的渲染主要就是通过`css`来完成的. + +- JavaScript + + 通过``包裹, 主要完成数据的交互和对DOM树(HTML是一个结构化的数据文件, DOM就是将结构化的数据转变成对象)的修改. + +## 浏览器渲染的过程 + +- 接收到HTML文件后开始构建DOM(Doucment Object Model)树. +- CSS来计算DOM树各个节点的坐标, 大小等CSS属性, 开始布局. +- 开始加载媒体资源和页面渲染. + +## 课后作业 + +- 完成京东搜索页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) + + ``` + f = open("search_keyword.html", "w", encoding="utf-8") + ``` + +- 完成京东详情页面的请求并保存为HTML格式文件(10个即可, 请求频繁容易被封) + - 练习python中json库的使用 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 60f6e9fc947d2b9c0b134af3608f1696f0c8f9d9..06689257b09280736d897400814c4f13e1ac6ee3 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,39 +1,39 @@ -# 第九周-第三节课 - -## 一个小又全的爬虫项目 - -- 任务生成者 - - 生成爬虫任务的组件, 最大的作用就是建立生产消费者模型, 将生产者和消费者剥离, 可以达到程序暂停重启的功能. - -- 配置文件 - - 当前爬虫项目的基础配置信息, 目的就是统一化配置, 避免重复修改. - -- 主函数/调度器 - - 以逻辑控制流协同各个组件, 完成爬取工作, 具有一定的调度功能 - -- 下载器 - - 用来和目标服务器进行交互, 获取数据的组件 - -- 解析器 - - 用来解析非结构化的页面内容, 获取想要的数据. - -- 存储器 - - 用来持久化解析后的数据 - - - 数据库 - - 存为本地文件, 比较推荐的格式为json, 结构严谨的可以保存为csv - -## 课后作业 - -- 搭建第一个爬虫项目 -- 为当前爬虫项目添加代理 -- 扩展: 将当前项目改造成多线程 -- 扩展2: 将当前项目改造成多进程 -- 扩展3: 通过aiohttp, aiomysql将项目改造成协程. - +# 第九周-第三节课 + +## 一个小又全的爬虫项目 + +- 任务生成者 + + 生成爬虫任务的组件, 最大的作用就是建立生产消费者模型, 将生产者和消费者剥离, 可以达到程序暂停重启的功能. + +- 配置文件 + + 当前爬虫项目的基础配置信息, 目的就是统一化配置, 避免重复修改. + +- 主函数/调度器 + + 以逻辑控制流协同各个组件, 完成爬取工作, 具有一定的调度功能 + +- 下载器 + + 用来和目标服务器进行交互, 获取数据的组件 + +- 解析器 + + 用来解析非结构化的页面内容, 获取想要的数据. + +- 存储器 + + 用来持久化解析后的数据 + + - 数据库 + - 存为本地文件, 比较推荐的格式为json, 结构严谨的可以保存为csv + +## 课后作业 + +- 搭建第一个爬虫项目 +- 为当前爬虫项目添加代理 +- 扩展: 将当前项目改造成多线程 +- 扩展2: 将当前项目改造成多进程 +- 扩展3: 通过aiohttp, aiomysql将项目改造成协程. + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 3af8e2a50c0334702842130beeeb709991186648..7cbbc35f268b9c150d1fe77001053ec297dc0705 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\271\235\345\221\250-\351\241\265\351\235\242\350\247\243\346\236\220\345\222\214\347\210\254\350\231\253\351\241\271\347\233\256\345\210\235\346\216\242/\347\254\254\344\271\235\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,220 +1,220 @@ -# 第九周-第二节课 - -## css-selector - -> 尽量避免解析路径中包含位置信息 - -> chrome页面中内置了Jquery环境, 用$符号来表示 - -- 直接定位元素 - - - 通过id进行定位 - - ``` - $("#id值") - ``` - - - 通过class进行定位 - - ``` - $(".class值") - ``` - - - **通过属性名进行定位** - - ``` - $("标签名[属性名='属性值']") - - $("ul[class='gl-warp clearfix']") - ``` - -- 获取兄弟节点 - - - 获取当前节点的下一个节点 - - - dom提供的接口, 不属于css-selector语法 - - ``` - tmp = $("li[data-sku='6039832']")[0] - tmp.nextElementSibling - ``` - - - 通过css-selector(不建议) - - ``` - $("ul[class='gl-warp clearfix'] li:first-child + li") - ``` - - - 获取当前节点的上一个节点 - - - dom提供的接口, 不属于css-selector语法 - - ``` - tmp = $("li[data-sku='2136538']")[0] - tmp.previousElementSibling - ``` - -- 获取父子节点 - - - 获取父节点 - - - dom提供的接口, 不属于css-selector语法 - - ``` - tmp.parentElement - ``` - - - 获取子节点 - - - 获取所有子节点 - - - **遍历**所有符合条件的元素 - - ``` - $("ul[class='gl-warp clearfix'] div[class='gl-i-wrap']") - ``` - - - dom提供的接口, 不属于css-selector语法 - - ``` - $("ul[class='gl-warp clearfix']")[0].children - ``` - - - 获取第一个子节点 - - ``` - :fist-child - $("ul[class='gl-warp clearfix'] li:first-child")[0] - ``` - - - 获取最后一个子节点 - - ``` - :last-child - $("ul[class='gl-warp clearfix'] li:last-child")[0] - ``` - - - 获取第N个子节点 - - ``` - :nth-child(索引) - $("ul[class='gl-warp clearfix'] li:nth-child(5)")[0] - ``` - -- 模糊匹配 - - - 匹配开头 - - `^` - - ``` - # 匹配data-sku属性值为2开头的元素 - $("li[data-sku^='2']") - ``` - - - 匹配结尾 - - `$` - - ``` - $("li[data-sku$='2']") - ``` - - - 匹配子集 - - `*` - - ``` - $("li[data-sku*='2']") - ``` - -- 获取文本值 - - ``` - $("li[data-sku='6039832'] div[class='p-name p-name-type-2'] em")[0].innerText - ``` - -- 获取属性值 - - ``` - $("ul[class='gl-warp clearfix'] li")[0].getAttribute("data-sku") - ``` - -## BeautifulSoup - -- 安装 - - ``` - pip install bs4 - pip install lxml - ``` - -- 使用BeautifulSoup - - ``` - from bs4 import BeautifulSoup - - - def jd_search_parse(html): - soup = BeautifulSoup(html, "lxml") - item = soup.select("li[data-sku='6039832']")[0] - ``` - -- 直接定位元素 - - 略 - -- 去除空白字符 - - ``` - html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") - ``` - -- 获取兄弟节点 - - - 获取上一个节点 - - ``` - tmp_ele.previous_sibling - ``` - - - 获取下一个节点 - - ``` - tmp_ele.next_sibling - ``` - -- 获取父子节点 - - - 获取父节点 - - ``` - tmp_ele.parent - ``` - - - 获取子节点 - - ``` - tmp_ele.children - ``` - -- 模糊匹配 - - 略 - -- 获取文本值 - - ``` - content = tmp_ele.text.strip() - ``` - -- 获取属性值 - - ``` - value = tmp_ele.attrs["data-sku"] - ``` - -## 课后作业 - -- 练习css-selector +# 第九周-第二节课 + +## css-selector + +> 尽量避免解析路径中包含位置信息 + +> chrome页面中内置了Jquery环境, 用$符号来表示 + +- 直接定位元素 + + - 通过id进行定位 + + ``` + $("#id值") + ``` + + - 通过class进行定位 + + ``` + $(".class值") + ``` + + - **通过属性名进行定位** + + ``` + $("标签名[属性名='属性值']") + + $("ul[class='gl-warp clearfix']") + ``` + +- 获取兄弟节点 + + - 获取当前节点的下一个节点 + + - dom提供的接口, 不属于css-selector语法 + + ``` + tmp = $("li[data-sku='6039832']")[0] + tmp.nextElementSibling + ``` + + - 通过css-selector(不建议) + + ``` + $("ul[class='gl-warp clearfix'] li:first-child + li") + ``` + + - 获取当前节点的上一个节点 + + - dom提供的接口, 不属于css-selector语法 + + ``` + tmp = $("li[data-sku='2136538']")[0] + tmp.previousElementSibling + ``` + +- 获取父子节点 + + - 获取父节点 + + - dom提供的接口, 不属于css-selector语法 + + ``` + tmp.parentElement + ``` + + - 获取子节点 + + - 获取所有子节点 + + - **遍历**所有符合条件的元素 + + ``` + $("ul[class='gl-warp clearfix'] div[class='gl-i-wrap']") + ``` + + - dom提供的接口, 不属于css-selector语法 + + ``` + $("ul[class='gl-warp clearfix']")[0].children + ``` + + - 获取第一个子节点 + + ``` + :fist-child + $("ul[class='gl-warp clearfix'] li:first-child")[0] + ``` + + - 获取最后一个子节点 + + ``` + :last-child + $("ul[class='gl-warp clearfix'] li:last-child")[0] + ``` + + - 获取第N个子节点 + + ``` + :nth-child(索引) + $("ul[class='gl-warp clearfix'] li:nth-child(5)")[0] + ``` + +- 模糊匹配 + + - 匹配开头 + + `^` + + ``` + # 匹配data-sku属性值为2开头的元素 + $("li[data-sku^='2']") + ``` + + - 匹配结尾 + + `$` + + ``` + $("li[data-sku$='2']") + ``` + + - 匹配子集 + + `*` + + ``` + $("li[data-sku*='2']") + ``` + +- 获取文本值 + + ``` + $("li[data-sku='6039832'] div[class='p-name p-name-type-2'] em")[0].innerText + ``` + +- 获取属性值 + + ``` + $("ul[class='gl-warp clearfix'] li")[0].getAttribute("data-sku") + ``` + +## BeautifulSoup + +- 安装 + + ``` + pip install bs4 + pip install lxml + ``` + +- 使用BeautifulSoup + + ``` + from bs4 import BeautifulSoup + + + def jd_search_parse(html): + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='6039832']")[0] + ``` + +- 直接定位元素 + + 略 + +- 去除空白字符 + + ``` + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") + ``` + +- 获取兄弟节点 + + - 获取上一个节点 + + ``` + tmp_ele.previous_sibling + ``` + + - 获取下一个节点 + + ``` + tmp_ele.next_sibling + ``` + +- 获取父子节点 + + - 获取父节点 + + ``` + tmp_ele.parent + ``` + + - 获取子节点 + + ``` + tmp_ele.children + ``` + +- 模糊匹配 + + 略 + +- 获取文本值 + + ``` + content = tmp_ele.text.strip() + ``` + +- 获取属性值 + + ``` + value = tmp_ele.attrs["data-sku"] + ``` + +## 课后作业 + +- 练习css-selector - 练习用beautifulsoup进行页面解析 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 2e86a64a46465cd5601d34d39d1bf6795f79c59b..8d4c688f599f32965da104bdc4d5043955268278 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,257 +1,257 @@ -# 第二周-第一节课 - -## Python函数的基本介绍 - -- 什么是函数? - - 函数是一段可以直接被另外一段程序或代码引用的程序或代码, 也叫做子程序, 方法. - - - 可重复使用 - - 可互相调用 - -- 函数的目的 - - - 为了代码段的复用 - -- 在`Python`中如何定义一个函数? - - ``` - def foo(arg): - return "Hello " + str(arg) - ``` - -- 函数的组成 - - - 参数列表 - - - 必须参数 - - 当前参数必须**按顺序**传入 - - - 关键字参数 - - 根据关键字参数传参可以无视顺序 - - ``` - def foo(arg=None, arg_2=None) - ``` - - - 默认参数 - - ``` - def foo(arg='tunan', arg_2=None) - ``` - - - 不定长参数 - - ``` - 在装饰器中会大量应用 - ``` - - 可以接受任意长度的参数. - - - `*` - - 代表了省略, 省略了参数`tuple`(元组) - - - `**` - - 省略了关键字参数`dict`(字典) - - - 函数体 - - - 返回值 - - 默认返回`None` - - ``` - return None - ``` - -## Python的运算符 - -- 算术运算 - - - `+` - - - `-` - - - `*` - - 乘法 - - - `/` - - 除法 - - - `//` - - 整除 - - - `%` - - 取余数 - - - `**` - - x的y次幂 - - - 开方(没有提供直接的运算符) - - ``` - x ** (1/2) - ``` - - - abs() - - 取绝对值 - -- 赋值运算 - - 通过`=`赋值 - - ``` - a = 1 - ``` - -- 比较运算 - - 比较的是两个对象的字面值, 字面值暂时可以简单地理解为输出值 - - - `<` - - - `>` - - - `<=` - - - `>=` - - - `==` - - 等于 - - - `!=` - - 不等于 - -- 标识号比较运算 - - **比较的是两个变量的内存地址** - - - `is` - - `is not` - - - 赋值类型为`str`, `int`的时候要考虑`Python`常量池 - - ``` - a = "test_1" - b = "test_1" - - a is b - >>> True - - a = '你好' - b = '你好' - a is b - >>> False - ``` - -- 成员检测运算 - - 判断元素是否在当前序列当中 - - - `in` - - ``` - a = [1,2,3] - 1 in a - >>> True - - b = [1, 2] - b in a - >>> False - ``` - - - `not in` - - - -- 布尔运算 - - 判断当前语句的结果是`True`还是`False` - - - `and` - - 只有两边都是`True`才返回`True` - - - `or` - - 两边表达式有一个`True`返回的结果为`True` - - - 短路 - - ``` - 表达式A or 表达式B - 当表达式A为True时, 表达式B就不会运行 - ``` - - - 逻辑取反 - - `not` - -- 位运算 - - ``` - 二进制运算, 未来刷题的时候再说, 有兴趣的同学可以了解一下 - ``` - - - `~` - - `^` - - `>>` - - `<<` - - `&` - - `|` - - - -## Python运算符优先级 - -| 运算符 | 描述 | -| ---------------------------------- | ---------------------------------- | -| or | 布尔运算或 | -| and | 布尔运算与 | -| not | 布尔运算逻辑取反 | -| in, not in, is, is not, <, !=, ... | 比较运算, 成员检测运算, 标识号检测 | -| +, - | 加法和减法 | -| *, /, //, % | 乘法, 除法, 整除, 取余 | -| +x, -x | 正负数 | -| ** | 幂 | - -- 自定义优先级 - - ``` - 如果不确定优先级, 出于可读性和避免未知的BUG, 我们都应该用()来自定义优先级 - ``` - - - 通过`()` - - ``` - (not b and c) or (d and e) - ``` - - - -## 课后作业 - -- 用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 - - ``` - my_calculator.py - - def add(a, b): - ... - def sqrt(a, b): - ... - ``` - +# 第二周-第一节课 + +## Python函数的基本介绍 + +- 什么是函数? + + 函数是一段可以直接被另外一段程序或代码引用的程序或代码, 也叫做子程序, 方法. + + - 可重复使用 + - 可互相调用 + +- 函数的目的 + + - 为了代码段的复用 + +- 在`Python`中如何定义一个函数? + + ``` + def foo(arg): + return "Hello " + str(arg) + ``` + +- 函数的组成 + + - 参数列表 + + - 必须参数 + + 当前参数必须**按顺序**传入 + + - 关键字参数 + + 根据关键字参数传参可以无视顺序 + + ``` + def foo(arg=None, arg_2=None) + ``` + + - 默认参数 + + ``` + def foo(arg='tunan', arg_2=None) + ``` + + - 不定长参数 + + ``` + 在装饰器中会大量应用 + ``` + + 可以接受任意长度的参数. + + - `*` + + 代表了省略, 省略了参数`tuple`(元组) + + - `**` + + 省略了关键字参数`dict`(字典) + + - 函数体 + + - 返回值 + + 默认返回`None` + + ``` + return None + ``` + +## Python的运算符 + +- 算术运算 + + - `+` + + - `-` + + - `*` + + 乘法 + + - `/` + + 除法 + + - `//` + + 整除 + + - `%` + + 取余数 + + - `**` + + x的y次幂 + + - 开方(没有提供直接的运算符) + + ``` + x ** (1/2) + ``` + + - abs() + + 取绝对值 + +- 赋值运算 + + 通过`=`赋值 + + ``` + a = 1 + ``` + +- 比较运算 + + 比较的是两个对象的字面值, 字面值暂时可以简单地理解为输出值 + + - `<` + + - `>` + + - `<=` + + - `>=` + + - `==` + + 等于 + + - `!=` + + 不等于 + +- 标识号比较运算 + + **比较的是两个变量的内存地址** + + - `is` + - `is not` + + - 赋值类型为`str`, `int`的时候要考虑`Python`常量池 + + ``` + a = "test_1" + b = "test_1" + + a is b + >>> True + + a = '你好' + b = '你好' + a is b + >>> False + ``` + +- 成员检测运算 + + 判断元素是否在当前序列当中 + + - `in` + + ``` + a = [1,2,3] + 1 in a + >>> True + + b = [1, 2] + b in a + >>> False + ``` + + - `not in` + + + +- 布尔运算 + + 判断当前语句的结果是`True`还是`False` + + - `and` + + 只有两边都是`True`才返回`True` + + - `or` + + 两边表达式有一个`True`返回的结果为`True` + + - 短路 + + ``` + 表达式A or 表达式B + 当表达式A为True时, 表达式B就不会运行 + ``` + + - 逻辑取反 + + `not` + +- 位运算 + + ``` + 二进制运算, 未来刷题的时候再说, 有兴趣的同学可以了解一下 + ``` + + - `~` + - `^` + - `>>` + - `<<` + - `&` + - `|` + + + +## Python运算符优先级 + +| 运算符 | 描述 | +| ---------------------------------- | ---------------------------------- | +| or | 布尔运算或 | +| and | 布尔运算与 | +| not | 布尔运算逻辑取反 | +| in, not in, is, is not, <, !=, ... | 比较运算, 成员检测运算, 标识号检测 | +| +, - | 加法和减法 | +| *, /, //, % | 乘法, 除法, 整除, 取余 | +| +x, -x | 正负数 | +| ** | 幂 | + +- 自定义优先级 + + ``` + 如果不确定优先级, 出于可读性和避免未知的BUG, 我们都应该用()来自定义优先级 + ``` + + - 通过`()` + + ``` + (not b and c) or (d and e) + ``` + + + +## 课后作业 + +- 用函数实现一个具有加, 减, 乘, 除, 整除, 取余, 开方的计算器 + + ``` + my_calculator.py + + def add(a, b): + ... + def sqrt(a, b): + ... + ``` + - 在交互模式中练习`Python`运算符(不用提交) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index babb611237d7b002fa387ea1e6cce46e0e9c39fb..8360421a29ea1e7c3431913148c899efbe6427c1 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,386 +1,386 @@ -# 第二周-第三节课 - -## 了解变量和引用 - -- 变量简单地说就是指向了一个实体 - -- 引用简单地说就是指向变量的变量 - - ``` - >>> a = 1 - >>> b = a - >>> id(a) - 1778508560 - >>> id(b) - 1778508560 - ``` - -## 基础数据结构的CRUD操作 - -- List(列表) - - **list中存的元素是引用** - - - create(增加) - - - append - - 末尾添加元素 - - ``` - >>> l = [] - >>> id(l) - 55200584 - >>> l.append("a") - >>> l - ['a'] - >>> id(l) - 55200584 - ``` - - - `+` 和`+=` - - - `+` - - 拼接两个列表, 然后返回一个新列表 - - - `+=` - - ``` - >>> l = ['a'] - >>> id(l) - 55200664 - >>> l += ['b'] - >>> id(l) - 55200664 - >>> l - ['a', 'b'] - ``` - - - `*`和`*=` - - ``` - >>> a = 'a' - >>> id(a) - 53622432 - >>> l = [a] * 10 - >>> l - ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - >>> id(l[0]) - 53622432 - >>> id(l[1]) - 53622432 - >>> id(l[9]) - 53622432 - - # 赋值语句之后, a已经是一个新的对象了 - >>> a = 'b' - >>> l - ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] - >>> id(a) - 53647264 - ``` - - - insert - - 指定位置添加元素 - - ``` - l.insert(0, 'b') - ``` - - - Retrieve(检索) - - - 索引取值 - - 所有序列都支持索引取值 - - - 切片 - - ``` - your_list[start:end:step] - # 取一段区间 - your_list[start:end] - - # 取最后一个值 - your_list[-1] - - # 间隔问题 - your_list[1:20:2] - ``` - - - index - - ``` - >>> l - ['a', 'b', 'c'] - >>> l.index('a') - 0 - ``` - - - Update(更新) - - - 索引赋值 - - ``` - l[0] = 'a_1' - ``` - - - 切片赋值 - - ``` - >>> l - ['a_1', 'a_2', 'b', 'c'] - >>> l[0:2] = "a" - >>> l - ['a', 'b', 'c'] - >>> l[0:2] = 1 - ``` - - - DELETE(删除) - - - pop() - - 从末尾删除元素并返回 - - ``` - >>> l - ['a', 'b', 'c'] - >>> x = l.pop() - >>> l - ['a', 'b'] - >>> x - 'c' - ``` - - - clear() - - 清楚当前列表的元素, 不会改变列表的内存地址. - - - ★SORT(排序) - - - sort() - - ``` - >>> l - [1, 3, 2, 6, 4] - >>> l.sort() - >>> l - [1, 2, 3, 4, 6] - - ``` - - - sorted - - 排序后返回新列表 - - ``` - >>> l2 = sorted(l) - >>> l - [1, 3, 2, 6, 4] - >>> l2 - [1, 2, 3, 4, 6] - >>> id(l) - 55201384 - >>> id(l2) - 55200984 - ``` - - - reverse - - ``` - >>> l2 - [1, 2, 3, 4, 6] - >>> l2.reverse() - >>> l2 - [6, 4, 3, 2, 1] - ``` - - - reversed - - 倒序之后返回新列表 - - ``` - >>> l - [1, 3, 2, 6, 4] - >>> list(reversed(l)) - [4, 6, 2, 3, 1] - ``` - -- tuple - - - Create - - 无 - - - Retrieve - - - 索引取值 - - index - - 切片 - - - Update - - 无 - - - Delete - - 无 - -- dict - - - Create - - - 键对值赋值 - - - update - - 提供合并字典的功能 - - ``` - >>> d - {'a': 1} - >>> d2 = {"b":2, "c": 3} - >>> d.update(d2) - >>> d - {'a': 1, 'b': 2, 'c': 3} - ``` - - - setdefault - - 如果字典中没有当前key, 那么就设置默认值 - - ``` - >>> d - {'a': 1, 'b': 2, 'c': 3} - >>> d.setdefault('b', 0) - 2 - >>> d.setdefault('d', 0) - 0 - >>> d - {'a': 1, 'b': 2, 'c': 3, 'd': 0} - - ``` - - - Retrieve - - - 键对值访问 - - - get - - 键对值访问缺失key会报错, 而get可以指定默认值 - - ``` - >>> d['e'] - Traceback (most recent call last): - File "", line 1, in - KeyError: 'e' - >>> d.get('f') - >>> d.get('f', 0) - 0 - ``` - - - keys() - - 返回所有key - - ``` - d.keys() - ``` - - - values() - - 返回所有value - - ``` - d.values() - ``` - - - items() - - 返回所有键对值 - - ``` - d.items() - ``` - - - Update - - - 键对值赋值 - - ``` - d['a'] = 100 - ``` - - - update - - ``` - >>> d.update({"b": 200, "c": 300}) - >>> d - {'a': 100, 'b': 200, 'c': 300, 'd': 0} - ``` - - - Delete - - - pop(key) - - 删除当前元素并返回value - - - popitem() - - 对于人来说, 相当于随机返回一个item - - - clear() - -- set - - - Create - - - add - - update - - - Retrieve - - - 运算符`in` - - ``` - >>> s - {'a'} - >>> "a" in s - True - - ``` - - - update - - - union - - 合并两个set, 并返回一个新的set - - - delete - - - remove 和discard - - discard缺失元素时不会报错, 而remove会报错 - - ``` - >>> s - {'b', 'c', 'a'} - >>> s.remove("a") - >>> s - {'b', 'c'} - >>> s.discard("e") - >>> s.remove("a") - Traceback (most recent call last): - File "", line 1, in - KeyError: 'a' - >>> - ``` - - - pop() - - 当成无序删除并返回元素 - -## 课后作业 - +# 第二周-第三节课 + +## 了解变量和引用 + +- 变量简单地说就是指向了一个实体 + +- 引用简单地说就是指向变量的变量 + + ``` + >>> a = 1 + >>> b = a + >>> id(a) + 1778508560 + >>> id(b) + 1778508560 + ``` + +## 基础数据结构的CRUD操作 + +- List(列表) + + **list中存的元素是引用** + + - create(增加) + + - append + + 末尾添加元素 + + ``` + >>> l = [] + >>> id(l) + 55200584 + >>> l.append("a") + >>> l + ['a'] + >>> id(l) + 55200584 + ``` + + - `+` 和`+=` + + - `+` + + 拼接两个列表, 然后返回一个新列表 + + - `+=` + + ``` + >>> l = ['a'] + >>> id(l) + 55200664 + >>> l += ['b'] + >>> id(l) + 55200664 + >>> l + ['a', 'b'] + ``` + + - `*`和`*=` + + ``` + >>> a = 'a' + >>> id(a) + 53622432 + >>> l = [a] * 10 + >>> l + ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + >>> id(l[0]) + 53622432 + >>> id(l[1]) + 53622432 + >>> id(l[9]) + 53622432 + + # 赋值语句之后, a已经是一个新的对象了 + >>> a = 'b' + >>> l + ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + >>> id(a) + 53647264 + ``` + + - insert + + 指定位置添加元素 + + ``` + l.insert(0, 'b') + ``` + + - Retrieve(检索) + + - 索引取值 + + 所有序列都支持索引取值 + + - 切片 + + ``` + your_list[start:end:step] + # 取一段区间 + your_list[start:end] + + # 取最后一个值 + your_list[-1] + + # 间隔问题 + your_list[1:20:2] + ``` + + - index + + ``` + >>> l + ['a', 'b', 'c'] + >>> l.index('a') + 0 + ``` + + - Update(更新) + + - 索引赋值 + + ``` + l[0] = 'a_1' + ``` + + - 切片赋值 + + ``` + >>> l + ['a_1', 'a_2', 'b', 'c'] + >>> l[0:2] = "a" + >>> l + ['a', 'b', 'c'] + >>> l[0:2] = 1 + ``` + + - DELETE(删除) + + - pop() + + 从末尾删除元素并返回 + + ``` + >>> l + ['a', 'b', 'c'] + >>> x = l.pop() + >>> l + ['a', 'b'] + >>> x + 'c' + ``` + + - clear() + + 清楚当前列表的元素, 不会改变列表的内存地址. + + - ★SORT(排序) + + - sort() + + ``` + >>> l + [1, 3, 2, 6, 4] + >>> l.sort() + >>> l + [1, 2, 3, 4, 6] + + ``` + + - sorted + + 排序后返回新列表 + + ``` + >>> l2 = sorted(l) + >>> l + [1, 3, 2, 6, 4] + >>> l2 + [1, 2, 3, 4, 6] + >>> id(l) + 55201384 + >>> id(l2) + 55200984 + ``` + + - reverse + + ``` + >>> l2 + [1, 2, 3, 4, 6] + >>> l2.reverse() + >>> l2 + [6, 4, 3, 2, 1] + ``` + + - reversed + + 倒序之后返回新列表 + + ``` + >>> l + [1, 3, 2, 6, 4] + >>> list(reversed(l)) + [4, 6, 2, 3, 1] + ``` + +- tuple + + - Create + + 无 + + - Retrieve + + - 索引取值 + - index + - 切片 + + - Update + + 无 + + - Delete + + 无 + +- dict + + - Create + + - 键对值赋值 + + - update + + 提供合并字典的功能 + + ``` + >>> d + {'a': 1} + >>> d2 = {"b":2, "c": 3} + >>> d.update(d2) + >>> d + {'a': 1, 'b': 2, 'c': 3} + ``` + + - setdefault + + 如果字典中没有当前key, 那么就设置默认值 + + ``` + >>> d + {'a': 1, 'b': 2, 'c': 3} + >>> d.setdefault('b', 0) + 2 + >>> d.setdefault('d', 0) + 0 + >>> d + {'a': 1, 'b': 2, 'c': 3, 'd': 0} + + ``` + + - Retrieve + + - 键对值访问 + + - get + + 键对值访问缺失key会报错, 而get可以指定默认值 + + ``` + >>> d['e'] + Traceback (most recent call last): + File "", line 1, in + KeyError: 'e' + >>> d.get('f') + >>> d.get('f', 0) + 0 + ``` + + - keys() + + 返回所有key + + ``` + d.keys() + ``` + + - values() + + 返回所有value + + ``` + d.values() + ``` + + - items() + + 返回所有键对值 + + ``` + d.items() + ``` + + - Update + + - 键对值赋值 + + ``` + d['a'] = 100 + ``` + + - update + + ``` + >>> d.update({"b": 200, "c": 300}) + >>> d + {'a': 100, 'b': 200, 'c': 300, 'd': 0} + ``` + + - Delete + + - pop(key) + + 删除当前元素并返回value + + - popitem() + + 对于人来说, 相当于随机返回一个item + + - clear() + +- set + + - Create + + - add + - update + + - Retrieve + + - 运算符`in` + + ``` + >>> s + {'a'} + >>> "a" in s + True + + ``` + + - update + + - union + + 合并两个set, 并返回一个新的set + + - delete + + - remove 和discard + + discard缺失元素时不会报错, 而remove会报错 + + ``` + >>> s + {'b', 'c', 'a'} + >>> s.remove("a") + >>> s + {'b', 'c'} + >>> s.discard("e") + >>> s.remove("a") + Traceback (most recent call last): + File "", line 1, in + KeyError: 'a' + >>> + ``` + + - pop() + + 当成无序删除并返回元素 + +## 课后作业 + - 完成四大基础数据结构的CRUD操作 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 845a3ea498cbbc26d577afa9b5b8288a58376a5f..c7c57641c2b125d1f53c5e6a48349f13db85623a 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\214\345\221\250-\345\255\227\347\254\246\344\270\262\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204CRUD/\347\254\254\344\272\214\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,301 +1,301 @@ -# 第二周-第二节课 - -## 字符串(字符序列)和字节序列 - -- 字符 - - - 由于历史原因, 将字符定义为`unicode`字符还不够准确, 但是未来字符的定义一定是`unicode`字符 - -- 字节 - - 就是字符的二进制表现形式 - -- 码位 - - 我们计算机显示的实际上是码位 - - ``` - >>> '你好'.encode("unicode_escape").decode() - '\\u4f60\\u597d' - >>> - >>> '\u4f60\u597d' - '你好' - ``` - - - `UNICODE`标准中以4~6个十六进制数字表示 - -- 编码 - - - 字符序列(string) -> 字节序列(bytes) -------------编码(encode) - - ``` - >>> "你好".encode("utf-8") - b'\xe4\xbd\xa0\xe5\xa5\xbd' - ``` - - - 字节序列(bytes) -> 字符序列(string) -------------解码(decode) - - ``` - >>> b - b'\xe4\xbd\xa0\xe5\xa5\xbd' - >>> b.decode("utf") - '你好' - ``` - -- 编码错误 - - - 乱码和混合编码 - - - 检查编码 - - 没有办法通过字节序列来得出编码格式, 都是统计学来预估当前的编码 - - ``` - # 安装chardet - pip install chardet - - # 导入charet - >>> import chardet - >>> chardet.detect(b) - ``` - - - 解决乱码和混合编码 - - - 忽略错误编码 - - ``` - >>> b_2.decode("utf-8", errors='ignore') - '你好' - ``` - - - 利用鬼符来替换 - - ``` - >>> b_2.decode("utf-8", errors='replace') - '你好��' - ``` - - - -## 字符串的CRUD操作 - -``` -通过dir("")可以查看当前字符串的操作方法 -``` - -- Create(创建) - - - `+` - - ``` - >>> a = "a" - >>> id(a) - 22951584 - >>> a = a + "b" - >>> id(a) - 60513280 - >>> a - 'ab' - ``` - - - `+=` - - ``` - a += "b" 就是 a = a + "b" 省略写法 - ``` - -- Retrieve(检索) - - - 根据索引获取字符 - - 在计算机语言当中, 索引值是从0开始数的 - - ``` - >>> a = "hello, world" - >>> a[1] - 'e' - ``` - - - find和index(获取目标字符的索引值) - - ``` - >>> a.find("e") - 1 - >>> a.find("!") - -1 - - # 找不到目标字符时, index会报错 - >>> a.index("!") - Traceback (most recent call last): - File "", line 1, in - ValueError: substring not found - ``` - - - startwith和endwith - - ``` - >>> f = "2020-11-22-xxxxx" - >>> f.startswith("2020-11-22") - True - >>> f = "xxxxx.jpg" - >>> f.endswith("jpg") - True - ``` - -- UPDATE(更新) - - - replace(替换) - - 返回的是一个新的字符串 - - ``` - a.replace("wer", "wor") - ``` - - - split(分割) - - ``` - >>> a = "<>, <>, <>" - >>> a.split(",") - ['<>', ' <>', ' <>'] - ``` - - - join(拼接) - - ``` - >>> b - ['<>', ' <>', ' <>'] - >>> ",".join(b) - '<>, <>, <>' - ``` - -- DELETE(删除) - - - strip - - ``` - >>> a - ' hello, world ' - >>> a.strip() - 'hello, world' - >>> - - ``` - - - lstrip - - - rstrip - -## 字符串的输出和输入 - -- 保存到文件 - - ``` - # open函数打开一个文件, 没有文件会新建, 但是路劲不对会报错 - # 指定文件名, 方法(读, 写, 追加), 编码格式 - output = open("output.txt", "w", encoding="utf-8") - content = "hello, world" - # 正式写入文件 - output.write(content) - # 关闭文件句柄 - output.close() - ``` - -- 读取文件 - - ``` - input = open("output.txt", "r", encoding="utf-8") - # 获取文件中的内容 - content = input.read() - print(content) - - # 暂时理解为只能读取一遍 - content_2 = input.read() - print(content_2) - ``` - -- 追加文件 - - ``` - output = open("output.txt", "a", encoding="utf-8") - content = "\nhello, world" - # 正式写入文件 - output.write(content) - # 关闭文件句柄 - output.close() - ``` - -## 字符串的格式化输出 - -- format - - - 按传入参数默认顺序 - - ``` - a = "ping" - b = "pong" - - "play pingpong: {}, {}".format(a, b) - ``` - - - 按指定参数索引 - - ``` - a = "ping" - b = "pong" - - "play pingpong: {0}, {1}, {0}, {1}".format(a, b) - ``` - - - 按关键词参数 - - ``` - a = "ping" - b = "pong" - - print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) - ``` - - - 按变量(推荐, 但是只有3.6以上才可以使用) - - ``` - a = "ping" - b = "pong" - - print(f"playing pingpong: {a}, {b}") - ``` - - - 小数的表示 - - ``` - >>> "{:.2f}".format(3.14159) - '3.14' - >>> - ``` - -- % - - ``` - >>> "playing %s %s" % ("ping", "pong") - 'playing ping pong' - - ``` - -## 课后作业 - -- 练习字符串的编码和解码 - -- 练习字符串的CRUD - -- 练习字符串的格式化 - - ``` - content = """ - >>> "playing %s %s" % ("ping", "pong") - 'playing ping pong' - - """ - ``` - -- 将content内容保存到本地文件 - +# 第二周-第二节课 + +## 字符串(字符序列)和字节序列 + +- 字符 + + - 由于历史原因, 将字符定义为`unicode`字符还不够准确, 但是未来字符的定义一定是`unicode`字符 + +- 字节 + + 就是字符的二进制表现形式 + +- 码位 + + 我们计算机显示的实际上是码位 + + ``` + >>> '你好'.encode("unicode_escape").decode() + '\\u4f60\\u597d' + >>> + >>> '\u4f60\u597d' + '你好' + ``` + + - `UNICODE`标准中以4~6个十六进制数字表示 + +- 编码 + + - 字符序列(string) -> 字节序列(bytes) -------------编码(encode) + + ``` + >>> "你好".encode("utf-8") + b'\xe4\xbd\xa0\xe5\xa5\xbd' + ``` + + - 字节序列(bytes) -> 字符序列(string) -------------解码(decode) + + ``` + >>> b + b'\xe4\xbd\xa0\xe5\xa5\xbd' + >>> b.decode("utf") + '你好' + ``` + +- 编码错误 + + - 乱码和混合编码 + + - 检查编码 + + 没有办法通过字节序列来得出编码格式, 都是统计学来预估当前的编码 + + ``` + # 安装chardet + pip install chardet + + # 导入charet + >>> import chardet + >>> chardet.detect(b) + ``` + + - 解决乱码和混合编码 + + - 忽略错误编码 + + ``` + >>> b_2.decode("utf-8", errors='ignore') + '你好' + ``` + + - 利用鬼符来替换 + + ``` + >>> b_2.decode("utf-8", errors='replace') + '你好��' + ``` + + + +## 字符串的CRUD操作 + +``` +通过dir("")可以查看当前字符串的操作方法 +``` + +- Create(创建) + + - `+` + + ``` + >>> a = "a" + >>> id(a) + 22951584 + >>> a = a + "b" + >>> id(a) + 60513280 + >>> a + 'ab' + ``` + + - `+=` + + ``` + a += "b" 就是 a = a + "b" 省略写法 + ``` + +- Retrieve(检索) + + - 根据索引获取字符 + + 在计算机语言当中, 索引值是从0开始数的 + + ``` + >>> a = "hello, world" + >>> a[1] + 'e' + ``` + + - find和index(获取目标字符的索引值) + + ``` + >>> a.find("e") + 1 + >>> a.find("!") + -1 + + # 找不到目标字符时, index会报错 + >>> a.index("!") + Traceback (most recent call last): + File "", line 1, in + ValueError: substring not found + ``` + + - startwith和endwith + + ``` + >>> f = "2020-11-22-xxxxx" + >>> f.startswith("2020-11-22") + True + >>> f = "xxxxx.jpg" + >>> f.endswith("jpg") + True + ``` + +- UPDATE(更新) + + - replace(替换) + + 返回的是一个新的字符串 + + ``` + a.replace("wer", "wor") + ``` + + - split(分割) + + ``` + >>> a = "<>, <>, <>" + >>> a.split(",") + ['<>', ' <>', ' <>'] + ``` + + - join(拼接) + + ``` + >>> b + ['<>', ' <>', ' <>'] + >>> ",".join(b) + '<>, <>, <>' + ``` + +- DELETE(删除) + + - strip + + ``` + >>> a + ' hello, world ' + >>> a.strip() + 'hello, world' + >>> + + ``` + + - lstrip + + - rstrip + +## 字符串的输出和输入 + +- 保存到文件 + + ``` + # open函数打开一个文件, 没有文件会新建, 但是路劲不对会报错 + # 指定文件名, 方法(读, 写, 追加), 编码格式 + output = open("output.txt", "w", encoding="utf-8") + content = "hello, world" + # 正式写入文件 + output.write(content) + # 关闭文件句柄 + output.close() + ``` + +- 读取文件 + + ``` + input = open("output.txt", "r", encoding="utf-8") + # 获取文件中的内容 + content = input.read() + print(content) + + # 暂时理解为只能读取一遍 + content_2 = input.read() + print(content_2) + ``` + +- 追加文件 + + ``` + output = open("output.txt", "a", encoding="utf-8") + content = "\nhello, world" + # 正式写入文件 + output.write(content) + # 关闭文件句柄 + output.close() + ``` + +## 字符串的格式化输出 + +- format + + - 按传入参数默认顺序 + + ``` + a = "ping" + b = "pong" + + "play pingpong: {}, {}".format(a, b) + ``` + + - 按指定参数索引 + + ``` + a = "ping" + b = "pong" + + "play pingpong: {0}, {1}, {0}, {1}".format(a, b) + ``` + + - 按关键词参数 + + ``` + a = "ping" + b = "pong" + + print("play pingpong: {a}, {b}, {a}, {b}".format(a='ping', b='pong')) + ``` + + - 按变量(推荐, 但是只有3.6以上才可以使用) + + ``` + a = "ping" + b = "pong" + + print(f"playing pingpong: {a}, {b}") + ``` + + - 小数的表示 + + ``` + >>> "{:.2f}".format(3.14159) + '3.14' + >>> + ``` + +- % + + ``` + >>> "playing %s %s" % ("ping", "pong") + 'playing ping pong' + + ``` + +## 课后作业 + +- 练习字符串的编码和解码 + +- 练习字符串的CRUD + +- 练习字符串的格式化 + + ``` + content = """ + >>> "playing %s %s" % ("ping", "pong") + 'playing ping pong' + + """ + ``` + +- 将content内容保存到本地文件 + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index ea1de6af1625a5ea1c3a1592c39cd5e8aad27faa..f996ea6a4a822ec78bef92536be9d50d3991dc16 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,200 +1,200 @@ -# 第五周-第一节课 - -## requests模块的介绍 - -- requests的作用 - - 通过python来模拟请求网址 - -- 一个模拟请求由以下四个部分组成 - - - url - - method - - body - - headers - -- 模拟请求百度 - ``` - 没有安装requests库的同学, 在当前python环境下执行以下语句安装第三方库 - pip install requests - ``` - ![install_requests.png](https://i.im5i.com/2021/01/11/install_requests.png) - ``` - import requests - - - def request_baidu(): - url = "https://www.baidu.com/" - # body = "" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(response.text) - ``` - -## 理解多线程和多进程 - -- 什么是进程?什么是线程? - - - 进程: 可以简单地认为是一个程序. 进程是操作系统分配资源的最小单位. - - 线程: 一个进程可以有多个线程, 每个线程可以独立完成一些任务. 线程是操作系统进行运算调度的最小单位. - -- 多线程demo - - ``` - from threading import Thread - for i in range(10): - # 只是创建了线程对象 - t = Thread(target=request_baidu) - # 启动线程 - t.start() - ``` - -- 多进程demo - - ``` - from multiprocessing import Process - for i in range(10): - # 只是创建了进程对象 - p = Process(target=request_baidu) - # 启动进程 - p.start() - ``` - -- 多线程 - - - 等待任务完成后回到主进程 - - 通过调用`Thread`对象的`join`方法 - - ``` - # 保存当前thread对象 - thread_array = [] - for i in range(10): - t = Thread(target=request_baidu, args=(i, )) - thread_array.append(t) - t.start() - # 调用thread对象join接口, 等待任务完成后回到主进程 - for t in thread_array: - t.join() - print("done!") - ``` - - - 如何拿到返回结果 - - - 赋值到全局变量当中, 添加到可变对象之中 - - ``` - result = [] - def request_baidu(index): - ... - result.append(response) - - if __name__ == "__main__": - thread_array = [] - for i in range(10): - t = Thread(target=request_baidu, args=(i, )) - thread_array.append(t) - t.start() - for t in thread_array: - t.join() - print("done!") - print(result) - ``` - -- 多进程 - - - 等待任务完成后回到主进程 - - 通过调用`Process`对象的`join`方法 - - - 如何拿到返回结果 - - 无法通过全局变量存储返回结果. - - 多进程相当于启动了多个程序, 共同执行了同一份代码, 他们之间的内存地址完全不一样 - - ``` - import requests - import time - from threading import Thread - from multiprocessing import Process - - result = [] - print(f"主进程result内存地址: {id(result)}") - - def request_baidu(index): - time.sleep(2) - url = "https://www.baidu.com/" - # body = "" - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - } - response = requests.get(url=url, headers=headers) - print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") - print(f"子进程result内存地址: {id(result)}") - result.append(response) - - # 如果没有判断入口代码段if __name__ == "__main__", 多进程程序会报错 - # 原因是windows和pycharm的进程阻塞带来的问题 - if __name__ == "__main__": - process_array = [] - for i in range(10): - p = Process(target=request_baidu, args=(i, )) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("done!") - print(result) - ``` - -- 多进程和多线程的异同点 - - - 相同点 - - - 都是对`cpu`工作时间段的描述, 只是颗粒度不同. - - 简单地说就是多进程和多线程都会调用`cpu`资源的, 但是进程可以启动多个线程去执行. - - - 在`linux`内核态不区分进程和线程 - - - 不同点 - - - 进程有自己的独立地址空间, 建立数据表来维护代码段, 堆栈段和数据段, 而线程共享进程中的资源, 使用相同的地址空间, 所以线程间的切换快得多. - - 因为线程共享进程的全局变量, 静态变量等对象, 线程间的通信更为方便, 而进程间的通信更加复杂, 需要以`ipc`的方式进行. - - 多进程要比多线程要健壮. 进程之间一般不会相互影响, 而多线程有一条线程崩溃, 会导致整个进程跟着发生崩溃或者无法正常退出等. - -## 全局解释器锁(GIL) - -- 计算密集型 - - 主要占用`cpu`资源 - -- IO密集型 - - `IO`就是`input output`, 需要等待的一些任务 - - - 网络请求会有网络延迟 - - 和数据库交互需要等待数据库查询事件 - - 读写硬盘 - -- 多进程在处理计算密集型程序的时候比多线程块 - - 由于全局解释器锁的存在, 一个进程下, 只允许一个线程执行`Python`程序的字节码(当前代码文件的二进制表示). - - 简单地说, 创建的10个线程其实在争夺一个`cpu`资源. 但是遇到`io`操作会让渡`cpu`资源. - -- 如何绕过GIL? - - - 将多线程方法改为多进程 - - 将计算密集型任务转移给C扩展. - - 分布式计算引擎`spark`, `Apache` - - 使用`PyPy`解释器, 工业上几乎没人这么用, 因为`PyPy`并不成熟. - -## 课后作业 - -- 利用`Python`实现一个多线程程序 -- 将多线程程序改为多进程程序 - +# 第五周-第一节课 + +## requests模块的介绍 + +- requests的作用 + + 通过python来模拟请求网址 + +- 一个模拟请求由以下四个部分组成 + + - url + - method + - body + - headers + +- 模拟请求百度 + ``` + 没有安装requests库的同学, 在当前python环境下执行以下语句安装第三方库 + pip install requests + ``` + ![install_requests.png](https://i.im5i.com/2021/01/11/install_requests.png) + ``` + import requests + + + def request_baidu(): + url = "https://www.baidu.com/" + # body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(response.text) + ``` + +## 理解多线程和多进程 + +- 什么是进程?什么是线程? + + - 进程: 可以简单地认为是一个程序. 进程是操作系统分配资源的最小单位. + - 线程: 一个进程可以有多个线程, 每个线程可以独立完成一些任务. 线程是操作系统进行运算调度的最小单位. + +- 多线程demo + + ``` + from threading import Thread + for i in range(10): + # 只是创建了线程对象 + t = Thread(target=request_baidu) + # 启动线程 + t.start() + ``` + +- 多进程demo + + ``` + from multiprocessing import Process + for i in range(10): + # 只是创建了进程对象 + p = Process(target=request_baidu) + # 启动进程 + p.start() + ``` + +- 多线程 + + - 等待任务完成后回到主进程 + + 通过调用`Thread`对象的`join`方法 + + ``` + # 保存当前thread对象 + thread_array = [] + for i in range(10): + t = Thread(target=request_baidu, args=(i, )) + thread_array.append(t) + t.start() + # 调用thread对象join接口, 等待任务完成后回到主进程 + for t in thread_array: + t.join() + print("done!") + ``` + + - 如何拿到返回结果 + + - 赋值到全局变量当中, 添加到可变对象之中 + + ``` + result = [] + def request_baidu(index): + ... + result.append(response) + + if __name__ == "__main__": + thread_array = [] + for i in range(10): + t = Thread(target=request_baidu, args=(i, )) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print("done!") + print(result) + ``` + +- 多进程 + + - 等待任务完成后回到主进程 + + 通过调用`Process`对象的`join`方法 + + - 如何拿到返回结果 + + 无法通过全局变量存储返回结果. + + 多进程相当于启动了多个程序, 共同执行了同一份代码, 他们之间的内存地址完全不一样 + + ``` + import requests + import time + from threading import Thread + from multiprocessing import Process + + result = [] + print(f"主进程result内存地址: {id(result)}") + + def request_baidu(index): + time.sleep(2) + url = "https://www.baidu.com/" + # body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + } + response = requests.get(url=url, headers=headers) + print(f"当前请求序号: {index}, 返回结果状态码: {response.status_code}") + print(f"子进程result内存地址: {id(result)}") + result.append(response) + + # 如果没有判断入口代码段if __name__ == "__main__", 多进程程序会报错 + # 原因是windows和pycharm的进程阻塞带来的问题 + if __name__ == "__main__": + process_array = [] + for i in range(10): + p = Process(target=request_baidu, args=(i, )) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!") + print(result) + ``` + +- 多进程和多线程的异同点 + + - 相同点 + + - 都是对`cpu`工作时间段的描述, 只是颗粒度不同. + + 简单地说就是多进程和多线程都会调用`cpu`资源的, 但是进程可以启动多个线程去执行. + + - 在`linux`内核态不区分进程和线程 + + - 不同点 + + - 进程有自己的独立地址空间, 建立数据表来维护代码段, 堆栈段和数据段, 而线程共享进程中的资源, 使用相同的地址空间, 所以线程间的切换快得多. + - 因为线程共享进程的全局变量, 静态变量等对象, 线程间的通信更为方便, 而进程间的通信更加复杂, 需要以`ipc`的方式进行. + - 多进程要比多线程要健壮. 进程之间一般不会相互影响, 而多线程有一条线程崩溃, 会导致整个进程跟着发生崩溃或者无法正常退出等. + +## 全局解释器锁(GIL) + +- 计算密集型 + + 主要占用`cpu`资源 + +- IO密集型 + + `IO`就是`input output`, 需要等待的一些任务 + + - 网络请求会有网络延迟 + - 和数据库交互需要等待数据库查询事件 + - 读写硬盘 + +- 多进程在处理计算密集型程序的时候比多线程块 + + 由于全局解释器锁的存在, 一个进程下, 只允许一个线程执行`Python`程序的字节码(当前代码文件的二进制表示). + + 简单地说, 创建的10个线程其实在争夺一个`cpu`资源. 但是遇到`io`操作会让渡`cpu`资源. + +- 如何绕过GIL? + + - 将多线程方法改为多进程 + - 将计算密集型任务转移给C扩展. + - 分布式计算引擎`spark`, `Apache` + - 使用`PyPy`解释器, 工业上几乎没人这么用, 因为`PyPy`并不成熟. + +## 课后作业 + +- 利用`Python`实现一个多线程程序 +- 将多线程程序改为多进程程序 + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index d2577afb52f5488036e1d5e369eab99f86766782..d07b82b33adf4c3285ad9a06e624bb0920a2dd54 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,199 +1,199 @@ -# 第五周-第三节课 - -## 迭代器和生成器 - -- 迭代器 - - 概念上: 迭代器可以用来表示一个数据流, 提供了数据的惰性返回功能(只有我们主动去使用next方法调用, 才会返回值). - - 实现上: 实现了`__next__`接口的对象 - - > 传统声明一个列表, 里面的元素会立即写进内存当中, 占用大量内存. - > - > 迭代器可以一次只返回一个元素, 占用内存非常小, 在读取大文件和大的数据集合的时候特别有用 - - - 通过`iter`方法返回一个迭代器对象 - - ``` - # 两者实现的功能是一摸一样的 - l = list(range(10**7)) - l2 = iter(range(10**7)) - ``` - - - 通过`next`方法主动获取迭代器中的值 - - ``` - # 当迭代器中没有值了以后, 会抛出StopIteration的异常, 需要大家自行处理一下 - l = iter(range(5)) - print(next(l)) - print(next(l)) - print(next(l)) - print(next(l)) - print(next(l)) - print(next(l)) - ``` - -- 生成器 - - 生成器是一种特殊的迭代器, 在迭代器惰性返回数据的基础上, 提供了额外的功能, 实现了程序的暂停. - - - 声明一个生成器 - - 只要函数体中有`yield`关键词, 它就是一个生成器 - - > yield翻译为让渡, 我们可以简单理解为暂停并返回右边的值 - - ``` - def my_range_gen(n): - for i in range(n): - yield i*i - print(f"current index: {i}") - - my_range = my_range_gen(10) - print(my_range) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - print(next(my_range)) - ``` - -- 生成器和迭代器的区别? - - 同样提供了惰性返回的功能, 迭代器侧重于提供**数据**的惰性返回功能, 生成器侧重于**指令**的惰性返回功能 - -## 协程 - -- 协程的原理 - - 协程的实现原理就是生成器的实现原理, 在生成器的基础上又提供了传递值的功能. - - - 通过`send`方法向生成器传递值, 以下例子中, b就是通过send方法赋值为2 - - 对生成器进行`send`操作一定要调用`next`方法预激, 使其停留在第一个yield位置 - - ``` - def simple_coro(a): - print("初始值 a=", a) - b = yield a - print("传递值 b=", b) - c = yield a + b - print("传递值 c=", c) - - coro = simple_coro(1) - print(next(coro)) - print(coro.send(2)) - print(coro.send(3)) - - - ``` - - ![](https://i.im5i.com/2021/01/10/yield.png) - - - 用协程实现计算平均数的函数 - - ``` - def coro_avg(): - total = 0 - length = 0 - while True: - try: - value = yield total/length - except ZeroDivisionError: - value = yield 0 - total += value - length += 1 - - my_avg = coro_avg() - print(next(my_avg)) - print(my_avg.send(2)) - print(my_avg.send(3)) - ``` - - - `yield`和`yield from` - - > yield from实现的协程异步程序晦涩难懂, 在python3.4引用asyncio标准库之后被弃用 - - `yield from` 用来驱动子程序中的循环并**返回最终值** - - ``` - def return_triple(): - while True: - value = yield - if value % 3 == 0: - return value - - - def triple_recorder(): - while True: - result = yield from return_triple() - triple_array.append(result) - - triple_array = [] - coro = triple_recorder() - next(coro) - for i in range(100): - coro.send(i) - print(triple_array) - ``` - -## 异步I/O - -- asyncio(异步) - - > Python3.4引入的标准库, 替换yield from实现协程异步IO, 可以更好地实现异步程序 - - 实现原理: 自动维护了一个事件队列, 然后循环访问事件来完成异步的消息维护. - - ``` - import asyncio - import time - - - class Response: - staus_code = 200 - - - async def sim_request(index): - print(f"模拟发送请求 Index: {index}") - response = Response() - # 模拟网络延迟 - # 当前是单线程运行的, 如果调用的是time.sleep(1), 那么这个线程会被阻塞 - # 当前线程被阻塞之后, 不会让渡cpu资源, 异步的效率就不会体现 - await asyncio.sleep(1) - print(f"request index {index}, response status_code: {response.staus_code}") - return response.staus_code - - # 获取消息队列 - loop = asyncio.get_event_loop() - - # 包装任务 - task_array = [] - for i in range(100): - task_array.append(sim_request(i)) - - # 循环访问事件来完成异步的消息维护 - loop.run_until_complete(asyncio.wait(task_array)) - - # 关闭事件循环 - loop.close() - ``` - - - 当前异步实际上有没有提高效率, 也关乎到你调用的第三方是不是异步的. - - > 这也是当前python异步的一个痛点, 就是丰富的第三方库不是都支持asyncio的. - - - 小技巧: 获取异步完成之后的所有返回值 - - ``` - result = loop.run_until_complete(asyncio.gather(*task_array)) - print(result) - ``` - -## 课后作业 - -- 什么是迭代器?什么是生成器?两者有什么区别? -- 协程的实现原理. -- `asyncio`实现原理 -- 用协程实现一个计算平均数的函数 -- 编写一个`asyncio`异步程序 +# 第五周-第三节课 + +## 迭代器和生成器 + +- 迭代器 + + 概念上: 迭代器可以用来表示一个数据流, 提供了数据的惰性返回功能(只有我们主动去使用next方法调用, 才会返回值). + + 实现上: 实现了`__next__`接口的对象 + + > 传统声明一个列表, 里面的元素会立即写进内存当中, 占用大量内存. + > + > 迭代器可以一次只返回一个元素, 占用内存非常小, 在读取大文件和大的数据集合的时候特别有用 + + - 通过`iter`方法返回一个迭代器对象 + + ``` + # 两者实现的功能是一摸一样的 + l = list(range(10**7)) + l2 = iter(range(10**7)) + ``` + + - 通过`next`方法主动获取迭代器中的值 + + ``` + # 当迭代器中没有值了以后, 会抛出StopIteration的异常, 需要大家自行处理一下 + l = iter(range(5)) + print(next(l)) + print(next(l)) + print(next(l)) + print(next(l)) + print(next(l)) + print(next(l)) + ``` + +- 生成器 + + 生成器是一种特殊的迭代器, 在迭代器惰性返回数据的基础上, 提供了额外的功能, 实现了程序的暂停. + + - 声明一个生成器 + + 只要函数体中有`yield`关键词, 它就是一个生成器 + + > yield翻译为让渡, 我们可以简单理解为暂停并返回右边的值 + + ``` + def my_range_gen(n): + for i in range(n): + yield i*i + print(f"current index: {i}") + + my_range = my_range_gen(10) + print(my_range) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + print(next(my_range)) + ``` + +- 生成器和迭代器的区别? + + 同样提供了惰性返回的功能, 迭代器侧重于提供**数据**的惰性返回功能, 生成器侧重于**指令**的惰性返回功能 + +## 协程 + +- 协程的原理 + + 协程的实现原理就是生成器的实现原理, 在生成器的基础上又提供了传递值的功能. + + - 通过`send`方法向生成器传递值, 以下例子中, b就是通过send方法赋值为2 + + 对生成器进行`send`操作一定要调用`next`方法预激, 使其停留在第一个yield位置 + + ``` + def simple_coro(a): + print("初始值 a=", a) + b = yield a + print("传递值 b=", b) + c = yield a + b + print("传递值 c=", c) + + coro = simple_coro(1) + print(next(coro)) + print(coro.send(2)) + print(coro.send(3)) + + + ``` + + ![](https://i.im5i.com/2021/01/10/yield.png) + + - 用协程实现计算平均数的函数 + + ``` + def coro_avg(): + total = 0 + length = 0 + while True: + try: + value = yield total/length + except ZeroDivisionError: + value = yield 0 + total += value + length += 1 + + my_avg = coro_avg() + print(next(my_avg)) + print(my_avg.send(2)) + print(my_avg.send(3)) + ``` + + - `yield`和`yield from` + + > yield from实现的协程异步程序晦涩难懂, 在python3.4引用asyncio标准库之后被弃用 + + `yield from` 用来驱动子程序中的循环并**返回最终值** + + ``` + def return_triple(): + while True: + value = yield + if value % 3 == 0: + return value + + + def triple_recorder(): + while True: + result = yield from return_triple() + triple_array.append(result) + + triple_array = [] + coro = triple_recorder() + next(coro) + for i in range(100): + coro.send(i) + print(triple_array) + ``` + +## 异步I/O + +- asyncio(异步) + + > Python3.4引入的标准库, 替换yield from实现协程异步IO, 可以更好地实现异步程序 + + 实现原理: 自动维护了一个事件队列, 然后循环访问事件来完成异步的消息维护. + + ``` + import asyncio + import time + + + class Response: + staus_code = 200 + + + async def sim_request(index): + print(f"模拟发送请求 Index: {index}") + response = Response() + # 模拟网络延迟 + # 当前是单线程运行的, 如果调用的是time.sleep(1), 那么这个线程会被阻塞 + # 当前线程被阻塞之后, 不会让渡cpu资源, 异步的效率就不会体现 + await asyncio.sleep(1) + print(f"request index {index}, response status_code: {response.staus_code}") + return response.staus_code + + # 获取消息队列 + loop = asyncio.get_event_loop() + + # 包装任务 + task_array = [] + for i in range(100): + task_array.append(sim_request(i)) + + # 循环访问事件来完成异步的消息维护 + loop.run_until_complete(asyncio.wait(task_array)) + + # 关闭事件循环 + loop.close() + ``` + + - 当前异步实际上有没有提高效率, 也关乎到你调用的第三方是不是异步的. + + > 这也是当前python异步的一个痛点, 就是丰富的第三方库不是都支持asyncio的. + + - 小技巧: 获取异步完成之后的所有返回值 + + ``` + result = loop.run_until_complete(asyncio.gather(*task_array)) + print(result) + ``` + +## 课后作业 + +- 什么是迭代器?什么是生成器?两者有什么区别? +- 协程的实现原理. +- `asyncio`实现原理 +- 用协程实现一个计算平均数的函数 +- 编写一个`asyncio`异步程序 - 扩展: 了解`aiohttp`异步请求网址 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 342f5173716da49f5e0fd7b2b14d9099a9049bff..31f783c41c980a01f193e0eb1269425c5abf1e24 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\344\272\224\345\221\250-\345\244\232\347\272\277\347\250\213\344\270\216\345\244\232\350\277\233\347\250\213/\347\254\254\344\272\224\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,184 +1,184 @@ -# 第五周-第二节课 - -## 进程间通信(IPC) - -- 文件 - - 通过读写文件来进行变量, 数据, 信息的传递 - - - 读写冲突 - - 两个进程同时进行写, 或者一个写一个读, 造成了冲突. - - - 解决读写冲突 - - - 互斥锁 - - ``` - from multiprocessing import Process, Lock - - - def save_to_file(index, lock): - with lock: - with open("test.log", "a", encoding="utf-8") as f: - f.write(str(index) + "\n") - - - if __name__ == "__main__": - process_array = [] - lock = Lock() - for i in range(10): - p = Process(target=save_to_file, args=(i, lock)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - print("done!") - ``` - -- 套接字(socket-插座) - - 通过一个协议, 连接两个进程. 主要就是网络请求. - - > 进程A向百度云上传文件, 进程B向百度云下载文件, 不会有冲突. - - ![socket.png](https://i.im5i.com/2021/01/10/socket.png) - -- 管道(了解) - - 用文件的内存缓冲区作为管道, 实现进程间通信 - - - 匿名管道 - - 主进程和子进程进行交互 - - - 具名管道 - - 和匿名管道原理是一样的, 不是不相关的进程也可以互相访问 - - ![ipc_pipeline.png](https://i.im5i.com/2021/01/10/ipc_pipeline.png) - -- 消息队列 - - 就是一个存在内核内存空间中的列表 - - > redis就是消息队列+socket - - ``` - from multiprocessing import Queue - - def save_to_queue(index, my_queue): - my_queue.put(index) - - - if __name__ == "__main__": - process_array = [] - my_queue = Queue() - for i in range(10): - p = Process(target=save_to_queue, args=(i, my_queue)) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - while True: - print(my_queue.get()) - ``` - -- 共享内存(了解) - - 进程访问内核态同一块内存 - - ``` - from multiprocessing import Queue, Array, Value - ``` - -- 信号量(了解) - - 不是用来传递数据的, 是用来传递消息 - - > 进程B要等到进程A执行到某一步操作后, 才会启动 - - 进程A->发消息->内核->转发信息->进程B - -## 线程间通信 - -线程间通信强调的是线程之间传递对象引用 - -- 共享变量 - - - 线程安全 - - 线程有GIL锁, 但是拿到GIL锁不代表可以一直执行下去. - - 现代计算机多线程也是A执行一会儿, B执行一会儿这样交替执行. - - ``` - import requests - import time - from threading import Thread - - - zero = 0 - - def foo(): - global zero - for i in range(10**7): - zero += 1 - zero -= 1 - - - if __name__ == "__main__": - process_array = [] - for i in range(2): - p = Thread(target=foo) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - print(zero) - ``` - - - 解决线程安全 - - 将重要指令包装成原子操作(不可分割的). - - - 加互斥锁 - - ``` - import requests - import time - from threading import Thread,Lock - - - zero = 0 - lock = Lock() - - def foo(): - global zero - for i in range(10**6): - with lock: - zero += 1 - zero -= 1 - - - if __name__ == "__main__": - process_array = [] - for i in range(2): - p = Thread(target=foo) - process_array.append(p) - p.start() - for p in process_array: - p.join() - - print(zero) - ``` - - - -## 课后作业 - -- 多进程锁, 多线程锁都要自己实现一遍 -- 多进程通过Queue来实现进程通信 +# 第五周-第二节课 + +## 进程间通信(IPC) + +- 文件 + + 通过读写文件来进行变量, 数据, 信息的传递 + + - 读写冲突 + + 两个进程同时进行写, 或者一个写一个读, 造成了冲突. + + - 解决读写冲突 + + - 互斥锁 + + ``` + from multiprocessing import Process, Lock + + + def save_to_file(index, lock): + with lock: + with open("test.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + + + if __name__ == "__main__": + process_array = [] + lock = Lock() + for i in range(10): + p = Process(target=save_to_file, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!") + ``` + +- 套接字(socket-插座) + + 通过一个协议, 连接两个进程. 主要就是网络请求. + + > 进程A向百度云上传文件, 进程B向百度云下载文件, 不会有冲突. + + ![socket.png](https://i.im5i.com/2021/01/10/socket.png) + +- 管道(了解) + + 用文件的内存缓冲区作为管道, 实现进程间通信 + + - 匿名管道 + + 主进程和子进程进行交互 + + - 具名管道 + + 和匿名管道原理是一样的, 不是不相关的进程也可以互相访问 + + ![ipc_pipeline.png](https://i.im5i.com/2021/01/10/ipc_pipeline.png) + +- 消息队列 + + 就是一个存在内核内存空间中的列表 + + > redis就是消息队列+socket + + ``` + from multiprocessing import Queue + + def save_to_queue(index, my_queue): + my_queue.put(index) + + + if __name__ == "__main__": + process_array = [] + my_queue = Queue() + for i in range(10): + p = Process(target=save_to_queue, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + while True: + print(my_queue.get()) + ``` + +- 共享内存(了解) + + 进程访问内核态同一块内存 + + ``` + from multiprocessing import Queue, Array, Value + ``` + +- 信号量(了解) + + 不是用来传递数据的, 是用来传递消息 + + > 进程B要等到进程A执行到某一步操作后, 才会启动 + + 进程A->发消息->内核->转发信息->进程B + +## 线程间通信 + +线程间通信强调的是线程之间传递对象引用 + +- 共享变量 + + - 线程安全 + + 线程有GIL锁, 但是拿到GIL锁不代表可以一直执行下去. + + 现代计算机多线程也是A执行一会儿, B执行一会儿这样交替执行. + + ``` + import requests + import time + from threading import Thread + + + zero = 0 + + def foo(): + global zero + for i in range(10**7): + zero += 1 + zero -= 1 + + + if __name__ == "__main__": + process_array = [] + for i in range(2): + p = Thread(target=foo) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + print(zero) + ``` + + - 解决线程安全 + + 将重要指令包装成原子操作(不可分割的). + + - 加互斥锁 + + ``` + import requests + import time + from threading import Thread,Lock + + + zero = 0 + lock = Lock() + + def foo(): + global zero + for i in range(10**6): + with lock: + zero += 1 + zero -= 1 + + + if __name__ == "__main__": + process_array = [] + for i in range(2): + p = Thread(target=foo) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + print(zero) + ``` + + + +## 课后作业 + +- 多进程锁, 多线程锁都要自己实现一遍 +- 多进程通过Queue来实现进程通信 - 把上述概念熟记并理解 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index d354b3ed1465c798c132e8a4ec2aca3817c19628..bc206791dc6c3869a6a2a7f95280dac35268c4a0 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,136 +1,136 @@ -# 第八周-第一节课 - -> tip: 通过 desc 表名命令查看当前表信息 -> -> tip2: as 关键字可以为我们的字段或者表取别名 - -## Mysql约束 - -顾名思义就是对表中的数据进行限定, 目的是保证数据的正确性, 有效性和完整性 - -- 主键约束`primary key` - - - 什么是主键 - - 关系表中记录的**唯一标识**(不能为null, 不可重复) - - > 选取和业务无关的字段, 常用的主键就是自增id - > - > 数据库引擎会通过主键建立索引, 索引是一个有序结构, 我们希望当前主键的值不要改变, 避免重新建立索引, 影响性能. - - - 添加主键 - - - 建表时添加 - - ``` - CREATE TABLE store_perf( - id int PRIMARY KEY auto_increment, - store_name varchar(255) - ) - ``` - - - 通过可视化界面操作(建议) - - - 主键的长度限制 - - `767bytes`, 对应的长度为`767/4=191` - - > bytes表示字节, 一个utf8mb4按四个字节算, 所以长度最大为191 - - - 自增键必须为主键 - - ``` - Incorrect table definition; there can be only one auto column and it must be defined as a key - ``` - - - 联合主键 - - 主键其实只能有一个, 如果在图形界面当中选择多个字段作为主键, 那么程序会自动帮我们创建联合主键 - - - 修改主键 - - - 添加主键 - - ``` - ALTER TABLE store_perf ADD PRIMARY KEY (`id`) - ``` - - - 移除主键 - - ``` - ALTER TABLE store_perf DROP PRIMARY KEY - ``` - - - 添加联合主键 - - ``` - ALTER TABLE store_perf ADD PRIMARY KEY (`id`, `store_name`) - ``` - -- 非空约束 - - `NOT NULL` - - > 只能约束程序层面上没有操作该表中的某个字段, 不能约束人行为上对其赋值为空白字符. - -- 唯一约束 - - `UNIQUE` - - > NULL可以重复 - > - > 比如统计店铺业绩, 该店铺不可以重复, 那就可以使用唯一约束 - -- 外键约束`foreign key` - - - 外键的作用 - - 保持数据的一致性和完整性, 通过外键来表达主表和从表的关系, 避免冗余字段. - - - 为什么现在不用外键了? - - - 性能问题 - - 插数据需要校验 - - - 并发问题 - - 在高并发的事务场景下, 使用外键容易造成死锁. - - - 扩展性问题 - - - 外键就相当于把对象之间的关系交给数据库来维护, 如果遇到分库分表, 外键是不生效的. - - 作数据迁移时, 触发器, 存储过程和外键都很难迁移, 增加了维护成本. - - - 维护成本 - - - 需要有专业DBA来维护庞大的数据库关系 - -- `default` - - 默认约束, 默认会填充当前字段. - - > 如果我们没有给一个有默认约束的字段create_time值, 那么该字段会默认填充CURRENT_TIMESTAMP - -## 分组查询`GROUP BY` - -将数据按某个字段进行分组, 配合`SUM`, `AVG`, `COUNT`, `MAX`, `MIN`等聚合函数做统计使用 - -``` -INSERT INTO store_perf(store_name, amount, department) values ("男装_店铺1", 34543123.23, "男装事业部"), ("男装_店铺2", 41232373.12, "男装事业部"),("男装_店铺3", 62135632.22, "男装事业部"), ("男装_店铺4", 612356123.26, "男装事业部"), ("女装_店铺1", 78716237854.3, "女装事业部"), ("女装_店铺2", 89123565741.23, "女装事业部"), ("女装_店铺3", 831235769.23, "女装事业部"), ("女装_店铺4", 1912312345.13, "女装事业部"), ("女装_店铺5", 87324234712.92, "女装事业部"), ("女装_店铺6", 12754547457.93, "女装事业部") -``` - -``` -SELECT count(*) as 店铺数, -FORMAT(AVG(amount), 2) as 平均业绩, -SUM(amount) as 总业绩, -MAX(amount) as 最大业绩, -MIN(amount) as 最小业绩, -department as 部门 -FROM store_perf GROUP BY department -``` - -## 课后作业 - -- 简单使用Mysql约束, 并举例说明使用场景. +# 第八周-第一节课 + +> tip: 通过 desc 表名命令查看当前表信息 +> +> tip2: as 关键字可以为我们的字段或者表取别名 + +## Mysql约束 + +顾名思义就是对表中的数据进行限定, 目的是保证数据的正确性, 有效性和完整性 + +- 主键约束`primary key` + + - 什么是主键 + + 关系表中记录的**唯一标识**(不能为null, 不可重复) + + > 选取和业务无关的字段, 常用的主键就是自增id + > + > 数据库引擎会通过主键建立索引, 索引是一个有序结构, 我们希望当前主键的值不要改变, 避免重新建立索引, 影响性能. + + - 添加主键 + + - 建表时添加 + + ``` + CREATE TABLE store_perf( + id int PRIMARY KEY auto_increment, + store_name varchar(255) + ) + ``` + + - 通过可视化界面操作(建议) + + - 主键的长度限制 + + `767bytes`, 对应的长度为`767/4=191` + + > bytes表示字节, 一个utf8mb4按四个字节算, 所以长度最大为191 + + - 自增键必须为主键 + + ``` + Incorrect table definition; there can be only one auto column and it must be defined as a key + ``` + + - 联合主键 + + 主键其实只能有一个, 如果在图形界面当中选择多个字段作为主键, 那么程序会自动帮我们创建联合主键 + + - 修改主键 + + - 添加主键 + + ``` + ALTER TABLE store_perf ADD PRIMARY KEY (`id`) + ``` + + - 移除主键 + + ``` + ALTER TABLE store_perf DROP PRIMARY KEY + ``` + + - 添加联合主键 + + ``` + ALTER TABLE store_perf ADD PRIMARY KEY (`id`, `store_name`) + ``` + +- 非空约束 + + `NOT NULL` + + > 只能约束程序层面上没有操作该表中的某个字段, 不能约束人行为上对其赋值为空白字符. + +- 唯一约束 + + `UNIQUE` + + > NULL可以重复 + > + > 比如统计店铺业绩, 该店铺不可以重复, 那就可以使用唯一约束 + +- 外键约束`foreign key` + + - 外键的作用 + + 保持数据的一致性和完整性, 通过外键来表达主表和从表的关系, 避免冗余字段. + + - 为什么现在不用外键了? + + - 性能问题 + + 插数据需要校验 + + - 并发问题 + + 在高并发的事务场景下, 使用外键容易造成死锁. + + - 扩展性问题 + + - 外键就相当于把对象之间的关系交给数据库来维护, 如果遇到分库分表, 外键是不生效的. + - 作数据迁移时, 触发器, 存储过程和外键都很难迁移, 增加了维护成本. + + - 维护成本 + + - 需要有专业DBA来维护庞大的数据库关系 + +- `default` + + 默认约束, 默认会填充当前字段. + + > 如果我们没有给一个有默认约束的字段create_time值, 那么该字段会默认填充CURRENT_TIMESTAMP + +## 分组查询`GROUP BY` + +将数据按某个字段进行分组, 配合`SUM`, `AVG`, `COUNT`, `MAX`, `MIN`等聚合函数做统计使用 + +``` +INSERT INTO store_perf(store_name, amount, department) values ("男装_店铺1", 34543123.23, "男装事业部"), ("男装_店铺2", 41232373.12, "男装事业部"),("男装_店铺3", 62135632.22, "男装事业部"), ("男装_店铺4", 612356123.26, "男装事业部"), ("女装_店铺1", 78716237854.3, "女装事业部"), ("女装_店铺2", 89123565741.23, "女装事业部"), ("女装_店铺3", 831235769.23, "女装事业部"), ("女装_店铺4", 1912312345.13, "女装事业部"), ("女装_店铺5", 87324234712.92, "女装事业部"), ("女装_店铺6", 12754547457.93, "女装事业部") +``` + +``` +SELECT count(*) as 店铺数, +FORMAT(AVG(amount), 2) as 平均业绩, +SUM(amount) as 总业绩, +MAX(amount) as 最大业绩, +MIN(amount) as 最小业绩, +department as 部门 +FROM store_perf GROUP BY department +``` + +## 课后作业 + +- 简单使用Mysql约束, 并举例说明使用场景. - 练习使用分组查询. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 44e3bfbbdde991883d0c81b906027e71e4fcc581..60ebc092892a2b767fdd5575ad31faef52425abd 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,221 +1,221 @@ -# 第八周-第三节课 - -## 用python连接数据库 - -- pymysql - - ``` - pip install pymysql - - #如果让你装vs环境, 执行以下命令升级pip即可 - python -m pip install --upgrade pip - ``` - -- 连接数据库 - - - 数据库设置 - - ``` - MYSQL_CONF = { - "host": "127.0.0.1", - "user": "root", - "password": "qwe369", - "db": "test" - } - ``` - - - 连接 - - ``` - # 连接数据库 - mysql_con = pymysql.connect(**MYSQL_CONF) - - # 简单理解真正执行语句的线程 - mysql_cursor = mysql_con.cursor() - ``` - -- 执行SQL语句 - - - 单条执行 - - > 执行时间15.31s - - ``` - @clock_it_deco - def insert_one(): - for i in range(10**4): - store_name = f"店铺_{i}" - amount = format(random.uniform(10**3, 10**6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - - SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES ('{store_name}', {amount}, '{department}', '{sta_date}')""" - print(SQL) - mysql_cursor.execute(SQL) - - # 显示执行commit, 避免cursor执行, 但是数据库未收到的执行指令的情况 - mysql_con.commit() - ``` - - - 多条执行 - - - 如果其中有一条记录报错, 那么整个values插入都会失败 - - ``` - @clock_it_deco - def insert_many(): - values = [] - for i in range(10**4): - store_name = f"店铺_{i}" - amount = format(random.uniform(10**3, 10**6), '.2f') - department = f"事业部_{random.randint(1, 10)}" - sta_date = time.strftime("%Y-%m-%d") - values.append((store_name, amount, department, sta_date)) - - SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) - VALUES (%s, %s, %s, %s)""" - print(values) - mysql_cursor.executemany(SQL, values) - mysql_con.commit() - ``` - - - 获取返回值 - - ``` - def get_shops(): - SQL = "select store_name, amount, sta_date from store_perf where department='事业部_1' LIMIT 2" - mysql_cursor.execute(SQL) - # 获取返回值 - query_set = mysql_cursor.fetchall() - print(query_set) - ``` - - - 返回的是一个元组, 元组中表示记录的也是一个元组 - - ``` - (('店铺_1', Decimal('823471.56'), '2021-02-06'), ('店铺_6', Decimal('726927.02'), '2021-02-06')) - ``` - -## 索引和优化 - -- 创建索引 - - > 未建索引: 0.287s - > - > 建了索引后: 0.016s - - - 设置索引的字段不可以超过191个字符长度, 也就是767个bytes - - ``` - CREATE INDEX 索引名 ON 表名(字段1, 字段2...) - - CREATE INDEX store_name_index ON store_perf(store_name) - ``` - -- 创建联合索引 - - ``` - CREATE INDEX store_name_sta_date_department_index ON store_perf(store_name, sta_date, department) - ``` - -- 查看索引 - - ``` - SHOW INDEX FROM store_perf - ``` - -- 删除索引 - - ``` - ALTER TABLE store_perf DROP INDEX store_name_index - ``` - -- 查看当前查询语句有没有命中索引 - - - EXPLAIN语句查看当前语句执行性能 - - 如果key有值, 说明命中了索引, 且key值为索引名 - - ``` - EXPLAIN SELECT * from store_perf WHERE store_name = "店铺_224123" - ``` - -- 单个字段可以命中联合索引吗? - - 联合索引涉及到一个叫`左缀查询`的规则 - - > 如果想命中索引, 查询语句中涉及到字段必须是联合索引创建时从左到右顺序 - - - 原理 - - 在`a_b_c_index`这样一个联合索引当中, 实质执行中是先查出`a`的结果集, 然后再查`b`或`c`的结果集 - -- 索引的实现原理 - - B+树, 一种特殊的链表, 用来实现二分查找. - -## 如何优化mysql - -- 合理地建立索引 - - - 频繁作为查询条件的字段应该建立索引 - - 唯一性太差的字段不适合单独建立索引 - - 更新非常频繁的字段不适合建立索引 - - 避免不经过索引的操作 - - `not in`, `!=`等反向逻辑 - - `BETWEEN`范围查找 - - `or`逻辑两边都必须命中索引才会走索引 - - 联合索引, 不按左缀查询规则 - -- 加缓存 - - - 数据库缓存 - - ``` - show VARIABLES LIKE '%query_cache%' - ``` - - - 用redis做缓存 - - ``` - 请求 -> redis -> 未命中 -> mysql -> 返回 - ``` - -- 换固态硬盘 - -## 事务 - -- 事务的提交, 回滚 - - ``` - START TRANSACTION; - INSERT INTO store_perf(store_name, amount, department, sta_date) VALUES ('店铺_1764', 753294.41, '事业部_8', '2021-02-05'); - ROLLBACK; - COMMIT; - ``` - -- 业务中使用事务 - - > 将class_2中的同学转移到class_1, 如果SQL_2报错, 会导致class_2中的同学丢失. - - ``` - def transaction(): - try: - SQL = "DELETE FROM class_2 where name='name_13'" - mysql_cursor.execute(SQL) - SQL_2 = "INSERT INTO class_1 VALUES(name)" - mysql_cursor.execute(SQL_2) - - except Exception as e: - print("raise Exceptions", e.args[0]) - print("rollback") - mysql_con.rollback() - finally: - mysql_con.commit() - ``` - -## 课后作业 - -- 练习`pymysql`的使用, 报错单语句执行, 多语句执行, 查询语句, 事务的使用 -- 练习索引的创建 +# 第八周-第三节课 + +## 用python连接数据库 + +- pymysql + + ``` + pip install pymysql + + #如果让你装vs环境, 执行以下命令升级pip即可 + python -m pip install --upgrade pip + ``` + +- 连接数据库 + + - 数据库设置 + + ``` + MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "qwe369", + "db": "test" + } + ``` + + - 连接 + + ``` + # 连接数据库 + mysql_con = pymysql.connect(**MYSQL_CONF) + + # 简单理解真正执行语句的线程 + mysql_cursor = mysql_con.cursor() + ``` + +- 执行SQL语句 + + - 单条执行 + + > 执行时间15.31s + + ``` + @clock_it_deco + def insert_one(): + for i in range(10**4): + store_name = f"店铺_{i}" + amount = format(random.uniform(10**3, 10**6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + + SQL = f"""INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES ('{store_name}', {amount}, '{department}', '{sta_date}')""" + print(SQL) + mysql_cursor.execute(SQL) + + # 显示执行commit, 避免cursor执行, 但是数据库未收到的执行指令的情况 + mysql_con.commit() + ``` + + - 多条执行 + + - 如果其中有一条记录报错, 那么整个values插入都会失败 + + ``` + @clock_it_deco + def insert_many(): + values = [] + for i in range(10**4): + store_name = f"店铺_{i}" + amount = format(random.uniform(10**3, 10**6), '.2f') + department = f"事业部_{random.randint(1, 10)}" + sta_date = time.strftime("%Y-%m-%d") + values.append((store_name, amount, department, sta_date)) + + SQL = """INSERT INTO store_perf(store_name, amount, department, sta_date) + VALUES (%s, %s, %s, %s)""" + print(values) + mysql_cursor.executemany(SQL, values) + mysql_con.commit() + ``` + + - 获取返回值 + + ``` + def get_shops(): + SQL = "select store_name, amount, sta_date from store_perf where department='事业部_1' LIMIT 2" + mysql_cursor.execute(SQL) + # 获取返回值 + query_set = mysql_cursor.fetchall() + print(query_set) + ``` + + - 返回的是一个元组, 元组中表示记录的也是一个元组 + + ``` + (('店铺_1', Decimal('823471.56'), '2021-02-06'), ('店铺_6', Decimal('726927.02'), '2021-02-06')) + ``` + +## 索引和优化 + +- 创建索引 + + > 未建索引: 0.287s + > + > 建了索引后: 0.016s + + - 设置索引的字段不可以超过191个字符长度, 也就是767个bytes + + ``` + CREATE INDEX 索引名 ON 表名(字段1, 字段2...) + + CREATE INDEX store_name_index ON store_perf(store_name) + ``` + +- 创建联合索引 + + ``` + CREATE INDEX store_name_sta_date_department_index ON store_perf(store_name, sta_date, department) + ``` + +- 查看索引 + + ``` + SHOW INDEX FROM store_perf + ``` + +- 删除索引 + + ``` + ALTER TABLE store_perf DROP INDEX store_name_index + ``` + +- 查看当前查询语句有没有命中索引 + + - EXPLAIN语句查看当前语句执行性能 + - 如果key有值, 说明命中了索引, 且key值为索引名 + + ``` + EXPLAIN SELECT * from store_perf WHERE store_name = "店铺_224123" + ``` + +- 单个字段可以命中联合索引吗? + + 联合索引涉及到一个叫`左缀查询`的规则 + + > 如果想命中索引, 查询语句中涉及到字段必须是联合索引创建时从左到右顺序 + + - 原理 + + 在`a_b_c_index`这样一个联合索引当中, 实质执行中是先查出`a`的结果集, 然后再查`b`或`c`的结果集 + +- 索引的实现原理 + + B+树, 一种特殊的链表, 用来实现二分查找. + +## 如何优化mysql + +- 合理地建立索引 + + - 频繁作为查询条件的字段应该建立索引 + - 唯一性太差的字段不适合单独建立索引 + - 更新非常频繁的字段不适合建立索引 + - 避免不经过索引的操作 + - `not in`, `!=`等反向逻辑 + - `BETWEEN`范围查找 + - `or`逻辑两边都必须命中索引才会走索引 + - 联合索引, 不按左缀查询规则 + +- 加缓存 + + - 数据库缓存 + + ``` + show VARIABLES LIKE '%query_cache%' + ``` + + - 用redis做缓存 + + ``` + 请求 -> redis -> 未命中 -> mysql -> 返回 + ``` + +- 换固态硬盘 + +## 事务 + +- 事务的提交, 回滚 + + ``` + START TRANSACTION; + INSERT INTO store_perf(store_name, amount, department, sta_date) VALUES ('店铺_1764', 753294.41, '事业部_8', '2021-02-05'); + ROLLBACK; + COMMIT; + ``` + +- 业务中使用事务 + + > 将class_2中的同学转移到class_1, 如果SQL_2报错, 会导致class_2中的同学丢失. + + ``` + def transaction(): + try: + SQL = "DELETE FROM class_2 where name='name_13'" + mysql_cursor.execute(SQL) + SQL_2 = "INSERT INTO class_1 VALUES(name)" + mysql_cursor.execute(SQL_2) + + except Exception as e: + print("raise Exceptions", e.args[0]) + print("rollback") + mysql_con.rollback() + finally: + mysql_con.commit() + ``` + +## 课后作业 + +- 练习`pymysql`的使用, 报错单语句执行, 多语句执行, 查询语句, 事务的使用 +- 练习索引的创建 - 将索引的内容背诵 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 71a42e80b5cb4615d1de0e7885960e2286fbc313..b0ab7c6170fb519388f2645030e8a61fdb82f8a4 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\253\345\221\250-Mysql\345\237\272\347\241\200(\344\272\214)/\347\254\254\345\205\253\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,126 +1,126 @@ -# 第八周-第二节课 - -## 变量声明 - -- 服务器系统变量 - - - 通过`@@`来调用系统变量 - - ``` - # 列出mysql所有系统变量 - SHOW VARIABLES - SELECT @@date_format - ``` - -- 用户变量 - - - 通过`@`来调用用户变量 - - ``` - # 输出变量yesterday - SELECT @yesterday - - # 对变量yesterday进行赋值 - SET @yesterday=subdate(CURRENT_DATE, 1); - - # 日期的格式化 - SET @yesterday=DATE_FORMAT(@yesterday, "%Y/%m/%d"); - - # 小数的格式化 - SET @amount=0.4; - SET @amount=CAST(@amount as DECIMAL(15, 3)); - SELECT @amount - ``` - -- 局部变量 - - - 不需要`@`前缀 - - 需要事先进行变量类型的声明和初始化 - -## 存储过程 - -简单地认为是`SQL`中的函数 - -- 声明一个存储过程 - - - 创建存储过程 - - - 每一句语句结束之后都要添加分号`;` - - ``` - CREATE PROCEDURE stat_store_perf(days INT) - BEGIN - DECLARE t_date VARCHAR(255); - set t_date = DATE_FORMAT(subdate(CURRENT_DATE, days), '%Y-%m-%d'); - SELECT count(*) as 店铺数, - FORMAT(AVG(amount), 2) as 平均业绩, - SUM(amount) as 总业绩, - MAX(amount) as 最大业绩, - MIN(amount) as 最小业绩, - department as 部门 - FROM store_perf WHERE sta_date=t_date - GROUP BY department; - END - ``` - -- 调用存储过程 - - ``` - CALL stat_store_perf(1) - ``` - -- 删除存储过程 - - ``` - DROP PROCEDURE stat_store_perf - ``` - -## 触发器 - -和存储过程一样, 都是嵌入到`mysql`中的一段程序, 区别就是存储过程需要显式调用, 而触发器式根据对表的相关操作自动激活执行. - -- 创建触发器 - - ``` - CREATE TRIGGER 触发器名 - BEFORE[AFTER] [INSERT, UPDATE, DELETE] - - - CREATE TRIGGER check_department - BEFORE INSERT - ON store_perf - FOR each row - BEGIN - IF new.department not in ("男装事业部", "女装事业部") THEN - SET new.department 'unknow'; - END IF; - END - ``` - -- 触发器的应用 - - 多用来检查字段 - -- 查看触发器 - - > 建议通过客户端删除 - - ``` - SHOW TRIGGERS FROM store_perf - ``` - -- 删除触发器 - - > 建议通过客户端删除 - - ``` - DROP TRIGGERS check_department - ``` - - - -## 课后作业 - -- 重点掌握用户变量, 练习变量的赋值和使用 -- 练习存储过程(能自行完整地写出一个函数) +# 第八周-第二节课 + +## 变量声明 + +- 服务器系统变量 + + - 通过`@@`来调用系统变量 + + ``` + # 列出mysql所有系统变量 + SHOW VARIABLES + SELECT @@date_format + ``` + +- 用户变量 + + - 通过`@`来调用用户变量 + + ``` + # 输出变量yesterday + SELECT @yesterday + + # 对变量yesterday进行赋值 + SET @yesterday=subdate(CURRENT_DATE, 1); + + # 日期的格式化 + SET @yesterday=DATE_FORMAT(@yesterday, "%Y/%m/%d"); + + # 小数的格式化 + SET @amount=0.4; + SET @amount=CAST(@amount as DECIMAL(15, 3)); + SELECT @amount + ``` + +- 局部变量 + + - 不需要`@`前缀 + - 需要事先进行变量类型的声明和初始化 + +## 存储过程 + +简单地认为是`SQL`中的函数 + +- 声明一个存储过程 + + - 创建存储过程 + + - 每一句语句结束之后都要添加分号`;` + + ``` + CREATE PROCEDURE stat_store_perf(days INT) + BEGIN + DECLARE t_date VARCHAR(255); + set t_date = DATE_FORMAT(subdate(CURRENT_DATE, days), '%Y-%m-%d'); + SELECT count(*) as 店铺数, + FORMAT(AVG(amount), 2) as 平均业绩, + SUM(amount) as 总业绩, + MAX(amount) as 最大业绩, + MIN(amount) as 最小业绩, + department as 部门 + FROM store_perf WHERE sta_date=t_date + GROUP BY department; + END + ``` + +- 调用存储过程 + + ``` + CALL stat_store_perf(1) + ``` + +- 删除存储过程 + + ``` + DROP PROCEDURE stat_store_perf + ``` + +## 触发器 + +和存储过程一样, 都是嵌入到`mysql`中的一段程序, 区别就是存储过程需要显式调用, 而触发器式根据对表的相关操作自动激活执行. + +- 创建触发器 + + ``` + CREATE TRIGGER 触发器名 + BEFORE[AFTER] [INSERT, UPDATE, DELETE] + + + CREATE TRIGGER check_department + BEFORE INSERT + ON store_perf + FOR each row + BEGIN + IF new.department not in ("男装事业部", "女装事业部") THEN + SET new.department 'unknow'; + END IF; + END + ``` + +- 触发器的应用 + + 多用来检查字段 + +- 查看触发器 + + > 建议通过客户端删除 + + ``` + SHOW TRIGGERS FROM store_perf + ``` + +- 删除触发器 + + > 建议通过客户端删除 + + ``` + DROP TRIGGERS check_department + ``` + + + +## 课后作业 + +- 重点掌握用户变量, 练习变量的赋值和使用 +- 练习存储过程(能自行完整地写出一个函数) - 练习触发器(只要求操作几次) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index f60fb95dd5d5fadd97aa0a4dc11df53825a4d97a..415cf034e7af44b1a197a7443e06966587acd30b 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,167 +1,167 @@ -# 第六周-第一节课 - -``` -推荐书籍 <<图解TCP/IP>> -``` - -## 输入网址后发生了什么 - -- 输入`url` - - 统一资源定位器`uniform resource locator` - - - `url`组成 - - ``` - https://www.baidu.com/ - 协议://域名[:端口]/路径 - - file:///H:/BaiduNetdiskDownload/ - ``` - - - `url`作用 - - 定位指定的资源. - - > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. - -- DNS解析 - - 域名系统`Domain Name System`, 将域名解析为`IP`地址 - - - 域名解析流程 - - 域名(www.baidu.com) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 - -- 客户端与服务器建立连接. - - 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 - -- 客户端正式向服务端发送请求. - -- 服务端处理请求并返回结果 - -- 浏览器接收到响应后, 做相应的渲染 - -## TCP/IP五层协议 - -``` -https://www.cnblogs.com/xjtu-lyh/p/12416763.html -``` - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223803915-1086885188.png) - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223816759-1375625683.png) - -![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223858705-1259511194.png) - -- 应用层 - - 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. - - ``` - 浏览网页 - 网易云 - 用python模拟请求 - ``` - - - 应用层协议 - - HTTP/HTTPS(超文本传输协议) - - DNS(域名系统) - - FTP(文件传输协议) - - SMTP(邮箱传输协议) - -- 传输层 - - 负责向两个主机应用进程的通信提供服务. - - > 一个主机可以开启不同的因看应用, 同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 - - ``` - 进程 <---> 进程 - ``` - - - 传输层协议 - - - TCP(传输控制协议) - - 提供面向连接, (尽可能)可靠的数据传输服务. - - ``` - 一对一 - ``` - - ``` - 面向连接指的就是, 客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. - ``` - - - 文件传输(FTP) - - 浏览网页(HTTP) - - - UDP(用户数据协议) - - 提供无连接的, 不保证数据传输的可靠性 - - ``` - 一对多, 一对一, 多对多... - ``` - - - 直播 - - 实况游戏 - -- 网络层 - - 决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. - - ``` - 主机 <---> 主机 - ``` - - - 网络层协议 - - - IP协议 - - - 公网IP - - 也就是指的传统IP地址, 是唯一的. - - - 局域网IP - - ``` - ipconfig - ``` - -- 数据链路层 - - 负责两台主机之间的数据传输, 向网路层提供数据传输服务 - - ``` - 网卡 <---> 网卡 - ``` - - - 数据链路层的作用 - - 比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是检错和纠错 - - - *流量控制 - - 差错检测 - - 差错控制 - -- 物理层 - - 物理层再局部局域网上传送数据帧, 在设备节点传输比特流. - - ``` - 光纤 <---> 光纤 - ``` - - - 物理层和数据链路层 - - ``` - 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. - ``` - -## 课后作业 - -- 讲清楚浏览器地址栏敲下`url`发生了什么? +# 第六周-第一节课 + +``` +推荐书籍 <<图解TCP/IP>> +``` + +## 输入网址后发生了什么 + +- 输入`url` + + 统一资源定位器`uniform resource locator` + + - `url`组成 + + ``` + https://www.baidu.com/ + 协议://域名[:端口]/路径 + + file:///H:/BaiduNetdiskDownload/ + ``` + + - `url`作用 + + 定位指定的资源. + + > url是uri的一个子集, uri是唯一标识符的意思. 身份证可以是uri, 但不是url. + +- DNS解析 + + 域名系统`Domain Name System`, 将域名解析为`IP`地址 + + - 域名解析流程 + + 域名(www.baidu.com) -> `DNS`服务器->返回真实的`IP`地址`36.152.44.96:443` -> 通过`IP`地址访问服务器 + +- 客户端与服务器建立连接. + + 客户端和服务端要互相确认身份, 建立连接通道后再发送数据 + +- 客户端正式向服务端发送请求. + +- 服务端处理请求并返回结果 + +- 浏览器接收到响应后, 做相应的渲染 + +## TCP/IP五层协议 + +``` +https://www.cnblogs.com/xjtu-lyh/p/12416763.html +``` + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223803915-1086885188.png) + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223816759-1375625683.png) + +![img](https://img2020.cnblogs.com/blog/1933084/202003/1933084-20200304223858705-1259511194.png) + +- 应用层 + + 为进程(客户端应用)和进程(服务器应用)之间提供服务. 应用层协议定义了应用之间进行数据交互的方式. + + ``` + 浏览网页 + 网易云 + 用python模拟请求 + ``` + + - 应用层协议 + - HTTP/HTTPS(超文本传输协议) + - DNS(域名系统) + - FTP(文件传输协议) + - SMTP(邮箱传输协议) + +- 传输层 + + 负责向两个主机应用进程的通信提供服务. + + > 一个主机可以开启不同的因看应用, 同不同的服务器之间进行通信, 但是都是共用一个传输服务来发送和接受信息 + + ``` + 进程 <---> 进程 + ``` + + - 传输层协议 + + - TCP(传输控制协议) + + 提供面向连接, (尽可能)可靠的数据传输服务. + + ``` + 一对一 + ``` + + ``` + 面向连接指的就是, 客户端和服务端进行三次交互验证, 也就是TCP三次握手. 建立连接后才可以发送数据. + ``` + + - 文件传输(FTP) + - 浏览网页(HTTP) + + - UDP(用户数据协议) + + 提供无连接的, 不保证数据传输的可靠性 + + ``` + 一对多, 一对一, 多对多... + ``` + + - 直播 + - 实况游戏 + +- 网络层 + + 决定了数据的转寄和**路径选择**, 封装和分组运输层产生的报文段/用户数据段. + + ``` + 主机 <---> 主机 + ``` + + - 网络层协议 + + - IP协议 + + - 公网IP + + 也就是指的传统IP地址, 是唯一的. + + - 局域网IP + + ``` + ipconfig + ``` + +- 数据链路层 + + 负责两台主机之间的数据传输, 向网路层提供数据传输服务 + + ``` + 网卡 <---> 网卡 + ``` + + - 数据链路层的作用 + + 比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是检错和纠错 + + - *流量控制 + - 差错检测 + - 差错控制 + +- 物理层 + + 物理层再局部局域网上传送数据帧, 在设备节点传输比特流. + + ``` + 光纤 <---> 光纤 + ``` + + - 物理层和数据链路层 + + ``` + 物理层才是真正传输数据的, 数据链路层是用来检查数据完整性的. + ``` + +## 课后作业 + +- 讲清楚浏览器地址栏敲下`url`发生了什么? - 五层协议有哪五层, 举例说明. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 6c0fa6c6e2a760ff6dcfc501f3c0a8af26c2e3a0..f85ac670898b7e02af797bfbd15526c5b5ce14b1 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,99 +1,99 @@ -# 第六周-第三节课 - -## 抓包 - -抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. - -对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. - -- 抓包软件 - - - Fiddler - - ``` - https://www.telerik.com/fiddler - ``` - - - Charles - - - wireshark - -- web端抓包 - - 现代互联网环境几乎都是https协议的网站 - - - 信任证书 - - ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) - - ``` - TOOLs -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -- App端抓包 - - ``` - 下载夜神模拟器 - ``` - - - 打开远程终端连接 - - ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) - - ``` - Rules -> Options -> Connections -> Allow remote computes to connect - ``` - - - 把手机/模拟器的代理指向fiddler - - ``` - - wifi调出设置的时候要长按 - - 查看当前fiddler所在pc本地局域网ip - - ipconfig/ifconfig - ``` - - 在代理项中填写ip地址和fiddler端口, 默认是8888 - - ``` - - ``` - - - 信任证书 - - - App有一定的反爬措施, 第一件事就是修改请求协议 - - - 双向验证 - - 需要客户端也带上证书 - - - 解决请求协议上的反爬措施 - - - 安装VirtualXposed_0.18.2, JustTrustMe - -## 模拟请求 - -- PostMan简单使用 - - - GET - - - POST - - - form_data - - 参数表单 - - - x-www-form-urlencoded - - 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 - - - raw - - 请求的真实body内容. - -## 课后作业 - -- 学会用fiddler抓包https请求 -- 学会用fiddler抓包手机app中的请求 +# 第六周-第三节课 + +## 抓包 + +抓包其实就是中间人攻击, 只是我们会主动信任像fiddler这样的代理软件. + +对于服务端, 它伪装成客户端. 对于客户端, 它伪装成服务端. + +- 抓包软件 + + - Fiddler + + ``` + https://www.telerik.com/fiddler + ``` + + - Charles + + - wireshark + +- web端抓包 + + 现代互联网环境几乎都是https协议的网站 + + - 信任证书 + + ![Qi3lw.png](https://i.im5i.com/2021/01/23/Qi3lw.png) + + ``` + TOOLs -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +- App端抓包 + + ``` + 下载夜神模拟器 + ``` + + - 打开远程终端连接 + + ![QinkU.png](https://i.im5i.com/2021/01/23/QinkU.png) + + ``` + Rules -> Options -> Connections -> Allow remote computes to connect + ``` + + - 把手机/模拟器的代理指向fiddler + + ``` + - wifi调出设置的时候要长按 + - 查看当前fiddler所在pc本地局域网ip + - ipconfig/ifconfig + ``` + - 在代理项中填写ip地址和fiddler端口, 默认是8888 + + ``` + + ``` + + - 信任证书 + + - App有一定的反爬措施, 第一件事就是修改请求协议 + + - 双向验证 + + 需要客户端也带上证书 + + - 解决请求协议上的反爬措施 + + - 安装VirtualXposed_0.18.2, JustTrustMe + +## 模拟请求 + +- PostMan简单使用 + + - GET + + - POST + + - form_data + + 参数表单 + + - x-www-form-urlencoded + + 如果headers中content-type为`x-www-form-urlencoded`, 那么我们需要在当前选项下填写参数 + + - raw + + 请求的真实body内容. + +## 课后作业 + +- 学会用fiddler抓包https请求 +- 学会用fiddler抓包手机app中的请求 - 学会使用postman模拟GET, POST请求. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 2f07690ea333765534a9a392d797bcb1f42f8f32..2afc6e188edca488da33f68135919c37a9ff2934 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\205\255\345\221\250-\347\275\221\347\273\234\351\200\232\344\277\241/\347\254\254\345\205\255\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,88 +1,88 @@ -# 第六周-第二节课 - -## 理解TCP/IP协议 - -- 什么是TCP/IP协议 - - `TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. - -- TCP/IP的作用 - - 起到了应用和硬件的之间承上启下的作用. - - ``` - 手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 - ``` - -## TCP/IP三次握手 - -为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. - -![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) - -- 三次握手的过程 - - - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 - - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 - - 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 - -- 第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? - - 为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. - -## TCP/IP四次挥手 - -![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) - -- 四次挥手的过程 - - ``` - 我们以客户端作为主动关闭方来描述四次挥手过程 - ``` - - - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 - - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 - - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 - - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 - -## HTTPS - -![](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) - -- https加密的过程 - - 客户端向服务端发送通信请求 - - - 服务端返回给客户端证书和密钥 - - - 客户端通过CA中心验证证书的真实性 - - - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. - - - 非对称加密 - - ``` - 16 = 2* 8 也可以是 4 * 4 - 公钥就是拿到了16这个结果 - 私钥就是某个因数2 - 通过这样的方式才可以得出唯一解8 - ``` - - - 服务端收到加密后的请求数据后, 使用私钥进行解密. - - - 服务器和客户端使用**对称加密**进行通信 - -- 中间人攻击 - - ![](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) - - 插入到客户端和服务端之间的通信, 对服务端伪造客户都安, 对客户端伪造服务端, 拦截通信产生的数据. - - - 产生的条件 - - 我们的客户端要主动信任中间人的证书 - -## 课后作业 - -- 讲述TCP/IP三次握手 -- 讲述TCP/IP四次挥手 +# 第六周-第二节课 + +## 理解TCP/IP协议 + +- 什么是TCP/IP协议 + + `TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. + +- TCP/IP的作用 + + 起到了应用和硬件的之间承上启下的作用. + + ``` + 手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 + ``` + +## TCP/IP三次握手 + +为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. + +![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png) + +- 三次握手的过程 + + - 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 + - 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 + - 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 + +- 第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? + + 为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. + +## TCP/IP四次挥手 + +![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019/7/TCP%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png) + +- 四次挥手的过程 + + ``` + 我们以客户端作为主动关闭方来描述四次挥手过程 + ``` + + - 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 + - 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 + - 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 + - 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 + +## HTTPS + +![](https://pic3.zhimg.com/v2-f0ed37591ced473aaf5b18c1a3e41696_b.jpg) + +- https加密的过程 + - 客户端向服务端发送通信请求 + + - 服务端返回给客户端证书和密钥 + + - 客户端通过CA中心验证证书的真实性 + + - 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. + + - 非对称加密 + + ``` + 16 = 2* 8 也可以是 4 * 4 + 公钥就是拿到了16这个结果 + 私钥就是某个因数2 + 通过这样的方式才可以得出唯一解8 + ``` + + - 服务端收到加密后的请求数据后, 使用私钥进行解密. + + - 服务器和客户端使用**对称加密**进行通信 + +- 中间人攻击 + + ![](https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091151144,717507179&fm=26&gp=0.jpg) + + 插入到客户端和服务端之间的通信, 对服务端伪造客户都安, 对客户端伪造服务端, 拦截通信产生的数据. + + - 产生的条件 + + 我们的客户端要主动信任中间人的证书 + +## 课后作业 + +- 讲述TCP/IP三次握手 +- 讲述TCP/IP四次挥手 - 讲述HTTPS加密的过程 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\344\270\200\345\221\250/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260(\347\254\254\345\215\201\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276).md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\344\270\200\345\221\250/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260(\347\254\254\345\215\201\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276).md" index f969a25586eeb1cee185780c2d06c5c5969da9fc..754babb036662010470b8f651dcc619269444907 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\344\270\200\345\221\250/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260(\347\254\254\345\215\201\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276).md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\344\270\200\345\221\250/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260(\347\254\254\345\215\201\344\270\200\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276).md" @@ -1,229 +1,229 @@ -# 第十周-第三节课 - -## Scrapy的启动和debug - -- 命令行 - - ``` - scrapy crawl jd_search - ``` - -- 启动脚本 - - ``` - # 新建run.py - - from scrapy import cmdline - - command = "scrapy crawl jd_search".split() - cmdline.execute(command) - ``` - -## Scrapy Item - -只是对解析的结构化结果进行一个约束, 在到达pipeline前就可以检查出数据错误. - -## Scrapy的设置 - -- ***ROBOTTEXT_OBEY** - - ``` - ROBOTTEXT_OBEY=False - ``` - - 获取对方网站是否允许爬虫获取数据的信息. - -- **设置中间件** - - 数字越小, 离`ENGINE`越近 - - ``` - DOWNLOADER_MIDDLEWARES = { - # 'jd_crawler_scrapy.middlewares.JdCrawlerScrapyDownloaderMiddleware': 543, - 'jd_crawler_scrapy.middlewares.UAMiddleware': 100, - } - ``` - -- **设置PIPELINE** - - ``` - ITEM_PIPELINES = { - 'jd_crawler_scrapy.pipelines.JdCrawlerScrapyPipeline': 300, - } - ``` - -- 请求限制 - - - ***CONCURRENT_REQUESTS** - - 请求并发数, 通过控制请求并发数达到避免或者延缓IP被封禁 - - ``` - CONCURRENT_REQUESTS = 1 - ``` - - - CONCURRENT_REQUESTS_PER_DOMAIN - - 控制每个`域名`请求的并发数 - - - CONCURRENT_REQUESTS_IP - - 控制每个`IP`请求的次数. 通过这样的方式可以过掉一些对IP封禁严格的网站. - - - CONCURRENT_ITEMS - - 默认为100, 控制处理`item`的并发数. 如果我存入的数据库性能比较差, 通过这样的方式解决防止数据库崩溃的情况. - - - ***DOWNLOAD_DELAY** - - 默认为0, 控制请求的频率. 在调度完一个请求后, 休息若干秒. - - > Scrapy会自动帮我们进行随机休息 (DOWNLOAD_DELAY - 0.5, DOWNLOAD_DELAY + 0.5) - - ``` - DOWNLOAD_DELAY = 2 - ``` - - - ***DOWNLOAD_TIMEOUT** - - 控制每个请求的超时时间. 通过这样的方式解决IP代理池质量差的问题. - - ``` - # 根据自己的IP代理池质量自定决定 - DOWNLOAD_TIMEOUT = 6 - ``` - - - ***REDIRECT_ENABLE** - - 默认为`True`, 建议修改为`False`, 因为大部分情况下, 重定向都是识别出你当前身份有问题, 重定向到`log in`页面 - -- 重试机制 - - - ***RETRY_ENABLE** - - ``` - RETYR_ENABLE = False - ``` - - 默认为`True`, 建议改成`False`, 然后自己重写重试中间件 - - - RETRY_TIMES - - 控制重新次数, RETRY_TIMES其实是当前项目的兜底配置 - - > 如果当前请求失败后永远会重试, 正好你请求的接口是收费的, 万一有一天报错, 那么产生的费用是巨大的. - - ``` - RETRY_TIMES = 3 - ``` - - - RETRY_HTTP_CODES - - ``` - RETRY_HTTP_CODES = [500, 502, 503, 504, 408, 429] - ``` - -- 过滤器 - - - **设置中指定过滤器** - - ``` -DUPEFILTER_CLASS = "jd_crawler_scrapy.middlewares.MyRFPDupeFilter" - ``` - - - **Spider中打开过滤器** - - ``` - yield scrapy.FormRequest( - dont_filter=False, - url=url, - method='GET', - # formdata=data, - callback=self.parse_search - ) - ``` - - - 过滤器 - - ``` - from scrapy.dupefilters import RFPDupeFilter - from w3lib.url import canonicalize_url - from scrapy.utils.python import to_bytes - import hashlib - import weakref - - class MyRFPDupeFilter(RFPDupeFilter): - """ - 过滤器是在到达下载器之前就生成了过滤指纹, 如果我们的下载器中间件报错了, 那么过滤指纹仍然生效, 但是没有实际请求. - 所以我们可以通过一些特殊参数来进行自定义过滤规则 - """ - def request_fingerprint(self, request, include_headers=None, keep_fragments=False): - cache = _fingerprint_cache.setdefault(request, {}) - cache_key = (include_headers, keep_fragments) - if cache_key not in cache: - fp = hashlib.sha1() - fp.update(to_bytes(request.method)) - fp.update(to_bytes(canonicalize_url(request.url, keep_fragments=keep_fragments))) - fp.update(request.body or b'') - fp.update(request.meta.get("batch_no", "").encode("utf-8")) - cache[cache_key] = fp.hexdigest() - return cache[cache_key] - ``` - - - -- LOG - - - LOG_ENABLE - - 默认为`True`, 是否使用log - - - LOG_FILE - - 设置保存的log文件目录 - - - LOG_LEVEL(按严重程序排序) - - - CRITICAL - - ERROR - - WARNING - - INFO - - DEBUG - -## Scrapy的中间件 - -- 请求头中间件 - - ``` - class UAMiddleware: - def process_request(self, request, spider): - request.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - - ``` - -- 重试中间件 - - ``` - from scrapy.downloadermiddlewares.retry import RetryMiddleware - from scrapy.utils.response import response_status_message - - class MyRetryMiddleware(RetryMiddleware): - """ - 解决对方服务器返回正常状态码200, 但是根据IP需要进行验证码验证的情况. - 我们可以通过换IP可以解决验证码, 那么就应该重试. - """ - def process_response(self, request, response, spider): - if request.meta.get('dont_retry', False): - return response - if "验证码" in response.text: - reason = response_status_message(response.status) - return self._retry(request, reason, spider) or response - return response - ``` - -## 课后作业 - -- 将jd_crawler_scrapy完善. -- 完成代理中间件的编写(查阅文档). -- 理解并重写重试中间件 +# 第十周-第三节课 + +## Scrapy的启动和debug + +- 命令行 + + ``` + scrapy crawl jd_search + ``` + +- 启动脚本 + + ``` + # 新建run.py + + from scrapy import cmdline + + command = "scrapy crawl jd_search".split() + cmdline.execute(command) + ``` + +## Scrapy Item + +只是对解析的结构化结果进行一个约束, 在到达pipeline前就可以检查出数据错误. + +## Scrapy的设置 + +- ***ROBOTTEXT_OBEY** + + ``` + ROBOTTEXT_OBEY=False + ``` + + 获取对方网站是否允许爬虫获取数据的信息. + +- **设置中间件** + + 数字越小, 离`ENGINE`越近 + + ``` + DOWNLOADER_MIDDLEWARES = { + # 'jd_crawler_scrapy.middlewares.JdCrawlerScrapyDownloaderMiddleware': 543, + 'jd_crawler_scrapy.middlewares.UAMiddleware': 100, + } + ``` + +- **设置PIPELINE** + + ``` + ITEM_PIPELINES = { + 'jd_crawler_scrapy.pipelines.JdCrawlerScrapyPipeline': 300, + } + ``` + +- 请求限制 + + - ***CONCURRENT_REQUESTS** + + 请求并发数, 通过控制请求并发数达到避免或者延缓IP被封禁 + + ``` + CONCURRENT_REQUESTS = 1 + ``` + + - CONCURRENT_REQUESTS_PER_DOMAIN + + 控制每个`域名`请求的并发数 + + - CONCURRENT_REQUESTS_IP + + 控制每个`IP`请求的次数. 通过这样的方式可以过掉一些对IP封禁严格的网站. + + - CONCURRENT_ITEMS + + 默认为100, 控制处理`item`的并发数. 如果我存入的数据库性能比较差, 通过这样的方式解决防止数据库崩溃的情况. + + - ***DOWNLOAD_DELAY** + + 默认为0, 控制请求的频率. 在调度完一个请求后, 休息若干秒. + + > Scrapy会自动帮我们进行随机休息 (DOWNLOAD_DELAY - 0.5, DOWNLOAD_DELAY + 0.5) + + ``` + DOWNLOAD_DELAY = 2 + ``` + + - ***DOWNLOAD_TIMEOUT** + + 控制每个请求的超时时间. 通过这样的方式解决IP代理池质量差的问题. + + ``` + # 根据自己的IP代理池质量自定决定 + DOWNLOAD_TIMEOUT = 6 + ``` + + - ***REDIRECT_ENABLE** + + 默认为`True`, 建议修改为`False`, 因为大部分情况下, 重定向都是识别出你当前身份有问题, 重定向到`log in`页面 + +- 重试机制 + + - ***RETRY_ENABLE** + + ``` + RETYR_ENABLE = False + ``` + + 默认为`True`, 建议改成`False`, 然后自己重写重试中间件 + + - RETRY_TIMES + + 控制重新次数, RETRY_TIMES其实是当前项目的兜底配置 + + > 如果当前请求失败后永远会重试, 正好你请求的接口是收费的, 万一有一天报错, 那么产生的费用是巨大的. + + ``` + RETRY_TIMES = 3 + ``` + + - RETRY_HTTP_CODES + + ``` + RETRY_HTTP_CODES = [500, 502, 503, 504, 408, 429] + ``` + +- 过滤器 + + - **设置中指定过滤器** + + ``` +DUPEFILTER_CLASS = "jd_crawler_scrapy.middlewares.MyRFPDupeFilter" + ``` + + - **Spider中打开过滤器** + + ``` + yield scrapy.FormRequest( + dont_filter=False, + url=url, + method='GET', + # formdata=data, + callback=self.parse_search + ) + ``` + + - 过滤器 + + ``` + from scrapy.dupefilters import RFPDupeFilter + from w3lib.url import canonicalize_url + from scrapy.utils.python import to_bytes + import hashlib + import weakref + + class MyRFPDupeFilter(RFPDupeFilter): + """ + 过滤器是在到达下载器之前就生成了过滤指纹, 如果我们的下载器中间件报错了, 那么过滤指纹仍然生效, 但是没有实际请求. + 所以我们可以通过一些特殊参数来进行自定义过滤规则 + """ + def request_fingerprint(self, request, include_headers=None, keep_fragments=False): + cache = _fingerprint_cache.setdefault(request, {}) + cache_key = (include_headers, keep_fragments) + if cache_key not in cache: + fp = hashlib.sha1() + fp.update(to_bytes(request.method)) + fp.update(to_bytes(canonicalize_url(request.url, keep_fragments=keep_fragments))) + fp.update(request.body or b'') + fp.update(request.meta.get("batch_no", "").encode("utf-8")) + cache[cache_key] = fp.hexdigest() + return cache[cache_key] + ``` + + + +- LOG + + - LOG_ENABLE + + 默认为`True`, 是否使用log + + - LOG_FILE + + 设置保存的log文件目录 + + - LOG_LEVEL(按严重程序排序) + + - CRITICAL + - ERROR + - WARNING + - INFO + - DEBUG + +## Scrapy的中间件 + +- 请求头中间件 + + ``` + class UAMiddleware: + def process_request(self, request, spider): + request.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + + ``` + +- 重试中间件 + + ``` + from scrapy.downloadermiddlewares.retry import RetryMiddleware + from scrapy.utils.response import response_status_message + + class MyRetryMiddleware(RetryMiddleware): + """ + 解决对方服务器返回正常状态码200, 但是根据IP需要进行验证码验证的情况. + 我们可以通过换IP可以解决验证码, 那么就应该重试. + """ + def process_response(self, request, response, spider): + if request.meta.get('dont_retry', False): + return response + if "验证码" in response.text: + reason = response_status_message(response.status) + return self._retry(request, reason, spider) or response + return response + ``` + +## 课后作业 + +- 将jd_crawler_scrapy完善. +- 完成代理中间件的编写(查阅文档). +- 理解并重写重试中间件 - 理解并重写过滤器 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 9b7bfdc03381f8b9018a880e7db86999eb7cace3..672f56cf34ff006179d3103e01f12ad908ee6f4b 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,112 +1,112 @@ -## 第十周-第一节课 - -## 路径管理 - -### 路径 - -- 绝对路径 - - 总是从根目录开始 - - ``` - H:\PyCharmProjects\tutorials_2\jd_crawler\main.py - ``` - -- 相对路径 - - ``` - jd_crawler\main.py - ``` - - - `.`和`..` - - `.`代表当前目录, `..`代表父目录 - -- 工作目录 - - 当前执行命令所在的目录 - - ``` - # 将工作目录添加进当前的路径列表 - sys.path.append(os.getcwd()) - ``` - -### 路径列表 - -- 查看当前路径列表 - - 只有在路径列表当中的包和模块才可以导入和调用 - - ``` - import sys - print(sys.path) - ``` - -- 路径搜索顺序 - - - 当前脚本路径, 也就是执行文件的目录 - - `PYTHONPATH`路径 - - 虚拟环境路径 - - `site-packages` - - 安装的第三方库所在路径 - -- 可以向路径列表添加路径 - - ``` - sys.path.append(r"H:\PyCharmProjects\tutorials_2") - ``` - -## 常见报错 - -- `ModuleNotFoundError: No module named 'xxxx'` - - - 为什么在pycharm中不报错, 在命令行当中报错 - - ``` - Pycharm会自动将当前项目的根目录添加到路径列表当中 - ``` - -- `ModuleNotFoundError: No module named 'parser.search'; 'parser' is not a pac - kage` - - - 自定义包和内置包名有冲突 - - 修改包名即可 - - - 导入的不是一个包 - -- `ModuleNotFoundError: No module named '__main__.jd_parser'; '__main__' is no - t a package` - - - **入口程序不可以使用相对路径** - - - `__main__` - - 主程序模块名会被修改为`__main__` - -- `ValueError: attempted relative import beyond top-level package` - - 当前访问路径已经超过了python已知的最大路径 - - ``` - from tutorial_2.jd_crawler.jd_parser.search import parse_jd_item - - top-level package 指的是上述from导入命令中的首路径tutorial_2, 而不是根据目录结构 - ``` - - - 把工作目录加入到路径列表当中 - - 进入到项目根目录下执行命令 - - 上述两个操作相当于将项目根目录加入到路径列表当中 - -## 注意事项 - -- 确定入口程序, 没有一个锚定的路径就没有办法做相对路径的管理 -- 将项目根目录加入到入口程序当中 -- 进入到项目根目录下执行命令 -- 项目目录结构不要嵌套的太深 -- 脚本文件或者临时运行单个模块中的方法, 可以将根目录临时添加到**路径列表**当中 - -## 课后作业 - -- 用命令行启动`jd_crawler` +## 第十周-第一节课 + +## 路径管理 + +### 路径 + +- 绝对路径 + + 总是从根目录开始 + + ``` + H:\PyCharmProjects\tutorials_2\jd_crawler\main.py + ``` + +- 相对路径 + + ``` + jd_crawler\main.py + ``` + + - `.`和`..` + + `.`代表当前目录, `..`代表父目录 + +- 工作目录 + + 当前执行命令所在的目录 + + ``` + # 将工作目录添加进当前的路径列表 + sys.path.append(os.getcwd()) + ``` + +### 路径列表 + +- 查看当前路径列表 + + 只有在路径列表当中的包和模块才可以导入和调用 + + ``` + import sys + print(sys.path) + ``` + +- 路径搜索顺序 + + - 当前脚本路径, 也就是执行文件的目录 + - `PYTHONPATH`路径 + - 虚拟环境路径 + - `site-packages` + - 安装的第三方库所在路径 + +- 可以向路径列表添加路径 + + ``` + sys.path.append(r"H:\PyCharmProjects\tutorials_2") + ``` + +## 常见报错 + +- `ModuleNotFoundError: No module named 'xxxx'` + + - 为什么在pycharm中不报错, 在命令行当中报错 + + ``` + Pycharm会自动将当前项目的根目录添加到路径列表当中 + ``` + +- `ModuleNotFoundError: No module named 'parser.search'; 'parser' is not a pac + kage` + + - 自定义包和内置包名有冲突 + + 修改包名即可 + + - 导入的不是一个包 + +- `ModuleNotFoundError: No module named '__main__.jd_parser'; '__main__' is no + t a package` + + - **入口程序不可以使用相对路径** + + - `__main__` + + 主程序模块名会被修改为`__main__` + +- `ValueError: attempted relative import beyond top-level package` + + 当前访问路径已经超过了python已知的最大路径 + + ``` + from tutorial_2.jd_crawler.jd_parser.search import parse_jd_item + + top-level package 指的是上述from导入命令中的首路径tutorial_2, 而不是根据目录结构 + ``` + + - 把工作目录加入到路径列表当中 + - 进入到项目根目录下执行命令 + - 上述两个操作相当于将项目根目录加入到路径列表当中 + +## 注意事项 + +- 确定入口程序, 没有一个锚定的路径就没有办法做相对路径的管理 +- 将项目根目录加入到入口程序当中 +- 进入到项目根目录下执行命令 +- 项目目录结构不要嵌套的太深 +- 脚本文件或者临时运行单个模块中的方法, 可以将根目录临时添加到**路径列表**当中 + +## 课后作业 + +- 用命令行启动`jd_crawler` - 在`/test`目录中增加`parser_test.py`模块做解析测试. \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index bd301b2734e7b15dd89cdf54d2b1b4054f72cc9c..8fefe4dd316c701e9afbff78c5c07cc38b997565 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,83 +1,83 @@ -# 第十周-第三节课 - -## Scrapy的启动和debug - -- 命令行 - - ``` - scrapy crawl jd_search - ``` - -- 启动脚本 - - ``` - # 新建run.py - - from scrapy import cmdline - - command = "scrapy crawl jd_search".split() - cmdline.execute(command) - ``` - -## Scrapy Item - -只是对解析的结构化结果进行一个约束, 在到达pipeline前就可以检查出数据错误. - -## Scrapy的设置 - -- ROBOTTEXT_OBEY - - 获取对方网站是否允许爬虫获取数据的信息. - -- 设置中间件 - - 数字越小, 离`ENGINE`越近 - - ``` - DOWNLOADER_MIDDLEWARES = { - # 'jd_crawler_scrapy.middlewares.JdCrawlerScrapyDownloaderMiddleware': 543, - 'jd_crawler_scrapy.middlewares.UAMiddleware': 100, - } - ``` - -- 设置PIPELINE - - ``` - ITEM_PIPELINES = { - 'jd_crawler_scrapy.pipelines.JdCrawlerScrapyPipeline': 300, - } - ``` - -- LOG - - - LOG_ENABLE - - 默认为`True`, 是否使用log - - - LOG_FILE - - 设置保存的log文件目录 - - - LOG_LEVEL(按严重程序排序) - - - CRITICAL - - ERROR - - WARNING - - INFO - - DEBUG - -## Scrapy的中间件 - -- 请求头中间件 - - ``` - class UAMiddleware: - def process_request(self, request, spider): - request.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" - - ``` - -## 课后作业 - -- 将jd_crawler_scrapy完善. +# 第十周-第三节课 + +## Scrapy的启动和debug + +- 命令行 + + ``` + scrapy crawl jd_search + ``` + +- 启动脚本 + + ``` + # 新建run.py + + from scrapy import cmdline + + command = "scrapy crawl jd_search".split() + cmdline.execute(command) + ``` + +## Scrapy Item + +只是对解析的结构化结果进行一个约束, 在到达pipeline前就可以检查出数据错误. + +## Scrapy的设置 + +- ROBOTTEXT_OBEY + + 获取对方网站是否允许爬虫获取数据的信息. + +- 设置中间件 + + 数字越小, 离`ENGINE`越近 + + ``` + DOWNLOADER_MIDDLEWARES = { + # 'jd_crawler_scrapy.middlewares.JdCrawlerScrapyDownloaderMiddleware': 543, + 'jd_crawler_scrapy.middlewares.UAMiddleware': 100, + } + ``` + +- 设置PIPELINE + + ``` + ITEM_PIPELINES = { + 'jd_crawler_scrapy.pipelines.JdCrawlerScrapyPipeline': 300, + } + ``` + +- LOG + + - LOG_ENABLE + + 默认为`True`, 是否使用log + + - LOG_FILE + + 设置保存的log文件目录 + + - LOG_LEVEL(按严重程序排序) + + - CRITICAL + - ERROR + - WARNING + - INFO + - DEBUG + +## Scrapy的中间件 + +- 请求头中间件 + + ``` + class UAMiddleware: + def process_request(self, request, spider): + request.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" + + ``` + +## 课后作业 + +- 将jd_crawler_scrapy完善. - 完成代理中间件的编写(查阅文档). \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 2628bf4c1d14f40b7495574c1809d34aeca98e15..db4b0430c9c912b48f6dfdb49cae87ccc18b725d 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\215\201\345\221\250-scrapy\351\241\271\347\233\256/\347\254\254\345\215\201\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,125 +1,125 @@ -# 第十周-第二节课 - -## Scrapy爬虫框架介绍 - -- 文档 - - - [英文文档](https://docs.scrapy.org/en/latest/) - - [中文文档](https://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.html) - -- 什么是scrapy - - 基于`twisted`搭建的异步爬虫框架. - - scrapy爬虫框架根据组件化设计理念和丰富的中间件, 使其成为了一个兼具高性能和高扩展的框架 - -- scrapy提供的主要功能 - - - **具有优先级功能的调度器** - - **去重功能** - - 失败后的重试机制 - - 并发限制 - - ip使用次数限制 - - .... - -- scrapy的使用场景 - - - 不适合scrapy项目的场景 - - 业务非常简单, 对性能要求也没有那么高, 那么我们写多进程, 多线程, 异步脚本即可. - - 业务非常复杂, 请求之间有顺序和失效时间的限制. - - **如果你不遵守框架的主要设计理念, 那就不要使用框架** - - 适合使用scrapy项目 - - 数据量大, 对性能有一定要求, 又需要用到**去重功能**和**优先级功能的调度器** - -- **scrapy组件** - - ![](https://docs.scrapy.org/en/latest/_images/scrapy_architecture_02.png) - - `ENGINE`从`SPIDERS`中获取初始请求任务`Requests` - - `ENGINE`得到`Requests`之后发送给`SCHEDULER`, `SCHEDULER`对请求进行调度后产出任务. - - `Scheduler`返回下一个请求任务给`ENGINE` - - `ENGINE`将请求任务交给`DOWNLOADER`去完成下载任务, 途径下载器中间件. - - 一旦下载器完成请求任务, 将产生一个`Response`对象给`ENGINE`, 途径下载器中间件 - - `ENGINE`收到`Response`对象后, 将该对象发送给`SPIDERS`去解析和处理, 途径爬虫中间件 - - `SPIDER`解析返回结果 - - 将解析结果`ITEMS`发送给`ENGINE` - - 生成一个新的`REQUESTS`任务发送给`ENGINE` - - 如果`ENGINE`拿到的是`ITEMS`, 那么就会发送给`ITEM PIPELINES`做数据处理, 如果是`REQUESTS`则发送给`SCHEDULER` - - 周而复始, 直到没有任务产出 - -## Scrapy教程 - -- 安装 - - ``` - pip install scrapy - ``` - -- 创建项目 - - ``` - scrapy startproject jd_crawler_scrapy - ``` - -- 目录结构 - - - spiders(目录) - - 存放`SPIDERS`项目文件, 一个scrapy项目下可以有多个爬虫实例 - - - items - - 解析后的结构化结果. - - - middlewares - - 下载器中间件和爬虫中间件的地方 - - - piplines - - 处理items的组件, 一般都在pipelines中完成items插入数据表的操作 - - - settings - - 统一化的全局爬虫配置文件 - - - scrapy.cfg - - 项目配置文件 - -- scrapy爬虫demo - - ``` - import scrapy - - - class JdSearch(scrapy.Spider): - name = "jd_search" - - def start_requests(self): - for keyword in ["鼠标", "键盘", "显卡", "耳机"]: - for page_num in range(1, 11): - url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" - - # 选用FormRequest是因为它既可以发送GET请求, 又可以发送POST请求 - yield scrapy.FormRequest( - url=url, - method='GET', - # formdata=data, # 如果是post请求, 携带数据使用formdata参数 - callback=self.parse_search # 指定回调函数处理response对象 - ) - - - def parse_search(self, response): - print(response) - ``` - -- 启动爬虫 - - ``` - scrapy crawl spider_name - ``` - -## 课后作业 - -- 背诵`scrapy`组件流程(必考) +# 第十周-第二节课 + +## Scrapy爬虫框架介绍 + +- 文档 + + - [英文文档](https://docs.scrapy.org/en/latest/) + - [中文文档](https://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.html) + +- 什么是scrapy + + 基于`twisted`搭建的异步爬虫框架. + + scrapy爬虫框架根据组件化设计理念和丰富的中间件, 使其成为了一个兼具高性能和高扩展的框架 + +- scrapy提供的主要功能 + + - **具有优先级功能的调度器** + - **去重功能** + - 失败后的重试机制 + - 并发限制 + - ip使用次数限制 + - .... + +- scrapy的使用场景 + + - 不适合scrapy项目的场景 + - 业务非常简单, 对性能要求也没有那么高, 那么我们写多进程, 多线程, 异步脚本即可. + - 业务非常复杂, 请求之间有顺序和失效时间的限制. + - **如果你不遵守框架的主要设计理念, 那就不要使用框架** + - 适合使用scrapy项目 + - 数据量大, 对性能有一定要求, 又需要用到**去重功能**和**优先级功能的调度器** + +- **scrapy组件** + + ![](https://docs.scrapy.org/en/latest/_images/scrapy_architecture_02.png) + - `ENGINE`从`SPIDERS`中获取初始请求任务`Requests` + - `ENGINE`得到`Requests`之后发送给`SCHEDULER`, `SCHEDULER`对请求进行调度后产出任务. + - `Scheduler`返回下一个请求任务给`ENGINE` + - `ENGINE`将请求任务交给`DOWNLOADER`去完成下载任务, 途径下载器中间件. + - 一旦下载器完成请求任务, 将产生一个`Response`对象给`ENGINE`, 途径下载器中间件 + - `ENGINE`收到`Response`对象后, 将该对象发送给`SPIDERS`去解析和处理, 途径爬虫中间件 + - `SPIDER`解析返回结果 + - 将解析结果`ITEMS`发送给`ENGINE` + - 生成一个新的`REQUESTS`任务发送给`ENGINE` + - 如果`ENGINE`拿到的是`ITEMS`, 那么就会发送给`ITEM PIPELINES`做数据处理, 如果是`REQUESTS`则发送给`SCHEDULER` + - 周而复始, 直到没有任务产出 + +## Scrapy教程 + +- 安装 + + ``` + pip install scrapy + ``` + +- 创建项目 + + ``` + scrapy startproject jd_crawler_scrapy + ``` + +- 目录结构 + + - spiders(目录) + + 存放`SPIDERS`项目文件, 一个scrapy项目下可以有多个爬虫实例 + + - items + + 解析后的结构化结果. + + - middlewares + + 下载器中间件和爬虫中间件的地方 + + - piplines + + 处理items的组件, 一般都在pipelines中完成items插入数据表的操作 + + - settings + + 统一化的全局爬虫配置文件 + + - scrapy.cfg + + 项目配置文件 + +- scrapy爬虫demo + + ``` + import scrapy + + + class JdSearch(scrapy.Spider): + name = "jd_search" + + def start_requests(self): + for keyword in ["鼠标", "键盘", "显卡", "耳机"]: + for page_num in range(1, 11): + url = f"https://search.jd.com/Search?keyword={keyword}&page={page_num}" + + # 选用FormRequest是因为它既可以发送GET请求, 又可以发送POST请求 + yield scrapy.FormRequest( + url=url, + method='GET', + # formdata=data, # 如果是post请求, 携带数据使用formdata参数 + callback=self.parse_search # 指定回调函数处理response对象 + ) + + + def parse_search(self, response): + print(response) + ``` + +- 启动爬虫 + + ``` + scrapy crawl spider_name + ``` + +## 课后作业 + +- 背诵`scrapy`组件流程(必考) - 完成scrapy项目的demo \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 25e2ed513c99767978e2d3739c219e4d9be07890..e7f339aca9e29d3777e33fdfc08f301a1951546b 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,157 +1,157 @@ -# 第四周-第一节课 - -## 导入第三方模块 - -- 导包的层级关系 - - - 模块(module) - - 以文件为载体, 包含各类对象 - - - 包(package) - - 以文件夹为载体, 包含了各类模块 - - - 库(lib) - - 包含了各类包 - -- `import 库` - -- `from 库/模块 import 模块/函数` - -- 导包的命名冲突 - - 通过`as`这个关键词来给当前模块/函数取个别名 - - ``` - from datetime import datetime as p_datetime - ``` - -## 时间模块time - -调用的都是系统级的接口, 提供时间的访问和转换的功能 - -- 查看时间 - - - 获取当前时间 - - ``` - # 有时区的 - time.localtime() - - 返回的是一个time.struct_time对象 - ``` - - - 时间戳 - - ``` - time.time() - ``` - - - 时间的格式化输出 - - ``` - now = time.localtime() - now = time.strftime("%Y-%m-%d %H:%M:%S", now) - print(now) - - # 可以省略时间对象 - now = time.strftime("%Y-%m-%d %H:%M:%S") - ``` - - - 运算 - - 将时间对象转换为`list`, 对相应的时间重新赋值后, 通过`time.struct_time`生成一个新的时间对象 - - ``` - time_list = list(time.localtime()) - time_list[2] = 4 - time.struct_time(time_list) - ``` - - - 时间休眠 - - 当前程序休眠n秒 - - ``` - time.sleep(3) - ``` - -## 时间模块datetime - -封装了time, 提供了更高级和更友好的接口 - -- 查看时间 - - ``` - # 获取计算机时间, 返回的是一个datetime.datime对象 - datetime.datetime.today() - - - # 获取指定时区的时间 - datetime.datetime.now(tz=None) - - # 获取utc时间 - datetime.datetime.utcnow() - ``` - -- 时间格式的转换 - - - `datetime.datetime` -> `str` - - ``` - now = datetime.datetime.now(tz=None) - now.strftime("%Y-%m-%d %H:%M:%S") - ``` - - - `str` -> `datetime.datetime` - - ``` - >>> now - '2021-01-03 23:38:26' - >>> datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S") - datetime.datetime(2021, 1, 3, 23, 38, 26) - ``` - - - `datetime.datetime` -> `timestamp` - - ``` - >>> now - datetime.datetime(2021, 1, 3, 23, 40, 45, 749240) - >>> now.timestamp() - 1609688445.74924 - ``` - - - `timestamp` -> `datetime.datetime` - - ``` - >>> ts - 1609688445.74924 - >>> datetime.datetime.fromtimestamp(ts, tz=None) - datetime.datetime(2021, 1, 3, 23, 40, 45, 749240) - ``` - -- 时间运算 - - - `timedelta` - - 只作用于`datetime.datetime`格式 - - ``` - # 选中目标模块 ctrl+B / command+B 跳转到模块源码 - def __new__(cls, days=0, seconds=0, microseconds=0, - milliseconds=0, minutes=0, hours=0, weeks=0): - ``` - - ``` - >>> from datetime import timedelta - >>> now + timedelta(hours=-1) - datetime.datetime(2021, 1, 3, 22, 40, 45, 749240) - ``` - -## 课后作业 - -- 通过`datetime`模块完成时间戳, `datetime.datetime`对象, 格式化字符串三者之间的转换 -- 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期`2020-01-02`. - +# 第四周-第一节课 + +## 导入第三方模块 + +- 导包的层级关系 + + - 模块(module) + + 以文件为载体, 包含各类对象 + + - 包(package) + + 以文件夹为载体, 包含了各类模块 + + - 库(lib) + + 包含了各类包 + +- `import 库` + +- `from 库/模块 import 模块/函数` + +- 导包的命名冲突 + + 通过`as`这个关键词来给当前模块/函数取个别名 + + ``` + from datetime import datetime as p_datetime + ``` + +## 时间模块time + +调用的都是系统级的接口, 提供时间的访问和转换的功能 + +- 查看时间 + + - 获取当前时间 + + ``` + # 有时区的 + time.localtime() + + 返回的是一个time.struct_time对象 + ``` + + - 时间戳 + + ``` + time.time() + ``` + + - 时间的格式化输出 + + ``` + now = time.localtime() + now = time.strftime("%Y-%m-%d %H:%M:%S", now) + print(now) + + # 可以省略时间对象 + now = time.strftime("%Y-%m-%d %H:%M:%S") + ``` + + - 运算 + + 将时间对象转换为`list`, 对相应的时间重新赋值后, 通过`time.struct_time`生成一个新的时间对象 + + ``` + time_list = list(time.localtime()) + time_list[2] = 4 + time.struct_time(time_list) + ``` + + - 时间休眠 + + 当前程序休眠n秒 + + ``` + time.sleep(3) + ``` + +## 时间模块datetime + +封装了time, 提供了更高级和更友好的接口 + +- 查看时间 + + ``` + # 获取计算机时间, 返回的是一个datetime.datime对象 + datetime.datetime.today() + + + # 获取指定时区的时间 + datetime.datetime.now(tz=None) + + # 获取utc时间 + datetime.datetime.utcnow() + ``` + +- 时间格式的转换 + + - `datetime.datetime` -> `str` + + ``` + now = datetime.datetime.now(tz=None) + now.strftime("%Y-%m-%d %H:%M:%S") + ``` + + - `str` -> `datetime.datetime` + + ``` + >>> now + '2021-01-03 23:38:26' + >>> datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S") + datetime.datetime(2021, 1, 3, 23, 38, 26) + ``` + + - `datetime.datetime` -> `timestamp` + + ``` + >>> now + datetime.datetime(2021, 1, 3, 23, 40, 45, 749240) + >>> now.timestamp() + 1609688445.74924 + ``` + + - `timestamp` -> `datetime.datetime` + + ``` + >>> ts + 1609688445.74924 + >>> datetime.datetime.fromtimestamp(ts, tz=None) + datetime.datetime(2021, 1, 3, 23, 40, 45, 749240) + ``` + +- 时间运算 + + - `timedelta` + + 只作用于`datetime.datetime`格式 + + ``` + # 选中目标模块 ctrl+B / command+B 跳转到模块源码 + def __new__(cls, days=0, seconds=0, microseconds=0, + milliseconds=0, minutes=0, hours=0, weeks=0): + ``` + + ``` + >>> from datetime import timedelta + >>> now + timedelta(hours=-1) + datetime.datetime(2021, 1, 3, 22, 40, 45, 749240) + ``` + +## 课后作业 + +- 通过`datetime`模块完成时间戳, `datetime.datetime`对象, 格式化字符串三者之间的转换 +- 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期`2020-01-02`. + diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index b2fc40a86bc9362bbd6731def8b55f712cae3713..ba3ac59f881cc8b760b9e3846f2ca210adaf08d1 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,176 +1,176 @@ -# 第四周-第三节课 - -## 类属性和实例属性 - -- 类属性 - - - 通过类对象可以直接访问的属性 - - - 抽象概念的固有属性, 要考虑当前抽象概念的普适性 - - ``` - # 贴标签不是一个特别好的抽象, 原因他没有一个普适性 - class Developer: - programing_language = None - busy = True - ``` - - - 私有属性 - - 不希望外部更改, 只作用于类内部 - - - 通过`__变量名`来声明私有属性 - - ``` - class Lottery: - __items = ["mac", "ipad", "iphone"] - ``` - - - 通过`类._类名__变量名`来访问私有属性 - - ``` - print(Lottery._Lottery__items) - ``` - -- 实例属性 - - - 绑定在实例上的属性, 只能通过**该实例**进行访问 - - - 实例的自有属性 - - ``` - class Developer: - programing_language = None - busy = True - __case = "doing something" - - d_python = Developer() - d_python.programing_language = "python" - d_java = Developer() - d_java.programing_language = "java" - - print(d_java.programing_language) - print(d_python.programing_language) - ``` - - - 私有属性 - - 通过`self.__变量名`来声明私有属性 - - 通过`实例._类名__变量名`来访问私有属性 - -## 类方法, 静态方法, 实例方法 - -- 类方法 - - - 仅供类调用的方法 - - - 通过`classmethod`装饰器来声明一个类方法 - - - 自定义类创建 - - ``` - class Developer: - programing_language = None - busy = True - __case = "doing something" - def __init__(self, hairs): - self.__hairs = hairs - - @classmethod - def __new__(cls, *args, **kwargs): - print("init class") - return super().__new__(cls) - - @classmethod - def get_case(cls): - return cls.__case - ``` - -- 静态方法 - - - 类可以直接调用的方法 - - - 通过`staticmethod`装饰器装饰 - - - 对一类抽象行为的归类 - - ``` - class MyMath: - - @staticmethod - def add(a, b): - return a + b - ``` - -- 实例方法 - - - 仅供实例调用的方法 - -## 接口, 协议和抽象基类 - -- 接口 - - 对象公开方法的子集, 让对象在系统中扮演特定的角色. - - ``` - list实现了增删改查的接口, 只要有一个接口没有实现那就不属于list - tuple只提供了查的接口 - ``` - -- 协议 - - 非正式的接口, 协议与继承没有关系, 一个类可能会实现多个接口, 从而让实例扮演多个角色 - - ``` - list扮演者列表的角色, 但同时也是一个序列, 序列并不是一个实体类. - ``` - - - 协议的应用 - - ``` - class MyDict(dict): - def __iadd__(self, other): - self.update(other) - return self - - def __str__(self): - return f"My Dict {self.items()}" - ``` - -- 抽象基类 - - 把客观事物封装成抽象的元类, 区分概念和实现. - - - 只要有`@abc.abstractmethod`装饰器的类就是抽象基类 - - ``` - import abc - class Mixin: - def sign(self): - pass - - def rank(self): - pass - - class Gamer: - @abc.abstractmethod - def sign(self): - pass - - - class GoGamer(Mixin, Gamer): - pass - - class Swimmer(Mixin, Gamer): - pass - ``` - -## 课后作业 - -- 将之前封装的`MyMath`类中的实例方法改为静态方法, 体会两者的区别. -- 为上节课自定义类添加以下功能: - - 添加类属性 - - 添加类私有属性 - - 添加类方法或者类的私有属性 - - 在`__init__`方法中初始化实例属性 - - 在`__init__`方法中绑定私有实例属性 +# 第四周-第三节课 + +## 类属性和实例属性 + +- 类属性 + + - 通过类对象可以直接访问的属性 + + - 抽象概念的固有属性, 要考虑当前抽象概念的普适性 + + ``` + # 贴标签不是一个特别好的抽象, 原因他没有一个普适性 + class Developer: + programing_language = None + busy = True + ``` + + - 私有属性 + + 不希望外部更改, 只作用于类内部 + + - 通过`__变量名`来声明私有属性 + + ``` + class Lottery: + __items = ["mac", "ipad", "iphone"] + ``` + + - 通过`类._类名__变量名`来访问私有属性 + + ``` + print(Lottery._Lottery__items) + ``` + +- 实例属性 + + - 绑定在实例上的属性, 只能通过**该实例**进行访问 + + - 实例的自有属性 + + ``` + class Developer: + programing_language = None + busy = True + __case = "doing something" + + d_python = Developer() + d_python.programing_language = "python" + d_java = Developer() + d_java.programing_language = "java" + + print(d_java.programing_language) + print(d_python.programing_language) + ``` + + - 私有属性 + - 通过`self.__变量名`来声明私有属性 + - 通过`实例._类名__变量名`来访问私有属性 + +## 类方法, 静态方法, 实例方法 + +- 类方法 + + - 仅供类调用的方法 + + - 通过`classmethod`装饰器来声明一个类方法 + + - 自定义类创建 + + ``` + class Developer: + programing_language = None + busy = True + __case = "doing something" + def __init__(self, hairs): + self.__hairs = hairs + + @classmethod + def __new__(cls, *args, **kwargs): + print("init class") + return super().__new__(cls) + + @classmethod + def get_case(cls): + return cls.__case + ``` + +- 静态方法 + + - 类可以直接调用的方法 + + - 通过`staticmethod`装饰器装饰 + + - 对一类抽象行为的归类 + + ``` + class MyMath: + + @staticmethod + def add(a, b): + return a + b + ``` + +- 实例方法 + + - 仅供实例调用的方法 + +## 接口, 协议和抽象基类 + +- 接口 + + 对象公开方法的子集, 让对象在系统中扮演特定的角色. + + ``` + list实现了增删改查的接口, 只要有一个接口没有实现那就不属于list + tuple只提供了查的接口 + ``` + +- 协议 + + 非正式的接口, 协议与继承没有关系, 一个类可能会实现多个接口, 从而让实例扮演多个角色 + + ``` + list扮演者列表的角色, 但同时也是一个序列, 序列并不是一个实体类. + ``` + + - 协议的应用 + + ``` + class MyDict(dict): + def __iadd__(self, other): + self.update(other) + return self + + def __str__(self): + return f"My Dict {self.items()}" + ``` + +- 抽象基类 + + 把客观事物封装成抽象的元类, 区分概念和实现. + + - 只要有`@abc.abstractmethod`装饰器的类就是抽象基类 + + ``` + import abc + class Mixin: + def sign(self): + pass + + def rank(self): + pass + + class Gamer: + @abc.abstractmethod + def sign(self): + pass + + + class GoGamer(Mixin, Gamer): + pass + + class Swimmer(Mixin, Gamer): + pass + ``` + +## 课后作业 + +- 将之前封装的`MyMath`类中的实例方法改为静态方法, 体会两者的区别. +- 为上节课自定义类添加以下功能: + - 添加类属性 + - 添加类私有属性 + - 添加类方法或者类的私有属性 + - 在`__init__`方法中初始化实例属性 + - 在`__init__`方法中绑定私有实例属性 - 在自定义类中实现`__str__`, 自定义输出格式 \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" index 59805effc72f94e00e9d6fc86f5304d73743bc4d..6797ae1c45d31cd06a59f2a46e9a7082cfa9ce72 100644 --- "a/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" +++ "b/\347\254\254\344\272\214\346\234\237\351\232\217\345\240\202\347\254\224\350\256\260/\347\254\254\345\233\233\345\221\250-\347\261\273\344\270\216\351\235\242\345\220\221\345\257\271\350\261\241/\347\254\254\345\233\233\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276-\351\232\217\345\240\202\347\254\224\350\256\260.md" @@ -1,170 +1,170 @@ -# 第四周-第二节课 - -## 类的创建, 实例化, 初始化 - -- 什么是类 - - 类就是拥有相同功能或者相同属性的对象集合 - -- 类的创建 - - - `object`是所有类的基类 - - ``` - class GoGamer(object): - subject = 'go' - - print(GoGamer) - ``` - -- 类的实例化 - - 实例就是抽象概念的具象化 - - ``` - kejie = GoGamer() - print(kejie) - ``` - -- 类的初始化 - - 类创建一个新实例的时候会默认调用`__init__`这样一个特殊方法 - - ``` - class GoGamer(object): - subject = 'go' - def __init__(self, obj): - self.p = obj - - kejie = GoGamer("金勺子") - print(f"柯洁含着{kejie.p}出生") - ``` - - - 关于`self` - - 指代还未实例化的实例 - -## 面向对象 - -- 面向过程 - - - `程序=数据结构+算法` - - 强调的是一个实现的细节 - -- 面向对象 - - 完成对越来越庞大项目代码以及对外公开接口的归类和重用, 是一种更高级的抽象. - - - 通过什么手段来完成上述目的? - - - 继承 - - ``` - class ChineseGoGamer(GoGamer): - nation = 'cn' - - class KoreaGoGamer(GoGamer): - nation = 'kr' - ``` - - - 处理多继承冲突 - - - 查看`MRO(mehotd resolution order)` - - ``` - class A: - def __init__(self): - print("init A") - - class B: - def __init__(self): - print("init B") - - - class C(A, B): - pass - - print(C.__mro__) - ``` - - - 指定类方法的调用顺序 - - ``` - class C(A, B): - def __init__(self): - super(A, self).__init__() - ``` - - - `super`函数源码 - - ``` - def super(cls, inst): - mro = inst.__class__.mro() - return mro[mro.index(cls) + 1] - - def super(类, 实例): - # 获取当前实例的方法解析顺序 - mro = 实例.类.mro() - return mro[mro.index(类) + 1] - ``` - - - 多态 - - 方式为覆盖和重载 - - - 覆盖(子类和父类之间的, 是垂直的关系) - - 子类可以继承父类的所有属性和方法, 但是同时子类也可以重写父类的属性和方法, 达到自定义的目的. - - ``` - class A: - def __init__(self): - print("init A") - - class B: - def __init__(self): - print("init B") - - - class C(A, B): - def __init__(self): - print("init C") - ``` - - - 重载(类中的方法和方法之间的, 是水平关系) - - Python中式没有重载, 但是可以用装饰器来实现该功能. - - - 封装 - - 把客观事物封装成抽象的类, 隐藏实现细节, 使得代码模块化. - -## 课后作业 - -- 用类封装一个`MyMath`类, 实现加, 减, 乘, 除, 幂, 开方 - - ``` - class MyMath: - def add(self, a, b): - return a + b - .... - ``` - -- 自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 - - ``` - 例: - class Book: - content - def __init__(self, sig): - self.sig = sig - ``` - -- 创建多个继承作业2父类的子类 - - ``` - class ToolBook(Book): - pass - ``` - +# 第四周-第二节课 + +## 类的创建, 实例化, 初始化 + +- 什么是类 + + 类就是拥有相同功能或者相同属性的对象集合 + +- 类的创建 + + - `object`是所有类的基类 + + ``` + class GoGamer(object): + subject = 'go' + + print(GoGamer) + ``` + +- 类的实例化 + + 实例就是抽象概念的具象化 + + ``` + kejie = GoGamer() + print(kejie) + ``` + +- 类的初始化 + + 类创建一个新实例的时候会默认调用`__init__`这样一个特殊方法 + + ``` + class GoGamer(object): + subject = 'go' + def __init__(self, obj): + self.p = obj + + kejie = GoGamer("金勺子") + print(f"柯洁含着{kejie.p}出生") + ``` + + - 关于`self` + + 指代还未实例化的实例 + +## 面向对象 + +- 面向过程 + + - `程序=数据结构+算法` + - 强调的是一个实现的细节 + +- 面向对象 + + 完成对越来越庞大项目代码以及对外公开接口的归类和重用, 是一种更高级的抽象. + + - 通过什么手段来完成上述目的? + + - 继承 + + ``` + class ChineseGoGamer(GoGamer): + nation = 'cn' + + class KoreaGoGamer(GoGamer): + nation = 'kr' + ``` + + - 处理多继承冲突 + + - 查看`MRO(mehotd resolution order)` + + ``` + class A: + def __init__(self): + print("init A") + + class B: + def __init__(self): + print("init B") + + + class C(A, B): + pass + + print(C.__mro__) + ``` + + - 指定类方法的调用顺序 + + ``` + class C(A, B): + def __init__(self): + super(A, self).__init__() + ``` + + - `super`函数源码 + + ``` + def super(cls, inst): + mro = inst.__class__.mro() + return mro[mro.index(cls) + 1] + + def super(类, 实例): + # 获取当前实例的方法解析顺序 + mro = 实例.类.mro() + return mro[mro.index(类) + 1] + ``` + + - 多态 + + 方式为覆盖和重载 + + - 覆盖(子类和父类之间的, 是垂直的关系) + + 子类可以继承父类的所有属性和方法, 但是同时子类也可以重写父类的属性和方法, 达到自定义的目的. + + ``` + class A: + def __init__(self): + print("init A") + + class B: + def __init__(self): + print("init B") + + + class C(A, B): + def __init__(self): + print("init C") + ``` + + - 重载(类中的方法和方法之间的, 是水平关系) + + Python中式没有重载, 但是可以用装饰器来实现该功能. + + - 封装 + + 把客观事物封装成抽象的类, 隐藏实现细节, 使得代码模块化. + +## 课后作业 + +- 用类封装一个`MyMath`类, 实现加, 减, 乘, 除, 幂, 开方 + + ``` + class MyMath: + def add(self, a, b): + return a + b + .... + ``` + +- 自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例 + + ``` + 例: + class Book: + content + def __init__(self, sig): + self.sig = sig + ``` + +- 创建多个继承作业2父类的子类 + + ``` + class ToolBook(Book): + pass + ``` + \ No newline at end of file