本文教程 *** 作环境:windows7系统、Python 3.9.1,DELL G3电脑。
1、locals 函数
2、语法
locals()
3、返回值
返回一个字典,该字典包含当前位置的所有局部变量。
4、使用实例
def foo(arg, a): x = 1 y = 'xxxxxx' for i in range(10): j = 1 k = i print locals()
输出
foo(1,2) #{'a': 2, 'i': 9, 'k': 9, 'j': 1, 'arg': 1, 'y': 'xxxxxx', 'x': 1}
以上就是python中locals函数的介绍,如果修改需要更新并以字典形式返回当前全部局部变量,可以套用上述代码使用locals函数哦~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)