内置函数_locals_变量相关
描述
locals() 函数会以字典类型返回当前位置的全部局部变量。
示例代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
num1 = 100 def func(): num2 = 10 print(locals()) func() """ 执行结果: {'num2': 10} """
locals() 函数会以字典类型返回当前位置的全部局部变量。
num1 = 100 def func(): num2 = 10 print(locals()) func() """ 执行结果: {'num2': 10} """