py class

来源:互联网 发布:常用的哈希算法 编辑:程序博客网 时间:2024/06/11 19:28

Tang 继承object类s

class Tang(object):
    def __init__(self, n, ph):
         self.name = n
         self.phone = ph
         print 'a new object is created'

    def shoot(self, newph):
         self.phone = newph
         print 'Update phone:', self.phone
  

Heng继承父类Tang
class Heng(Tang):
     def __init__(self, n, ph, id, ema):
         Tang.__init__(self, n, ph)
         self.idnum = id
         self.email = ema
         print 'create Heng'

     def UpdateEmail(self, em):
          self. email = em
         print 'update Emial :', self.email

 


#t = Tang('tang', 12345689)
#t.shoot(987654321)

p = Heng('xiang', 139, 561, 'tang@163.com')
print  p.name, p.phone, p.idnum, p.email
print p.UpdateEmail('xianghe@163.com')

原创粉丝点击