python3 globals()_locals().py

"""
模块:globals()_locals().py
参考:https://www.f.com/python/python-func-globals.html
https://www.f.com/python/python-func-locals.html
知识点:
1.globals()
globals(),返回全局变量的字典。
2.
locals(),返回局部变量的字典。
"""


# 1.
def f(arg):  # 两个局部变量:arg、z
    z = 1
    print(locals())


f(4)
# {'z': 1, 'arg': 4}

# 2.
a = 'ok'
print(globals())
print('f:', f)
# f: <function f at 0x000001BF52DC2E18>
print('__name__:', __name__)
# __name__: __main__
print('__file__:', __file__)
# __file__: I:/aoshenji/cs.py
print('a:', a)
# a: ok
# print('__doc__:', __doc__)
# __doc__:
# 模块:globals()_locals().py
# 参考:https://www.f.com/python/python-func-globals.html
# https://www.f.com/python/python-func-locals.html
# 知识点:
# 1.globals()
# globals(),返回全局变量的字典。
# 2.
# locals(),返回局部变量的字典。
发布了198 篇原创文章 · 获赞 58 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/104006538