class Programer(object):
hobby = 'Play Computer'
def __init__(self, name, age, weight):
self.name = name
self._age = age
self.__weight = weight
@classmethod
def get_hobby(cls):
return cls.hobby
@property
def get_weight(self):
return self.__weight
def self_introduction(self):
print("my name is %s \n i am %s years old" % (self.name, self._age))
class BcakendProgramer(Programer):
def __init__(self, name, age, weight, language): # 创建构造函数
super(BcakendProgramer, self).__init__(name, age, weight) # 调用父类构造函数
self.language = language # 再添加一个属性,进行赋值
if __name__ == '__main__':
programer = BcakendProgramer('Albert', 21, 50, 'Chinese')
print('dir()-----将属性打印:\n', dir(programer))
print('programer.__dict__ ----- 是将这个对象在构造函数里面赋予值的属性打印出来\n', programer.__dict__)
print('type(programer)是个啥东西:判断paogranmer的种类\n', type(programer))
print('isinstance(programer,Programer)是个啥东西:-----判断后者是不是前者的父类\n', isinstance(programer, Programer))
#输出结果
dir()-----将属性打印: ['_Programer__weight', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_age', 'get_hobby', 'get_weight', 'hobby', 'language', 'name', 'self_introduction']
programer.__dict__ ----- 是将这个对象在构造函数里面赋予值的属性打印出来 {'name': 'Albert', '_age': 21, '_Programer__weight': 50, 'language': 'Chinese'}
type(programer)是个啥东西:判断paogranmer的种类 <class '__main__.BcakendProgramer'>
isinstance(programer,Programer)是个啥东西:-----判断后者是不是前者的父类 True