country = '澳大利亚' class Chinese: country = '中国' def __init__(self,name): self.name = name print('------>',country) #既不是类属性,也不是实例属性,根据作用域原则查找 print('------>',self.country) #先找自己的属性字典,再找类的属性字典,如果没有直接报错 c1 = Chinese('zhao')
country = '澳大利亚' class Chinese: country = '中国' def __init__(self,name): self.name = name print('------>',country) #既不是类属性,也不是实例属性,根据作用域原则查找 print('------>',self.country) #先找自己的属性字典,再找类的属性字典,如果没有直接报错 c1 = Chinese('zhao')