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文件夹里 - -[](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文件夹里 + +[](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 -``` - - - - - - - -### 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 +``` + + + + + + + +### 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`连接, 尽可能地保证数据传输的正确性. -> - - - -### 1.三次握手的过程 - -- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 -- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 -- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 - -### 2.第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? - -为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. - -## 三.TCP/IP四次挥手 - - - -### 1.四次挥手的过程 - -``` -我们以客户端作为主动关闭方来描述四次挥手过程 -``` - -- 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 -- 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 -- 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 -- 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 - -## 四.HTTPS - - - -### 1.https加密的过程 - -- 客户端向服务端发送通信请求 - -- 服务端返回给客户端证书和密钥 - -- 客户端通过CA中心验证证书的真实性 - -- 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. - - - 非对称加密 - - ``` - 16 = 2* 8 也可以是 4 * 4 - 公钥就是拿到了16这个结果 - 私钥就是某个因数2 - 通过这样的方式才可以得出唯一解8 - ``` - -- 服务端收到加密后的请求数据后, 使用私钥进行解密. - -- 服务器和客户端使用**对称加密**进行通信 - -### 2.中间人攻击 - - - -插入到客户端和服务端之间的通信, 对服务端伪造客户端, 对客户端伪造服务端, 拦截通信产生的数据. - -- 产生的条件 - - 我们的客户端要主动信任中间人的证书 - -## 五.课后作业 - -- 讲述TCP/IP三次握手 -- 讲述TCP/IP四次挥手 +# 第六周-第二节课-TCP和IP + +## 一.理解TCP/IP协议 + +### 1.什么是TCP/IP协议 + +`TCP/IP`并不是单个协议, 而是指一组协议的集合, 所以`TCP/IP`也叫`TCP/IP`协议族. + +### 2.TCP/IP的作用 + +起到了应用和硬件的之间承上启下的作用. + +``` +手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网 +``` + +## 二.TCP/IP三次握手 + +> 目的:为了建立可靠的`TCP`连接, 尽可能地保证数据传输的正确性. +> + + + +### 1.三次握手的过程 + +- 客户端向服务端发送带有`SYN(同步序列编号)`标识的数据包 --------------------------服务端确认了客户端的发送能力正常 +- 服务端向客户端发送了带有`SYN-ACK(确认字符)`标识的数据包-----------------------服务端确认了自己接受能力是正常 +- 客户端向服务端返回带有`ACK`标识的数据包-----------------------------------------------服务端确认了自己发送能力, 客户端接受正常 + +### 2.第2次握手已经传回了`ACK`, 为什么服务端还要返回`SYN`? + +为了告诉客户端, 接收到的信号确实是其发送的信号, 表明了客户端到服务端的通信是正常的. + +## 三.TCP/IP四次挥手 + + + +### 1.四次挥手的过程 + +``` +我们以客户端作为主动关闭方来描述四次挥手过程 +``` + +- 客户端向服务端发送了一个`FIN(finish)`数据包-------------------------------------关闭客户端到服务端的连接通道 +- 服务端收到`FIN`后, 返回了`ACK`数据包----------------------------------------------------服务端已经知道了客户端到服务端的连接通道已关闭 +- 服务端发送`FIN`数据包至客户端, 关闭与客户端的连接------------------------------目的是关闭服务端到客户端的连接通道 +- 客户端返回`ACK`数据包确认------------------------------------------------------------------通知服务端客户端已经知道了服务端到客户端之间的连接通道已关闭 + +## 四.HTTPS + + + +### 1.https加密的过程 + +- 客户端向服务端发送通信请求 + +- 服务端返回给客户端证书和密钥 + +- 客户端通过CA中心验证证书的真实性 + +- 客户端完成认证之后, 使用公钥对发送数据进行加密, 发送给服务端. + + - 非对称加密 + + ``` + 16 = 2* 8 也可以是 4 * 4 + 公钥就是拿到了16这个结果 + 私钥就是某个因数2 + 通过这样的方式才可以得出唯一解8 + ``` + +- 服务端收到加密后的请求数据后, 使用私钥进行解密. + +- 服务器和客户端使用**对称加密**进行通信 + +### 2.中间人攻击 + + + +插入到客户端和服务端之间的通信, 对服务端伪造客户端, 对客户端伪造服务端, 拦截通信产生的数据. + +- 产生的条件 + + 我们的客户端要主动信任中间人的证书 + +## 五.课后作业 + +- 讲述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协议的网站 -> - -- 信任证书 - -  - - ``` - Rules -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -### 3. App端抓包 - -``` -下载夜神模拟器 -``` - -- 打开远程终端连接 - -  - - ``` -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协议的网站 +> + +- 信任证书 + +  + + ``` + Rules -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +### 3. App端抓包 + +``` +下载夜神模拟器 +``` + +- 打开远程终端连接 + +  + + ``` +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录入信息 -- 常用的运算符及常用函数练习 - - - +- 通过navicat建表, 包含当前常用的数据类型. +- 通过INSERT录入信息 +- 常用的运算符及常用函数练习 + + +  \ 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操作 + + + +### 练习集合操作 + +- 并集 + +  + +- 交集 + +  + +- 差集 + +  + +- 补集 + +  + 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协议的网站 - - - 信任证书 - -  - - ``` - Rules -> Options -> HTTPS - - 勾选Decrypt HTTPS traffic - - 右上角点击Actions - - Trust Root Certificates - ``` - -- App端抓包 - - ``` - 下载夜神模拟器 - ``` - - - 打开远程终端连接 - -  - - ``` - 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协议的网站 + + - 信任证书 + +  + + ``` + Rules -> Options -> HTTPS + - 勾选Decrypt HTTPS traffic + - 右上角点击Actions + - Trust Root Certificates + ``` + +- App端抓包 + + ``` + 下载夜神模拟器 + ``` + + - 打开远程终端连接 + +  + + ``` + 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 - - - - - - - - - 罗技(G) - - - - - - - 罗技(Logitech) - - - - - - - 雷蛇(Razer) - - - - - - - 联想(lenovo) - - - - - - - 雷柏(Rapoo) - - - - - - - 达尔优 - - - - - - - 双飞燕(A4TECH) - - - - - - - 惠普(HP) - - - - - - - 微软(Microsoft) - - - - - - - 赛睿(SteelSeries) - - - - - - - 戴尔(DELL) - - - - - - - 英菲克(INPHIC) - - - - - - - 小米(MI) - - - - - - - ROG - - - - - - - ThinkPad - - - - - - - 飞利浦(PHILIPS ) - - - - - - - 外星人(Alienware) - - - - - - - 雷神(ThundeRobot) - - - - - - - 前行者(EWEADN) - - - - - - - 华为(HUAWEI) - - - - - - - 狼蛛(AULA) - - - - - - - 华硕(ASUS) - - - - - - 牧马人 - - - - - - - 多彩(Delux) - - - - - - - 微星(MSI) - - - - - - - 科大讯飞(iFLYTEK) - - - - - - - 冰豹 - - - - - - - 机械师(MACHENIKE) - - - - - - - ZOWIE GEAR - - - - - - 玩家国度(ROG) - - - - - - - 灵蛇 - - - - - - 罗技(logitech) - - - - - - - 黑爵(AJAZZ) - - - - - - - 美商海盗船(USCORSAIR) - - - - - - - 洛斐(LOFREE) - - - - - - 蝰蛇(VIPERADE) - - - - - - - SANWA SUPPLY - - - - - - - 宏碁(acer) - - - - - - - 沃野 - - - - - - - CHERRY - - - - - - - 新贵(Newmen) - - - - - - - Xtrfy - - - - - - - 金士顿(Kingston) - - - - - - - 宜丽客(ELECOM) - - - - - - - 富勒(Fuhlen) - - - - - - 因科特 - - - - - - - AKKO - - - - - - 吉选(GESOBYTE) - - - - - - 3Dconnexion - - - - - - 银雕(YINDIAO) - - - - - - - 麦塔奇(Microtouch) - - - - - - 迪摩 - - - - - - - 本手 - - - - - - - 富德 - - - - - - 狼界 - - - - - - - 爱国者(aigo) - - - - - - - 新盟(TECHNOLOGY) - - - - - - - MAD CATZ - - - - - - 普泽罗 - - - - - - - 现代(HYUNDAI) - - - - - - - ThinkPlus - - - - - - - Apple - - - - - - 肯辛通(Kensington) - - - - - - 库肯(KUKEN) - - - - - - 森松尼(sunsonny) - - - - - - - BUBM - - - - - - - 火银狐 - - - - - - - 烽火狼 - - - - - - 余音 - - - - - - - 磁动力(ZIDLI) - - - - - - - 游狼 - - - - - - 钛度 - - - - - - - 现代翼蛇 - - - - - - - 蝰蛇(KUISHE) - - - - - - - 咪鼠科技(Mimouse) - - - - - - - ENDGAME GEAR - - - - - - - 得力(deli) - - - - - - - 冰狐 - - - - - - 掌握者 - - - - - - - JRC - - - - - - - 虎符电竞(ESPORTS TIGER) - - - - - - Dear Mean - - - - - - 斗鱼(DOUYU.COM) - - - - - - - 贝戋马户(james donkey) - - - - - - - AOC - - - - - - - 摩天手(Mofii) - - - - - - - 追光豹 - - - - - - - 方正科技(ifound) - - - - - - - 京东京造 - - - - - - - 酷冷至尊(CoolerMaster) - - - - - - - perixx - - - - - - - RK - - - - - - - 独牙(DUYA) - - - - - - ET - - - - - - 惊雷 - - - - - - - 技嘉(GIGABYTE) - - - - - - 印象笔记 - - - - - - - 科普斯 - - - - - - 腹灵(FL·ESPORTS) - - - - - - 猛豹 - - - - - - - HYPERX - - - - - - QQfamily - - - - - - 虹龙 - - - - - - - MIIIW - - - - - - - 炫光 - - - - - - 米徒(ME TOO) - - - - - - 快鼠(FAST MOUSE) - - - - - - GYSFONE - - - - - - 纳卓者(NAZZHE) - - - - - - 力胜 - - - - - - - B.O.W - - - - - - - 摩豹(Motospeed) - - - - - - - 雷宝龙 - - - - - - - 赛德斯 - - - - - - - glorious - - - - - - bejoy - - - - - - - imiia - - - - - - MageGee - - - - - - - 雷迪凯(LDK.al) - - - - - - ONIKUMA - - - - - - 朗森 - - - - - - SOZA - - - - - - - 太空步(Monwalk) - - - - - - - 摩肯 - - - - - - - 喵王 - - - - - - - 耐也(Niye) - - - - - - - ikbc - - - - - - 因科特(ironcat) - - - - - - Leoisilence - - - - - - - 京烁 - - - - - - 剑圣一族 - - - - - - - 汉王(Hanvon) - - - - - - - uFound - - - - - - - 黑峡谷(Hyeku) - - - - - - - 极速射貂(GSEdo) - - - - - - 慕正 - - - - - - - 虹PAD(hongpad) - - - - - - 轻帆 - - - - - - 狼派(teamwolf) - - - - - - - 德意龙(BORN IN WAR) - - - - - - - SWIFTPOINT - - - - - - 品怡 - - - - - - 东来也 - - - - - - - 卡佐(AZZOR) - - - - - - - 倍晶(BestJing) - - - - - - - 龙涛 - - - - - - 游猎者 - - - - - - - 虎猫 - - - - - - Matcheasy - - - - - - - 狼途(Langtu) - - - - - - - e元素 - - - - - - - 梦田(MVTV) - - - - - - 雷狼 - - - - - - 全球翻译官 - - - - - - HIXANNY - - - - - - - 魔炼者(MAGIC-REFINER) - - - - - - 相思豆 - - - - - - 敏涛 - - - - - - FirstBlood - - - - - - - 长城(Great Wall) - - - - - - 邦兴晖 - - - - - - 菲沐(FAMOR) - - - - - - - 赤灵 - - - - - - - 初忆(CHUYI) - - - - - - - 讯拓(Sunt) - - - - - - - 酷倍达(QPAD ) - - - - - - - 荣耀(HONOR) - - - - - - CCA - - - - - - - 银雕(yindiao) - - - - - - - DCOMA - - - - - - - 酷今(COOLTODAY) - - - - - - - oloey - - - - - - - 酷米索(KUMISUO) - - - - - - POLIGU - - - - - - 全语通 - - - - - - 精晟小太阳 - - - - - - 罗品贡技 - - - - - - - HUKE - - - - - - 黑吉蛇 - - - - - - 汉钦 - - - - - - - 泰格斯(TARGUS) - - - - - - 微森 - - - - - - - 迪士尼(Disney) - - - - - - - 不梵 - - - - - - - 西伯利亚(XIBERIA) - - - - - - - 乐帆(LeFanT) - - - - - - 佳晟丰(JIA SHENG FENG) - - - - - - - QMXD - - - - - - 艾丝恺 - - - - - - - 飞遁(LESAILES) - - - - - - - 带带 - - - - - - 力拓 - - - - - - - 拼搏者 - - - - - - 漫呗熊 - - - - - - DURGOD - - - - - - Darmoshark - - - - - - - 果瀚 - - - - - - 鹧鸪鸟(CHUKAR) - - - - - - 黑沙(HEISHA) - - - - - - - 索尼(SONY) - - - - - - - 虎克 - - - - - - - 镭拓(Rantopad) - - - - - - 玲魅 - - - - - - - 京天(KOTIN) - - - - - - WGJCE - - - - - - 昇欧 - - - - - - LIMEIDE - - - - - - FVYESH - - - - - - - 神舟(HASEE) - - - - - - 秋拓 - - - - - - - 攀升(IPASON) - - - - - - 帝伊工坊 - - - - - - - 暗杀星 - - - - - - - AZIO - - - - - - - i-rocks - - - - - - - 宁美(NINGMEI) - - - - - - - 零度世家 - - - - - - - 海尔(Haier) - - - - - - - B.FRIENDit - - - - - - 驰顾 - - - - - - 蝙蝠骑士(Batknight) - - - - - - 梵超 - - - - - - 百馨味 - - - - - - - AJIUYU - - - - - - 易科星 - - - - - - - HOBBYBOX - - - - - - - 墨一(MOYi) - - - - - - 良雫 - - - - - - 爵蝎(JUEXIE) - - - - - - 雷腾 - - - - - - 逆狼 - - - - - - - F.L - - - - - - 自由狼(ZIYOU LANG) - - - - - - 威润祺 - - - - - - LUOKASI - - - - - - - 维恩克 - - - - - - - a豆(adol) - - - - - - 轻松熊 - - - - - - - 乾竡客 - - - - - - - 脉歌(Macaw) - - - - - - - 纽曼(Newmine) - - - - - - 罗姿 - - - - - - EGGUEA - - - - - - 心汐 - - - - - - BULUO - - - - - - Facroo - - - - - - - 锦读(JINDU) - - - - - - 极米熊 - - - - - - 冰雷 - - - - - - 时代节点(ERA NODE) - - - - - - - 纯彩(purecolor) - - - - - - 三侠 - - - - - - - 研龙 - - - - - - isoojo - - - - - - 素咫(sozvr) - - - - - - 首爵 - - - - - - - 优派(ViewSonic) - - - - - - - 西部猎人(VV.HUNTER) - - - - - - - 绿巨能(llano) - - - - - - 越飞传 - - - - - - - 概力 - - - - - - - 优想 - - - - - - - 科乐多(KELEDUO) - - - - - - - 金正(NINTAUS) - - - - - - - 桑瑞得(Sunreed) - - - - - - 鑫片 - - - - - - - 京炼 - - - - - - HAWOES - - - - - - - 骨伽(COUGAR) - - - - - - - JETech Design - - - - - - 越俊云商 - - - - - - 龙吐珠(LONGTUZHU) - - - - - - 京臣 - - - - - - - 亮朵(LIGHTDOT) - - - - - - - 火影 - - - - - - 狄普(DiePuo) - - - - - - - RK ROYAL KLUDGE - - - - - - 顾胜 - - - - - - - 小袋鼠(XIAO DAI SHU) - - - - - - 咔咔鱼(KAKAY) - - - - - - - 倍方 - - - - - - 鹿为 - - - - - - - 米力 - - - - - - - NVV - - - - - - Corsair - - - - - - - GANSS - - - - - - - 绿联(UGREEN) - - - - - - 酷奇(cooskin) - - - - - - HHKB - - - - - - 炽魂(Blasoul) - - - - - - 金米诺(JINMINUO) - - - - - - 优微客 - - - - - - 梵特科(FANTECH) - - - - - - 蓝盛(LENTION) - - - - - - 升派(ESPL) - - - - - - - 金陵声宝 - - - - - - - 机械革命(MECHREVO) - - - - - - - 格玛斯(gemasi) - - - - - - 徕声(AUGLAMOUR) - - - - - - - 一龙通金 - - - - - - - 跆威(Tai wei) - - - - - - - 英望 - - - - - - - 派凡(oatsbasf) - - - - - - 苹果(Apple) - - - - - - - 信蓝铭 - - - - - - - 洋典(YANGDIAN) - - - - - - - 橙朗 - - - - - - - JINCOMSO - - - - - - - 尼凡(Nifan) - - - - - - - 宜适酷(EXCO) - - - - - - 力鎂(LIMEIDE) - - - - - - - 镇魂歌 - - - - - - 嘻他 - - - - - - 韵果 - - - - - - 无尘谷 - - - - - - 宛丝希 - - - - - - - 优本配 - - - - - - 梦叶夕(Mengyexi) - - - - - - Repair Your Life - - - - - - 御密达(YUMIDA) - - - - - - 津浆 - - - - - - - 菲尼拉(phylina) - - - - - - CINQUS - - - - - - 景萦忻 - - - - - - 素拓(SUTUO) - - - - - - - 酷嬷 - - - - - - - 阿米洛(Varmilo) - - - - - - 迷铭乐 - - - - - - - 久宇 - - - - - - - 武极 - - - - - - 索能(SUONENG) - - - - - - 九科星 - - - - - - - OFH - - - - - - 尚本 - - - - - - 安麦威 - - - - - - 云里游(YUNLIYOU) - - - - - - - 斯泰克(stiger) - - - - - - 美克杰 - - - - - - 暴狼客 - - - - - - - 彩膜坊 - - - - - - - 未来人类(Terrans Force) - - - - - - 七品 - - - - - - 古風 - - - - - - 机械师 - - - - - - 雷真 - - - - - - Dukotod - - - - - - - 酷元素(KUYUANSU) - - - - - - - 天威(PrintRite) - - - - - - 木丁丁 - - - - - - 海琴烟 - - - - - - 吉润星 - - - - - - - 元迈 - - - - - - wkuk - - - - - - - Kolinsky - - - - - - - KH - - - - - - - lianqi - - - - - - YWVFDR - - - - - - - 广群达 - - - - - - - Bonks - - - - - - 万人迷(manovo) - - - - - - 尚·雅 - - - - - - 硬豹 - - - - - - 雅诺仕(ANOCE) - - - - - - - RS - - - - - - - 十八渡 - - - - - - 薰之沓 - - - - - - - 京俏 - - - - - - 游戏狂人(GAME MADMAN) - - - - - - - 凯迪威 - - - - - - - HRHPYM - - - - - - 佐凡 - - - - - - - 宜客莱(ECOLA) - - - - - - - 艾拍宝(iPazzPort) - - - - - - 尚雅 - - - - - - - 妖禄(Fairy Gift) - - - - - - 摩加(Mojia) - - - - - - 橡儿 - - - - - - - AWKICI - - - - - - - 小米有品 - - - - - - - 埃普(UP) - - - - - - - 3M - - - - - - 云派(witsp@d) - - - - - - AYALEY - - - - - - 胖牛 - - - - - - 米物(MIIIW) - - - - - - - 酷蛇(COOLSNAKE) - - - - - - 画尚(halsanr) - - - - - - 同福茂 - - - - - - - 黑狼(Black Wolf) - - - - - - SEIHOO - - - - - - - LOMAZOO - - - - - - 鳗而登 - - - - - - - 名龙堂(MLOONG) - - - - - - - 安尚(ACTTO) - - - - - - 纯孩子 - - - - - - - 江铭 - - - - - - SU·YOSD - - - - - - - 维豹 - - - - - - 小熊堂 - - - - - - MOYOGV - - - - - - 岑鑫 - - - - - - - 花朶 - - - - - - 希讯(HOPECENT) - - - - - - 欢乐投 - - - - - - - 通优派 - - - - - - 衡文(HENGWEN) - - - - - - 捣旦国度 - - - - - - - 奥睿科(ORICO) - - - - - - 耀胜(YAOSHENG) - - - - - - - 特兰恩(Tralean) - - - - - - - 典元(DIANYUAN) - - - - - - - 瀚沪(HANHU) - - - - - - - 悦利(richblue) - - - - - - - 丽博尔(liboer) - - - - - - 纽赛(NUSIGN) - - - - - - 德普(DEEP) - - - - - - 硕臣 - - - - - - 布谷鸟 - - - - - - MC - - - - - - 简之 - - - - - - Keating Berus - - - - - - - 莫哥斯(MAGUS) - - - - - - BURJUMAN - - - - - - luvlee - - - - - - 妙手回潮 - - - - - - TELAYMUS - - - - - - 荔新 - - - - - - - 博米迦(BMIEGA) - - - - - - - 鑫喆 - - - - - - - 福鹿(FULU) - - - - - - 助率(ZHULV) - - - - - - EVESKY - - - - - - - 京选 - - - - - - - 逸祺 - - - - - - 北海巨妖(GiiarKraken) - - - - - - - 晶华 - - - - - - - 南极人(Nanjiren) - - - - - - - 俞兆林(YUZHAOLIN) - - - - - - 迪舒(DISHU) - - - - - - - 优联(Youlian) - - - - - - - 金霸王 - - - - - - - 胜为(shengwei) - - - - - - - 毕亚兹(BIAZE) - - - - - - - Borsu - - - - - - - 七彩虹(Colorful) - - - - - - 巴迈尔 - - - - - - 领臣(LINGCHEN) - - - - - - - 第九城(V.NINE) - - - - - - - KOVOL - - - - - - 科立讯 - - - - - - - Anskp - - - - - - - 南孚 - - - - - - - 滴露(Dettol) - - - - - 已选条件: - - 确定 - 取消 - - - - 更多 - 多选 - - - - - - 外设产品: - - - - - - 鼠标 - - - - 键盘 - - - - 鼠标垫 - - - - 线缆 - - - - 手写板 - - - - 电脑清洁 - - - - 移动固态硬盘 - - - - - 确定 - 取消 - - - - 更多 - 多选 - - - - - - - 电脑整机: - - - - - - 笔记本配件 - - - - 平板电脑配件 - - - - 特殊商品 - - - - 平板电脑 - - - - 台式机 - - - - 游戏本 - - - - 笔记本 - - - - 服务器/工作站 - - - - - 确定 - 取消 - - - - 更多 - 多选 - - - - - - - 连接方式: - - - - - 无线 - - - 有线 - - - 蓝牙 - - - 多模 - - - 其他 - - - - - 确定 - 取消 - - - - 更多 - 多选 - - - - - - 适用场景: - - - - - 游戏 - - - 办公 - - - - - 确定 - 取消 - - - - 更多 - 多选 - - - - - - 高级选项: - - - - 产品类型 - 尺寸 - 游戏性能 - 背光效果 - 特点 - 类型 - 数字键盘 - 轴体类型 - 轴体品牌 - 类别 - 其他分类 - - - - - - - - - 静音鼠标 - - - 充电鼠标 - - - 便携鼠标 - - - 轨迹球 - - - 演示器 - - - 多选 - - - 确定 - 取消 - - - - - - - 100mm-120mm - - - 小于100mm - - - 121mm-130mm - - - 大于130mm - - - 多选 - - - 确定 - 取消 - - - - - - - 入门级 - - - 发烧级 - - - 骨灰级 - - - 多选 - - - 确定 - 取消 - - - - - - - RGB - - - 单光 - - - 混光 - - - 无光 - - - 多选 - - - 确定 - 取消 - - - - - - - 磨砂材质 - - - 类肤材质 - - - 镜面材质 - - - 左手适用型 - - - 其他 - - - 多选 - - - 确定 - 取消 - - - - - - - 机械键盘 - - - 键鼠套装 - - - 数字键盘 - - - 超薄键盘 - - - 薄膜键盘 - - - 个性定制键盘 - - - 静电容键盘 - - - 键盘配件 - - - 其他 - - - 多选 - - - 确定 - 取消 - - - - - - - 有数字键盘 - - - 无数字键盘 - - - 多选 - - - 确定 - 取消 - - - - - - - 青轴 - - - 红轴 - - - 光轴 - - - 茶轴 - - - 黑轴 - - - 其他 - - - 多选 - - - 确定 - 取消 - - - - - - - 其他轴 - - - 樱桃轴 - - - 欧姆龙轴 - - - 凯华轴 - - - 自有轴 - - - 多选 - - - 确定 - 取消 - - - - - - - 手提电脑包 - - - 双肩电脑包 - - - 单肩电脑包 - - - 创意配件 - - - 其他 - - - 多选 - - - 确定 - 取消 - - - - - - - 二手装机配件 - - - 二手硬盘 - - - 户外照明 - - - 旅行装备 - - - 二手笔记本配件 - - - 二手台式机 - - - 二手笔记本 - - - 二手平板电脑配件 - - - 二手一体机 - - - 电脑包 - - - 旅行配件 - - - 保暖防护 - - - 电池/充电器 - - - 二手游戏周边 - - - 办公文具 - - - 电脑桌 - - - 升降桌 - - - 特殊商品 - - - 养生器械 - - - 家庭护理 - - - 护腕 - - - 收纳袋/包 - - - 分隔收纳 - - - 收纳箱 - - - 投影配件 - - - 白板 - - - 收银机 - - - 二手路由器 - - - 二手网络机顶盒 - - - 二手网络配件 - - - 创意礼品 - - - 工艺礼品 - - - 显卡 - - - 装机配件 - - - 特殊商品 - - - 取暖器 - - - 卡通周边 - - - 二手智能家居 - - - 车载支架 - - - 车身装饰件 - - - 导航/中控膜 - - - 层架/置物架 - - - 二手经管图书 - - - 二手计算机图书 - - - 二手期刊杂志 - - - 按摩器 - - - 家用五金 - - - 其它身体护理 - - - 足贴 - - - 耳机/耳麦 - - - 中国地图 - - - 世界地图 - - - 智能家居 - - - 电料配件 - - - 膏贴(器械) - - - 二手苹果配件 - - - 湿巾 - - - 网络配件 - - - 赠品 - - - 其他器械 - - - 魔幻/奇幻 - - - 幼小衔接 - - - Children's Books(儿童图书) - - - 早教启智 - - - 跳蛋 - - - 创意家居 - - - 其他科 - - - 电子开关 - - - 消毒液 - - - 二手纸品湿巾 - - - 教育周边 - - - 生活电器配件 - - - 对讲机配件 - - - - - 确定 - 取消 - - - - - - - - - - - - - 综合 - 销量 - 评论数 - 新品 - 价格 - - - - - - - - - - - - - - - - - - 清空 - 确定 - - - - - 1/100 - - < - > - - 共71万+件商品 - - - - - 配送至 - - - 北京 - - - - - - - - - - - 京东物流 - 货到付款 - 仅显示有货 - 京东国际 - 可配送全球 - PLUS专享 - 拍拍二手 - - - - - - - - - - - - - - - - - - - - - - - - ¥19.90 - - - - - 英菲克(INPHIC)PW1h 有线鼠标 游戏鼠标 静音鼠标 宏定义 家用办公笔记本电脑台式USB通用 黑色 - - - - - - - - 英菲克(INPHIC)京东自营旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 广告 - - - - - - - - - - - - - - - - - ¥19.00 - - - - - 戴尔(DELL)MS116 有线鼠标 商务办公鼠标(黑色)(适用于联想,华为,惠普,小米等品牌笔记本台式机) - 戴尔(DELL)MS116 有线鼠标 商务办公鼠标(黑色)(适用于联想,华为,惠普,小米等品牌笔记本台式机) - - - - - - - 戴尔京东自营官方旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥29.00 - - - - - 小米无线鼠标 Lite 2.4GHz无线传输 办公鼠标 黑色 - 【稳定】2.4GHz无线传输,省电节能稳定续航 -【手感】握感充盈轻巧舒适,简单轻便,摆脱有线束缚。 -查看更多好物【更多好物猛戳》 - - - - - - - 小米京东自营旗舰店 - - - 自营 - 放心购 - 新品 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥79.00 - - ¥69.00 - - - - -罗技(Logitech)M220 鼠标 无线鼠标 办公鼠标 静音鼠标 对称鼠标 灰黑色 带无线2.4G接收器 - 【静无止静,享受静音】无线自由连接,即插即用性微型接收器,稳定流畅的光学追踪【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - - - - 罗技京东自营旗舰店 - - - 自营 - 1件9.5折 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥19.90 - - - - - 联想(Lenovo)鼠标有线鼠标 办公鼠标 联想大红点M120Pro有线鼠标 笔记本台式机鼠标 - 【重磅上新】MK3背光机械键盘,晒单评论送E卡,数量有限先到先得!查看查看 - - - - - - - 联想京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥279.00 - - - - - 京东超市 -罗技(G)G502 HERO主宰者有线鼠标 游戏鼠标 HERO引擎 RGB鼠标 电竞鼠标 25600DPI - 【电脑数码超级品类日】爆款秒杀低至279元 -【爆款强推】高性能传感器,11个可编程按键,可调节配重 -【可调节重量】拥有极致游戏体验速戳》 - - - - - - - 罗技G京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥299.00 - - - - - 赛睿(SteelSeries)Rival 310 赛博朋克2077合作外设品牌 RGB人体工程学 魔兽怀旧开服 电竞游戏鼠标 黑 - - - - - - - - 赛睿京东自营旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 广告 - - - - - - - - - - - - - - - - - ¥28.90 - - - - - -联想(Lenovo)鼠标 无线鼠标 办公鼠标 联想大红点M120Pro无线鼠标 台式机鼠标 笔记本鼠标 - 【重磅上新】MK3背光机械键盘,晒单评论送E卡,数量有限先到先得!查看查看 - - - - - - - 联想京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥99.00 - - - - - 京东超市 -罗技(G)G102 游戏鼠标 黑色 RGB鼠标 吃鸡鼠标 绝地求生 轻量化设计 200-8000DPI G102第二代 - 【电脑数码超级品类日】爆款秒杀低至99元 -【下单有惊喜】热映电影票全场送 -【极致操作】轻量化设计,吃鸡神器速戳》 - - - - - - - 罗技G京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - 北京预定 - - - - - - - - - - - - - - - - ¥119.00 - - - - - 京东超市 -罗技(G)G102 游戏鼠标 RGB鼠标 吃鸡鼠标 绝地求生 轻量化设计 200-8000DPI G102第二代黑色 - 2.25-2.27电脑数码超级品类日,领120、80、40、20元券(部分产品可用),更有入会开卡领京豆,鼠标0元试用戳戳: - - - - - - - 罗技外设京东自营官方旗舰店 - - - 自营 - 券99-20 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥9.90 - - - - - 京东超市 -雷柏(Rapoo) N1200S 有线鼠标 办公鼠标 对称鼠标 笔记本鼠标 电脑鼠标 台式机鼠标 黑色 - 【2.25电脑数码品类日】雷柏Cherry轴机械键盘低至199元,舒适手感,兼顾游戏办公!点击前往 - - - - - - - 雷柏京东自营官方旗舰店 - - - 自营 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥65.00 - - - - - 京东超市 -罗技(Logitech)M275(M280) 鼠标 无线鼠标 办公鼠标 右手鼠标 黑色 带无线2.4G接收器 - 【舒适曲线,畅享无线】舒适曲线握槽,防滑图案【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - 去看二手 - - - - 罗技京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - 1件9.5折 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥499.00 - - - - - 赛睿(SteelSeries)Sensei Ten 10 游戏鼠标FPX战队鼠标有线电竞吃鸡人体工学RGB办公鼠标 - - - - - - - - 赛睿京东自营旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 广告 - - - - - - - - - - - - - - - - - ¥179.00 - - - - - 京东超市 -雷蛇 Razer 巴塞利斯蛇 X 极速版 小巴蛇 鼠标 无线鼠标 游戏鼠标 右手鼠标 电竞 双无线模式 黑色 16000DPI - 2.4G+5.0蓝牙双模式连接【PAW3369光学引擎】【约5000万次点击寿命】【6个可编程按键】 - - - - 去看二手 - - - - 雷蛇(Razer)京东自营官方旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥27.90 - - - - - 前行者3代电竞游戏绝地求生lolcf吃鸡机械2代台式电脑笔记本家用有线宏鼠标办公外设苹果静音非无声 冷酷黑鼠标【金属静音版】 - 【全国七仓配送*大部分地区*当日达/次日达-累计销售超59万+】【30天免费试用、三年换新】新品推荐-智能语音鼠标 - - - - - - - 敏涛数码专营店 - - - 京东物流 - 放心购 - 秒杀 - 免邮 - 券每满300减40 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥129.00 - - ¥119.00 - - - - -罗技(Logitech)M546(M545) 鼠标 无线鼠标 办公鼠标 对称鼠标 优联 双轴滚轮 黑色 带无线2.4G接收器 - 【轻松操作,便捷无线】新型双轴滚轮,激光机追踪技术,拇指按键令操作更为简单【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - - - - 罗技京东自营旗舰店 - - - 自营 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥179.00 - - - - - 京东超市 -罗技(G)G304 LIGHTSPEED无线鼠标 游戏鼠标 轻质便携 吃鸡鼠标 绝地求生 鼠标宏 黑色 12000DPI - 【电脑数码超级品类日】爆款秒杀低至179元 -【下单有惊喜】热映电影票全场送 -【极致操作】轻量化设计,吃鸡神器速戳》 - - - - - - - 罗技G京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥39.00 - - - - - 京东超市 -罗技(Logitech)M110 鼠标 有线鼠标 办公鼠标 静音鼠标 对称鼠标 黑色 自营 - 【静无止静,享受静音】降噪幅度超过90%,设置快捷,使用方便,双手通用的全尺寸舒适设计,3年有限质保【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - - - - 罗技京东自营旗舰店 - - - 自营 - 秒杀 - 1件9.5折 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥69.00 - - - - - 华硕 WT425无线鼠标 静音鼠标 办公鼠标 人体工学鼠标游戏鼠标 USB鼠标 黑色 - - - - - - - - 华硕京东自营旗舰店 - - - 自营 - - - 对比 - 关注 - 加入购物车 - - 广告 - - - - - - - - - - - - - - - - - ¥79.00 - - - - - 京东超市 -雷蛇(Razer) 蝰蛇标准版 鼠标 有线鼠标 游戏鼠标 人体工程学 电竞 白色 6400DPI - 蝰蛇标准版白色【人体工学设计】【1000HZ轮询率】【防滑侧裙】【6400DPI光学引擎】 - - - - 去看二手 - - - - 雷蛇(Razer)京东自营官方旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 北京预定 - - - - - - - - - - - - - - - - ¥49.00 - - - - - 雷神(ThundeRobot)无线游戏鼠标ML201 长续航 10米远距离传输无线游戏鼠标 - 【春节不打烊】春节好运无止境,拆未知牛气盲盒,更有百万京豆等你瓜分!详情点击 - - - - - - - 雷神京东自营官方旗舰店 - - - 自营 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥649.00 - - - - - 京东超市 -罗技(G)PRO WIRELESS 有线/无线鼠标 游戏鼠标 无线鼠标 RGB鼠标 轻量化设计 吃鸡鼠标 25600DPI - 【电脑数码超级品类日】爆款秒杀低至649元 -【下单有惊喜】热映电影票全场送 -【职业选手联合研发】吃鸡神器速戳》 - - - - 去看二手 - - - - 罗技G京东自营旗舰店 - - - 自营 - 放心购 - 秒杀 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥28.00 - - - - - 惠普(HP)M270有线游戏鼠标办公家用笔记本台式电脑吃鸡LOL绝地求生CF电竞专用机械宏编程鼠标 黑色宏编程鼠标 - 【京东物流】七仓配送,全国大部分地区当天/次日送达 -【售后无忧,赠15天价保,赠运费险】 -【收藏加购】首页加入会员立领3元券多重福利~~入会和更多产品请点击~~ - - - - - - - 志仕数码专营店 - - - 放心购 - 新品 - 闪购 - 免邮 - 券每满300减40 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥19.90 - - - - - 飞利浦 鼠标有线静音办公游戏电竞网吧机械无声便携式笔记本台式电脑男女通用人体工程学设计 经典黑 - 【两年免费换新】七仓配送,全国大部分地区当天/次日送达【赠运费险,15天免费退换,售后无忧】收藏加购首页更优惠,详情点击收藏加购首页更优惠,详情点击 - - - - - - - 志仕影音娱乐专营店 - - - 京东物流 - 放心购 - 新品 - 券每满300减40 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥499.00 - - - - - ROG 月刃无线版 无线鼠标 蓝牙鼠标三模 游戏鼠标 PBT按键 RGB灯效神光同步 可换微动 轻量化鼠标 16000DPI - - - - - - - - 华硕京东自营旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 广告 - - - - - - - - - - - - - - - - - ¥55.00 - - - - - 京东超市 -罗技(Logitech)M185(M186) 鼠标 无线鼠标 办公鼠标 对称鼠标 黑色灰边 带无线2.4G接收器 - 【经典款,稳定可靠,高效无线】2.4GHz无线技术,即插即用微型Nano接收器,长达12月电池寿命【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - - - - 罗技京东自营旗舰店 - - - 自营 - 秒杀 - 1件9.5折 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥79.00 - - - - - 京东超市 -雷蛇(Razer) 蝰蛇标准版 鼠标 有线鼠标 游戏鼠标 人体工程学 电竞 黑色 6400DPI lol吃鸡神器cf - 雷蛇蝰蛇标准版【人体工学】【可编程按键】【1000HZ轮询率】 - - - - 去看二手 - - - - 雷蛇(Razer)京东自营官方旗舰店 - - - 自营 - 放心购 - - - 对比 - 关注 - 加入购物车 - - 北京预定 - - - - - - - - - - - - - - - - ¥59.00 - - - - - 牧马人M1有线电竞游戏鼠标RGB背光机械宏编程鼠标网吧笔记本办公电脑台式吃鸡竞技轻量化设计外设 M1幻彩之影-黑色RGB宏编程版 - 牧马人轻量化鼠标,仅重99克,专为亚洲人手型设计,RGB流光特效、6段DPI调节,牧马人定制芯片,游戏娱乐办公均可适用! - - - - - - - 牧马人旗舰店 - - - 京东物流 - 放心购 - 秒杀 - 券每满300减40 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥99.00 - - - - - 京品数码 -罗技(Logitech)Pebble鹅卵石 鼠标 无线蓝牙鼠标 办公鼠标 静音鼠标 女性鼠标 便携鼠标 对称鼠标 玫瑰粉 - 【颜值担当】罗技鹅卵石无线鼠标,轻巧便携,舒适手感,蓝牙或USB连接【寻找无线静音鼠标,摆脱尾巴束缚,M220了解一下】 - - - - - - - 罗技京东自营旗舰店 - - - 自营 - 秒杀 - 1件9.5折 - 赠 - - - 对比 - 关注 - 加入购物车 - - - - - - - - - - - - - - - - - ¥29.90 - - - - - 京东超市 -英菲克(INPHIC)PM6 无线鼠标 静音鼠标 无线游戏鼠标 办公鼠标 可充电便携鼠标 电脑台式笔记本2.4G通用 黑 - 焕新开学季,英菲克键鼠爆款秒杀直降,部分商品领劵满49-10,满99-20,爆款无线充电鼠标低至29.9戳这查看购买 - - - - - - - 英菲克(INPHIC)京东自营旗舰店 - - - 自营 - 秒杀 - 券49-10 - - - 对比 - 关注 - 加入购物车 - - - - - - -正在加载中,请稍后~~ - - - - - - - - 商品精选 - - - - - - 精品推荐 - 商家精选 - - - - - - - - - - - - - 商品精选 - - - - - - - - 您是不是要找: - - - - 重新搜索: - - - 搜索 - 说说我使用搜索的感受 - - - - - - - - - - - - - - - - - - - 多品类齐全,轻松购物 - - - - - - 快多仓直发,极速配送 - - - - - - 好正品行货,精致服务 - - - - - - 省天天低价,畅选无忧 - - - - - - - - - - - - - - - - 购物指南 - - - - 购物流程 - - - - - - 会员介绍 - - - - - - 生活旅行/团购 - - - - - - 常见问题 - - - - - - 大家电 - - - - - - 联系客服 - - - - - - - - 配送方式 - - - - 上门自提 - - - - - - 211限时达 - - - - - - 配送服务查询 - - - - - - 配送费收取标准 - - - - - - 海外配送 - - - - - - - - 支付方式 - - - - 货到付款 - - - - - - 在线支付 - - - - - - 分期付款 - - - - - - 公司转账 - - - - - - - - 售后服务 - - - - 售后政策 - - - - - - 价格保护 - - - - - - 退款说明 - - - - - - 返修/退换货 - - - - - - 取消订单 - - - - - - - - 特色服务 - - - - 夺宝岛 - - - - - - DIY装机 - - - - - - 延保服务 - - - - - - 京东E卡 - - - - - - 京东通信 - - - - - - 京鱼座智能 - - - - - - - - - - - - - - - - - - - - - - - - - - -