描述
globals函数作用:查看所有的全局变量
示例代码:
def func(): num2 = 10 print(globals()) func()
运行结果:
""" 执行结果: { '__name__': '__main__', '__doc__': ' globals函数: 作用: 查看所有的全局变量 ', '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f3b74758850>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/home/xyxifeng/PycharmProjects/chapter01/day09_高阶函数/hw_23_内置函数globals_变量相关.py', '__cached__': None, 'num1': 100, 'func': <function func at 0x7f3b746cce60>} """