网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

如何在Python中使用类的继承-创新互联

如何在Python中使用类的继承?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的万宁网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!python是什么意思

Python是一种跨平台的、具有解释性、编译性、互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。

python —类的继承

root@kali:~/python/mod# vi class2.py
root@kali:~/python/mod# cat class2.py
#!/usr/bin/python
# --*-- coding:utf-8 --*--
class person:
  def __init__(self,name,nationality,age,sex,job):
    self.Name = name
    self.Country = nationality
    self.Age = age
    self.Sex= sex
    self.Job = job
  def talk(self,msg):
    self.msg = msg#定义msg变量,可以在python交换环境中调用
    if self.msg != 0:
      print '''Hello %s,
    you are from %s
    you are %s years old
    you are %s
    your job is %s.
    Am i right?''' %(self.Name,self.Country,self.Age,self.Sex,self.Job)
  def skill(self):
    if self.Job == 'IT Engineor':
      print '''To be IT Engineor,you must many skills:\n
    1.Linux
    2.shell
    3.database
    4.python
    '''
  def action(self):
    if self.msg != 2:
      print 'call this fuction!!'
    else:
      pass
class love(person):#继承父类peson信息,写恋爱史
  def __init__(self,number_of_friends,name,nationality,age,sex,job):
    person.__init__(self,name,nationality,age,sex,job)#继承父类信息
    self.number = number_of_friends
  def interaction(self):
    first_lover = raw_input("please input your first love's name:")
    first_age = raw_input("how oid are you?")
    status = raw_input("what is your current status:?")
    self.status = status
    self.talk(2)
    year_gap = int(self.Age) - int(first_age)
    print '''\nAnd your personal relationships as folloe:
    your met your first when you were %s,her name is %s
    now you are %s,but %s years later,now xx years past ,you still in love with her!you have % friends'''% (first_age,first_lover,status,year_gap,self.number)
#p = person('xuweibo','CN','19','Malse','IT Engineor')
p2 = love(2,'xuweibo','CN','76','Malse','IT Engineor')
p2.interaction()
'''
#--------绑定实例-------------
p = person('xuweibo','CN','19','Malse','IT Engineor')
p.talk(1)
p.skill()
p.action()
#----------------------------
#----------不绑定实例-------------------
#person('xuweibo','CN','19','Malse','IT Engineor').talk(2)
#person('xuweibo','CN','19','Malse','IT Engineor').skill()
#--------------------------------------
'''
root@kali:~/python/mod#

运行:

root@kali:~/python/mod#
root@kali:~/python/mod# python class2.py
please input your first love's name:cuihua
how oid are you?21
what is your current status:?sigle
Hello xuweibo,
    you are from CN
    you are 76 years old
    you are Malse
    your job is IT Engineor.
    Am i right?
And your personal relationships as folloe:
    your met your first when you were 21,her name is cuihua
    now you are sigle,but 55 years later,now xx years past ,you still in love with her!you have 2.000000riends
root@kali:~/python/mod#

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


本文标题:如何在Python中使用类的继承-创新互联
文章位置:http://bjjierui.cn/article/ddhgod.html

其他资讯