# 1.类或对象是否能做字典的key # 2.简述python的私有成员是如何实现的 # 3.私有成员能在类的外部使用么?能在子类中使用么? # 4.读程序写结果.(不执行) ''' class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) class RoleConfig(StarkConfig): def changelist(self,request): print('666') ''' #创建了一个列表,列表中有三个对象(实例) # config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] # for item in config_obj_list: # print(item.num) # 5.读程序写结果.(不执行) print("<===5===>") ''' class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) class RoleConfig(StarkConfig): pass ''' #创建了一个列表,列表中有三个对象(实例) # config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] # for item in config_obj_list: # item.changelist(168) # print(config_obj_list[0].num) # 6.读程序写结果.(不执行) ''' class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) class RoleConfig(StarkConfig): def changelist(self,request): print(666,self.num) config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] for item in config_obj_list: item.changelist(168) ''' # 7.读程序写结果.(不执行) ''' print("<====>") class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) def run(self): self.changelist(999) class RoleConfig(StarkConfig): def changelist(self,request): print(666,self.num) config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] config_obj_list[1].run() config_obj_list[2].run() ''' # 8.读程序写结果.(不执行) ''' print("<==8==>") class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) def run(self): self.changelist(999) class RoleConfig(StarkConfig): def changelist(self,request): print(666,self.num) class AdminSite(object): def __init__(self): self._registry = {} def register(self,k,v): self._registry[k] = v site = AdminSite() print(len(site._registry)) site.register('range',666) site.register('shilei',438) print(len(site._registry)) site.register('lyd',StarkConfig(19)) site.register('yjl',StarkConfig(20)) site.register('fgz',RoleConfig(33)) print(len(site._registry)) print(site._registry) ''' # 9.读程序写结果.(不执行) print("<==9==>") class StarkConfig(): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) def run(self): self.changelist(999) class RoleConfig(StarkConfig): def changelist(self,request): print(666,self.num) class AdminSite(): def __init__(self): self._registry = {} def register(self,k,v): self._registry[k] = v site = AdminSite() site.register('lyd',StarkConfig(19)) site.register('yjl',StarkConfig(20)) site.register('fgz',RoleConfig(33)) # print(len(site._registry)) for k,row in site._registry.items(): row.changelist(5) for k,row in site._registry.items(): row.run() # 10.读程序写结果.(不执行) print("<==10==>") class JustCounter: __secretCount = 0 def count(self): self.__secretCount += 1 print(self.__secretCount) def count3(): print(JustCounter.__secretCount) class Bars(JustCounter): def count2(self): print(self.__secretCount) # 情况一 # counter1 = JustCounter() # counter1.count() # counter1.count() # 情况二 # counter2 = Bars() # counter2.count() # counter2.count() # 情况三 # JustCounter.count3()