オブジェクト向け三大プロパティ


#        
#1.  
#2.  
#3.  
'''
1.     :         ,        ,          ,        。
               python ,  (   )            (  ,  )

'''
#     
#class Parent1:
#    pass

#class Parent2:
#    pass

#class Sub1(Parent1):
#    pass

#class Sub2(Parent1,Parent2):
#    pass

#print(Parent1.__bases__)  #           
#print(Sub1.__bases__)    #           
#print(Sub2.__bases__)    #           

# python2    2 :
#1.   ,:     object   ,       。
#2.   ,:   object   ,       。

# python3        :
# 
#class olstu:
#    sch='oldboy'
#    def __init__(self,name,age,sex):
#        self.name=name
#        self.age=age
#        self.sex=sex

#    def learn(self):
#        print('%s is learing' %self.name)

#class olteach:
#    sch='oldboy'
#    def __init__(self,name,age,sex):
#        self.name=name
#        self.age=age
#        self.sex=sex

 #   def tech(self):
#        print('%s is teachring' % self.name)

#    (    )
class olper:
    sch = 'oldboy'
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def tell__info(self):
        print('  :   :   :' %(self.name,self.age,self.sex))

class olstu(olper):
    def learn(self):
        print('%s is learing' % self.name)
    def tell__info(self):
        print('wo is stu',end='')
        print('  :   :   :' %(self.name,self.age,self.sex))

class olteach(olper):
    def tech(self):
        print('%s is teachring' % self.name)

#         ,           ,            ,             。     ,          。
stu1=olstu('sut',18,'ser')
tea1=olteach('tea',18,'sse')
#print(stu1.__dict__)
#print(stu1.sch)
stu1.tell__info()
tea1.tell__info()

#    
class foo:
    def f1(self):
       print('from foo.f1')

    def f2(self):    #self=obj
        print('from foo.f2')
        self.f1()          #obj.f1()
class bar(foo):
    def f1(self):
        print('from bar.f1')
obj=bar()
obj.f2()

#         
#class olper:
#    sch = 'oldboy'
#    def __init__(self, name, age, sex):
#        self.name = name
#        self.age = age
#        self.sex = sex

#    def tell__info(self):
#        print('  :   :   :' %(self.name,self.age,self.sex))

#class olstu(olper):
#    def learn(self):
#        print('%s is learing' % self.name)
#    def tell__info(self):
#        print('wo is stu',end='')
#        olper.tell__info(self)

#stu1=olstu('sut',18,'ser')
#stu1.tell__info()

#
class olper:
    sch = 'oldboy'
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def tell__info(self):
        print('  :   :   :' %(self.name,self.age,self.sex))

class olstu(olper):
    def __init__(self,name,age,sex,work):
       #self.name=name
       #self.age=age
       #self.sex=sex
       olper.__init__(self,name,age,sex)
       self.work=work

    def learn(self):
       print('%s is learing' % self.name)
    def tell__info(self):
        print('wo is stu:',end='')
        olper.tell__info(self)

stu1=olstu('sut',18,'ser','ss')
stu1.tell__info()

#          super(),super          。
class olper:
    sch = 'oldboy'
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def tell__info(self):
        print('  :   :   :' %(self.name,self.age,self.sex))

class olstu(olper):
    def __init__(self,name,age,sex,work):
       #self.name=name
       #self.age=age
       #self.sex=sex
       super().__init__(name,age,sex)
       self.work=work

    def tell__info(self):
        print('i is stu' ,end='')
       # olper.tell__info(self)
        super().tell__info()

stu1=olstu('hu',15,'sdf','python')
stu1.tell__info()

#super   
class Foo:
    def f2(self):
      print('=====')

    def f1(self):
        print('foo.f1')
        super().f2()

class Bar:
    def f2(self):
        print('Bar.f2')

class  Sub(Foo,Bar):
    pass

s=Sub()
print(Sub.mro())

s.f1()

#  
#class olper:
#    sch = 'oldboy'
#    def __init__(self, name, age, sex):
#        self.name = name
#        self.age = age
#        self.sex = sex

 #   def tell__info(self):
#        print('  :   :   :' %(self.name,self.age,self.sex))

#class olstu(olper):
#    def __init__(self,name,age,sex,work,st_id,year,day):
#       #self.name=name
#       #self.age=age
#       #self.sex=sex
#       olper.__init__(self,name,age,sex)
#       self.work=work
#       self.st_id=st_id
#       self.year=year
#       self.day = day

#    def learn(self):
#       print('%s is learing' % self.name)

#   def tell__info(self):
#       print('wo is stu:',end='')
#       olper.tell__info(self)

#    def tell_birth(self):
#         print('  :《%s-%s》' %(self.year,self.day))

#class olteach(olper):
 #   def __init__(self,name,age,sex,level,salary,year,day):
#       olper.__init__(self,name,age,sex)
#       self.level=level
#       self.salary=salary
#       self.year=year
#       self.day=day

#    def tech(self):
#        print('%s is teachring' % self.name)

#   def tell_birth(self):
#        print('  :《%s-%s》' %(self.year,self.day))

#    def tell__info(self):
#        print('wo is teach:',end='')
#        olper.tell__info(self)

#stu1=olstu('sut',18,'ser','ss',1,1995,9)
#teac1=olteach('tea',18,'tea',8,4000,1985,2)

