一. 动态传参
形参:1.位置参数 2.默认值参数 3.动态传参:(1)*args:动态接受位置参数,(2)**kwargs:动态接受关键字参数
顺序:位置,*args, 默认值,**kwargs
*, **: def func(*args,**kwargs) :无敌传参
pass
*, ** 在形参位置:聚合 在实参位置 :打散
实参:(1)位置参数 (2)关键字参数 (3)混合参数
二. 名称空间和作用域
名称空间:保存名字用的 (变量,函数,类)
1.内置名称空间:python自己,print, input, len
2.全局名称空间:你写的代码从上到下
3.局部名称空间:函数,类,方法,其他模块,对象
作用域:全局作用域(内置+全局)
局部作用域(局部名称空间)
!!!注:从局部找全局可以,但是从全局找局部是不可以的
globalls() :查看全局作用域中的名字
locals () :查看当前作用域中的名字
三. 函数的嵌套(难点):每一层都会产生独自的名称空间
四. global nonlocal
global:在局部引入全局的内容,可以升华一个变量为全局变量
nonlocal :在局部,引入上一层名称空间中的变量,如果没有,继续上一层 . . .