From e99722ac373e702c1147c652fd01dda31b2f3c92 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, 2 Jan 2021 22:54:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=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?= 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\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/.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\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/.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\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/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From ae20b01b83de6cf3f9987199e9deaa92dac62b85 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, 2 Jan 2021 22:54:33 +0800 Subject: [PATCH 2/2] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../21.01.02.py" | 66 +++++++++++++++++++ 1 file changed, 66 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..fdcf4f27 --- /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,66 @@ +# #问题一,练习作用域之间的转换 +# 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(*args, **kwargs): + if args not in a.keys(): + a[args] = func(*args, **kwargs) + return a[args] + return wrap + +@ cache_deco +def fib(n): + if n <= 1: + return 1 + return fib(n-1) + fib(n-2) + +print(fib(10)) -- Gitee