1. class person(object):
    2. tall = 180
    3. hobbies = []
    4. def __init__(self, name, age,weight):
    5. self.name = name
    6. self.age = age
    7. self.weight = weight
    8. def infoma(self):
    9. print('%s is %s weights %s'%(self.name,self.age,self.weight))
    10. person.hobbies.extend(["football", "woman"])
    11. print("person hobbies list: %s" %person.hobbies) ## person hobbies list: ['football', 'woman']
    12. person.hobbies2 = ["reading", "jogging", "swimming"]
    13. print("person hobbies2 list: %s" %person.hobbies2) ## person hobbies2 list: ['reading', 'jogging', 'swimming']
    14. print(dir(person))
    15. ## ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__',
    16. # '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__',
    17. # '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
    18. # '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
    19. # 'hobbies', 'hobbies2', 'infoma', 'tall']
    20. #实例数据属性只能通过实例访问
    21. Bruce = person("Bruce", 25,60)
    22. print ("%s is %d years old" %(Bruce.name, Bruce.age) )
    23. # 在实例生成后,还可以动态添加实例数据属性,但是这些实例数据属性只属于该实例
    24. # 重新实例化的对象不包含实例数据属性
    25. Bruce.gender = "male"
    26. print( "%s is %s" %(Bruce.name, Bruce.gender) )
    27. # 可以通过类属性访问该实例
    28. print(dir(Bruce))
    29. # ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
    30. # '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
    31. # '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
    32. # '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
    33. # 'age', 'gender', 'hobbies', 'infoma', 'name', 'tall', 'weight']
    34. Bruce.hobbies.append("C#")
    35. print(Bruce.hobbies) ## ['C#']