主要方法如下:
1.*args 把所有位置参数聚合到元组中
2.**kwargs 把所有的关键字参数聚合到字典中
3.‘*’在函数的调用时,代表打散
4.默认参数的陷阱!
def func(name,alist=[]): alist.append(name) return alist res = func('alex') res2 = func('panda') #res == ['alex'] #res2 == ['alex','panda '] #如果 默认参数 指向一个可迭代的数据类型
5.局部嵌套定义的函数需要用 nonlocal 声明
def wrapper(): count = 1 def inner(): nonlocal count count += 1
下一篇:Python中嵌套函数作用