summaryrefslogtreecommitdiff
path: root/basics/python
diff options
context:
space:
mode:
authorzhang <zch921005@126.com>2022-10-23 11:39:29 +0800
committerzhang <zch921005@126.com>2022-10-23 11:39:29 +0800
commit2fe442cce5ddeeddf66958ee42a9d2d244d1a39e (patch)
treecbe1b072bfad1005792b9ed6e2955bb64dfa8099 /basics/python
parent2fef28a07fcc9f43455b24188987f882220c05f2 (diff)
update
Diffstat (limited to 'basics/python')
-rw-r--r--basics/python/closure.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/basics/python/closure.py b/basics/python/closure.py
new file mode 100644
index 0000000..a1fc502
--- /dev/null
+++ b/basics/python/closure.py
@@ -0,0 +1,16 @@
+
+from random import randint
+
+def outer(msg):
+ value = randint(0, 100)
+ message = msg
+ def inner():
+ print(msg)
+ return inner
+
+if __name__ == '__main__':
+ f = outer('zhang')
+ f()
+ f()
+ f()
+