From 6e2eec277d33fcda9b1517ac966f8fcc8274b848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=99=9A=E5=B9=B3?= <8437069+zhang-xuping@user.noreply.gitee.com> Date: Sat, 9 Jan 2021 19:50:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=9C=9F=E8=AE=AD=E7=BB=83=E8=90=A5/1?= =?UTF-8?q?=E7=8F=AD/1=E7=8F=AD=5F=E5=98=98=E5=98=98/=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E5=91=A8-=E7=AC=AC=E4=B8=89=E8=8A=82-=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8F=90=E4=BA=A4/21.01.02.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../21.01.02.py" | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" 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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" deleted file mode 100644 index a80f5afd..00000000 --- "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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" +++ /dev/null @@ -1,69 +0,0 @@ -#问题一,练习作用域之间的转换 -total = 0 -def sum(a, b): - total = a + b - print("函数内是局部变量:", total) - return total -print(sum(5, 10)) -print("函数外是全局变量:", total) - -total1 = 1 -def func(): - global total1 - print(total1) - total1 = 2 - print(total1) -print(func()) -print(total1) - -def a(): - total = 1 - def b(): - nonlocal total - total = 3 - print(total) - return b - b() - print(total) -a() - -#问题二,实现一个装饰器,用来输出函数的执行时间 -import time -def clock_deco(func): - def wrap(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") - return result - return wrap - -@clock_deco -def cool(a, b): - num = 0 - while True: - if num >= a ** b: - break - num += 1 - -cool(5, 10) - -#问题三,使用装饰器来为斐波那契函数增加缓存 -a = {} -def cache_deco(func): - global a - def wrap(n): - if n not in a: - a[n] = func(n) - return a[n] - return wrap - -@ cache_deco -def fib(n): - if n < 2: - return n - else: - return fib(n - 2) + fib(n - 1) - -print(fib(10)) -print(a) -- Gitee From de0f7332f995e369eb89880f4b2a666a5ab7bb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=99=9A=E5=B9=B3?= <8437069+zhang-xuping@user.noreply.gitee.com> Date: Sat, 9 Jan 2021 19:50:53 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=91=A8=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E8=8A=82=E8=AF=BE=E8=AF=BE=E5=90=8E=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=90=8E=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../21.01.02.py" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" 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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" new file mode 100644 index 00000000..19fbbf2a --- /dev/null +++ "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_\345\230\230\345\230\230/\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21.01.02.py" @@ -0,0 +1,68 @@ +#问题一,练习作用域之间的转换 +total = 0 +def sum(a, b): + total = a + b + print("函数内是局部变量:", total) + return total +print(sum(5, 10)) +print("函数外是全局变量:", total) + +total1 = 1 +def func(): + global total1 + print(total1) + total1 = 2 + print(total1) +print(func()) +print(total1) + +def a(): + total = 1 + def b(): + nonlocal total + total = 3 + print(total) + return b + b() + print(total) +a() + +#问题二,实现一个装饰器,用来输出函数的执行时间 +import time +def clock_deco(func): + def wrap(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} 执行时长为:{format(end_time - start_time, '.2f')}s") + return result + return wrap + +@clock_deco +def cool(a, b): + num = 0 + while True: + if num >= a ** b: + break + num += 1 + +cool(5, 10) + +#问题三,使用装饰器来为斐波那契函数增加缓存 + +def cache_deco(func): + a = {} + def wrap(n): + if n not in a: + a[n] = func(n) + return a[n] + return wrap + +@ cache_deco +def fib(n): + if n < 2: + return n + else: + return fib(n - 2) + fib(n - 1) + +print(fib(10)) -- Gitee From c57dfdd6359094712bc803eb27ff9662db20a424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=99=9A=E5=B9=B3?= <8437069+zhang-xuping@user.noreply.gitee.com> Date: Sat, 9 Jan 2021 22:48:40 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=9B=9B?= =?UTF-8?q?=E5=91=A8-=E7=AC=AC=E4=B8=89=E8=8A=82-=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From 8a3f25b4af0e42549d100078bb7ef2c22b56c14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=99=9A=E5=B9=B3?= <8437069+zhang-xuping@user.noreply.gitee.com> Date: Sat, 9 Jan 2021 22:48:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E5=91=A8=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E8=8A=82=E8=AF=BE=E8=AF=BE=E5=90=8E=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../21_01_09.py" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" new file mode 100644 index 00000000..a276c066 --- /dev/null +++ "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" @@ -0,0 +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.ediv(10,5)) + +#第二问 +class Cat: + cute_cat = True + __mycat = {"David": 2} + def __init__(self, name, age): + + self. name = name + self. __age = age + + @classmethod + def __new__(cls, *args, **kwargs): + print("猫咪真可爱") + return super().__new__(cls) + + def __str__(self): + return "名字是:%s , 年龄是:%d" % (self. name, self. __age) + + + +print(Cat. _Cat__mycat) +tom = Cat("汤姆", 30) +print(tom) \ No newline at end of file -- Gitee From d5d99f5a2101650fd708babfb13cae68d7c4e0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=99=9A=E5=B9=B3?= <8437069+zhang-xuping@user.noreply.gitee.com> Date: Sat, 9 Jan 2021 22:55:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=9C=9F=E8=AE=AD=E7=BB=83=E8=90=A5/1?= =?UTF-8?q?=E7=8F=AD/1=E7=8F=AD=5F=E5=98=98=E5=98=98/=E7=AC=AC=E5=9B=9B?= =?UTF-8?q?=E5=91=A8-=E7=AC=AC=E4=B8=89=E8=8A=82-=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 .../21_01_09.py" | 48 ------------------- 2 files changed, 48 deletions(-) delete mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" delete mode 100644 "\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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/.keep" deleted file mode 100644 index e69de29b..00000000 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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" deleted file mode 100644 index a276c066..00000000 --- "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_\345\230\230\345\230\230/\347\254\254\345\233\233\345\221\250-\347\254\254\344\270\211\350\212\202-\344\275\234\344\270\232\346\217\220\344\272\244/21_01_09.py" +++ /dev/null @@ -1,48 +0,0 @@ -#第一问 -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.ediv(10,5)) - -#第二问 -class Cat: - cute_cat = True - __mycat = {"David": 2} - def __init__(self, name, age): - - self. name = name - self. __age = age - - @classmethod - def __new__(cls, *args, **kwargs): - print("猫咪真可爱") - return super().__new__(cls) - - def __str__(self): - return "名字是:%s , 年龄是:%d" % (self. name, self. __age) - - - -print(Cat. _Cat__mycat) -tom = Cat("汤姆", 30) -print(tom) \ No newline at end of file -- Gitee