#stu1.tell_birth()
#teac1.tell_birth()

#    
class olper:
    sch = 'oldboy'
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def tell__info(self):
        print('  :   :   :' %(self.name,self.age,self.sex))

class olstu(olper):
    def __init__(self,name,age,sex,work,st_id):
       #self.name=name
       #self.age=age
       #self.sex=sex
       olper.__init__(self,name,age,sex)
       self.work=work
       self.st_id=st_id

    def learn(self):
       print('%s is learing' % self.name)

    def tell__info(self):
        print('wo is stu:',end='')
        olper.tell__info(self)

class olteach(olper):
    def __init__(self,name,age,sex,level,salary):
       olper.__init__(self,name,age,sex)
       self.level=level
       self.salary=salary

    def tech(self):
        print('%s is teachring' % self.name)

    def tell__info(self):
        print('wo is teach:',end='')
        olper.tell__info(self)

class Date:
    def __init__(self,year,day):
         self.year=year
         self.day=day

    def tell_birth(self):
        print('  :《%s-%s》' % (self.year, self.day))

stu1=olstu('sut',18,'ser','ss',1)
date_obj1=Date(1995,9)
stu1.birth=date_obj1

teac1=olteach('tea',18,'tea',8,4000)
date_obj2=Date(1985,9)
teac1.birth=date_obj2

#print(stu1.birth)
#print(teac1.birth)

stu1.birth.tell_birth()
teac1.birth.tell_birth()

#     
#class olper:
#    sch = 'oldboy'
#    def __init__(self, name, age, sex, date_obj):
#        self.name = name
#        self.age = age
#        self.sex = sex
#        self.brith=date_obj

#    def tell__info(self):
#        print('  :   :   :' %(self.name,self.age,self.sex))

#class olstu(olper):
#    def __init__(self,name,age,sex,work,st_id,date_obj):
       #self.name=name
       #self.age=age
       #self.sex=sex
#       olper.__init__(self,name,age,sex,date_obj)
#       self.work=work
#       self.st_id=st_id

#    def learn(self):
#       print('%s is learing' % self.name)

#    def tell__info(self):
#        print('wo is stu:',end='')
#        olper.tell__info(self)

#class olteach(olper):
#    def __init__(self,name,age,sex,level,salary,date_obj):
#       olper.__init__(self,name,age,sex,date_obj)
#       self.level=level
#       self.salary=salary

#    def tech(self):
#        print('%s is teachring' % self.name)

#    def tell__info(self):
#        print('wo is teach:',end='')
#        olper.tell__info(self)

#class oldxiao(olper):
#    def __init__(self,name,age,sex,key,date_obj):
#        olper.__init__(self,name,age,sex,date_obj)
#        self.key=key
#    def tell_info(self):
#        print('xiaoshou',end='')
#        olper.tell__info(self)

#class Date:
#    def __init__(self,year,day):
#         self.year=year
#         self.day=day

#    def tell_birth(self):
#        print('  :《%s-%s》' % (self.year, self.day))

#date_obj=Date(1995,5)
#salte1=oldxiao('  ',45,'salce',73,date_obj)
#salte1.brith=date_obj
#salte1.tell__info()

#salte1.brith.tell_birth()

class olper:
    sch = 'oldboy'
    def __init__(self, name, age, sex, date_obj):
        self.name = name
        self.age = age
        self.sex = sex
        self.brith=date_obj

    def tell__info(self):
        print('  :   :   :' %(self.name,self.age,self.sex))

class olstu(olper):
    def __init__(self,name,age,sex,work,st_id,date_obj):
       #self.name=name
       #self.age=age
       #self.sex=sex
       olper.__init__(self,name,age,sex,date_obj)
       self.work=work
       self.st_id=st_id

    def learn(self):
       print('%s is learing' % self.name)

    def tell__info(self):
        print('wo is stu:',end='')
        olper.tell__info(self)

class olteach(olper):
    def __init__(self,name,age,sex,level,salary,date_obj):
       olper.__init__(self,name,age,sex,date_obj)
       self.level=level
       self.salary=salary
       self.caoure=[]

    def tech(self):
        print('%s is teachring' % self.name)

    def tell__info(self):
        print('wo is teach:',end='')
        olper.tell__info(self)

class oldxiao(olper):
    def __init__(self,name,age,sex,key,date_obj):
        olper.__init__(self,name,age,sex,date_obj)
        self.key=key
    def tell_info(self):
        print('xiaoshou',end='')
        olper.tell__info(self)

class Date:
    def __init__(self,year,day):
         self.year=year
         self.day=day

    def tell_birth(self):
        print('  :《%s-%s》' % (self.year, self.day))

class caoure:
    def __init__(self,name,precei,ptryird):
        self.name=name
        self.precei=precei
        self.ptryird=ptryird

    def tell_info(self):
        print('    :《%s,%s,%s》' %(self.name,self.precei,self.ptryird))

pytth=caoure('pythonsji',4566,'sf')
linux=caoure('linuxi',4566,'iii')
date_obj=Date(1998,9)

tech1=olteach('laohs',34,'ss',34,1000,date_obj)
tech1.caoure.append(pytth)
tech1.caoure.append(linux)

#print(tech1.caoure)
for i in tech1.caoure:
    i.tell_info()