当前本地符号表 current local symbol table

发布时间 2023-06-13 20:53:14作者: papering

实践:

1、

a,b=123,456
locals()['a']=1
locals()['b']=2
 
场景:
画图:
时序图 汽车、轮船 两家公司销量。
 

 

Built-in Functions — Python 3.11.4 documentation https://docs.python.org/3/library/functions.html#locals

 

locals()

Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. Note that at the module level, locals() and globals() are the same dictionary.

Note

 

The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.

 

locals()

更新并返回表示当前本地符号表的字典。 在函数代码块但不是类代码块中调用 locals() 时将返回自由变量。 请注意在模块层级上,locals() 和 globals() 是同一个字典。

备注

 

不要更改此字典的内容;更改不会影响解释器使用的局部变量或自由变量的值。

locals()