您的位置:首页 > 博客中心 > 编程语言 >

Python标准库:内置函数globals()

时间:2022-03-24 18:43

本函数是返回当前运行环境下的全局符号表字典。通过这个字典,可以查询有那些模块可以访问,那些函数可以访问,那些变量可以访问。可以用来获取当前全局符号表字典,给某些函数使用。

例子:

#globals()

def fun(x):
    return x
 
fun(100)
print(globals())

输出结果如下:

{‘__name__‘: ‘__main__‘, ‘__spec__‘: None, ‘__builtins__‘: <module ‘builtins‘ (built-in)>, ‘fun‘: <function fun at 0x003BB198>, ‘__file__‘:

...


热门排行

今日推荐

热门手游