We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9a73f47 commit 4fdff89Copy full SHA for 4fdff89
TODO.md
@@ -1 +1,2 @@
1
-1. 写一篇文章,详细的介绍lambda
+1. 写一篇文章,详细的介绍lambda
2
+2.如果有精力的话建议学习《Learn Python the Hard Way》这本书
day-11/partial-func.py
@@ -0,0 +1,20 @@
+
+# 使用functools.partial创建偏函数
3
+print(int('123')) # 123
4
+print(int('123', base=8)) # 83
5
6
+# 固定函数的部分参数
7
+def int_base_2(x, base=2):
8
+ return int(x, base)
9
10
+print(int_base_2('1010110')) # 86
11
12
+# 使用functools
13
+import functools
14
15
+int_base_2_v2 = functools.partial(int, base=2)
16
17
+print(int_base_2_v2('1010110')) # 86
18
19
+max_10 = functools.partial(max, 10)
20
+print(max_10(2, 3, 4)) # 10
0 commit comments