1.类没有实例属性时会调用类属性
class Flower(object):
height = 20
def __init__(self,name,color):
self.name = name
self.color = color
f = Flower('玫瑰','红色')
print(f.height)
#输出:20
2.实例属性的优先级高于类属性
class Flower(object):
height = 20
def __init__(self,name,color,height):
self.name = name
self.color = color
self.height = height
f = Flower('玫瑰','红色','10')
print(f.height)
#输出:10
3.删除实例属性
class Flower(object):
height = 20
def __init__(self,name,color,height):
self.name = name
self.color = color
self.height = height
f = Flower('玫瑰','红色',10)
del f.height
print(f.height)
#输出结果:20