Skip to content

Commit b4b1718

Browse files
committed
add code
1 parent 3a53b42 commit b4b1718

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

doudou/2020-06-19-skills/skills.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def outer(x):
2+
def inner(y):
3+
# 在内函数中 用到了外函数的变量
4+
nonlocal x
5+
x += y
6+
return x + y
7+
8+
# 外函数的返回值是内函数的引用
9+
return inner
10+
11+
fun = outer(10)
12+
13+
print(fun(10)) # 30
14+
print(fun(10)) # 40
15+
print(fun(10)) # 50

doudou/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Python技术 公众号文章代码库
1919
+ [字符画](https://github.com/JustDoPython/python-examples/tree/master/doudou/2020-05-17-character-drawing):字符画
2020

2121
+ [迷宫](https://github.com/JustDoPython/python-examples/tree/master/doudou/2020-06-12-maze):迷宫
22+
23+
+ [Python 骚操作](https://github.com/JustDoPython/python-examples/tree/master/doudou/2020-06-19-skills):Python 骚操作
24+
2225
---
2326

2427
从小白到工程师的学习之路。

0 commit comments

Comments
 (0)