2020年1月12日 MRKJ 面向对象 page181
class func: fly='you can fly' def __init__(self): self.name='name' print(self.fly) list1=[] for i in range(4): #生成4个实例 list1.append(func()) print(list1[1].name) print(list1[2].fly) print(list1)
》》》》
you can fly
you can fly
you can fly
you can fly
name
you can fly
[<__main__.func object at 0x02C00A30>, <__main__.func object at 0x02C00050>, <__main__.func object at 0x02C00970>, <__main__.func object at 0x02C00990>]
class func: fly='you can fly' def __init__(self): self.name='name'#实例属性 func.fly='FLY'#类属性 print(self.fly)