locals() 函数会以字典类型返回当前位置的全部局部变量。
num1 = 100 def func(): num2 = 10 print(locals()) func() """ 执行结果: {'num2': 10} """