- function.__doc__
- function(a = x, b = y) 关键字参数
- def function(a = x, b = y): 默认值参数
- def function(*params) 收集参数,可输入多个参数打包为元组
- 函数无return时返回None
- globle 将局部变量转化为全局变量
- 闭包
def FunX(x):
def FunY(y):
return x * y
return FunY
FunX(8)(5)
def Fun1():
x = 5
def Fun2():
nonlocal x
x *= x
return x
return Fun2()
- lambda 匿名函数
- g = lambda x : 2 * x + 1
- g(5)
- g = lambda x, y : x + y
- g(3, 4)
- filter()
- list(filter(None, [1, 0, False, True]))
def odd(x):
return x % 2
temp = range(10)
show = filter(odd, temp)
list(show)
- list(filter(lambda x : x % 2, range(10)))
- map 映射
- list(map(lambda x : x * 2, range(10)))
- 递归
- import sys
- sys.setrecursionlimit(n)