[Python] 命名空间&作用域
Python的类语句不会创建实例 类会创建命名空间,通过对象访问类的属性和方法 类不会创建作用域,对方法和属性的引用必须加以限定(如在方法中必须通过self引用实例的属性) class My1(): my1 = "My1bianliang" def __init__(self): print("My1gouzao") def __del__(self): print("My1xigou") class My2(): def __init__(self): print("My2gouzao") my1=My1() 结果: >>My1gouzao 说明没有创建作用域,只是了对象执行创建,没有析构 参考: Python 五个知识点搞定作用域: http://python.jobbole.com/86465/ Python函数的作用域和引用范围: https://www.cnblogs.com/saintdingspage/p/7788958.html Python 变量作用域: https://blog.csdn.net/mldxs/article/details/9250733 Python中的作用域及global用法: https://www.cnblogs.com/summer-cool/p/3884595.html 详解python命名空间和作用域: https://www