shengge0 2020-01-04
a = ‘我是模块中的变量a‘
def hi():
a = ‘我是函数里的变量a‘
print(‘函数“hi”已经运行!‘)
class Go2:
a = ‘我是类2中的变量a‘
def do2(self):
print(‘函数“do2”已经运行!‘)
print(a) # 打印变量“a”
hi() # 调用函数“hi”
A = Go2() # 实例化“Go2”类
print(A.a) # 打印实例属性“a”
A.do2() # 调用实例方法“do2” class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =