实例一:

class Geese:
    ”’大雁类”’
    def __init__(self,beak,wing,claw):
        print(“我是大雁类!我有以下特征:”)
        print(beak)
        print(wing)
        print(claw)
    def fly(self,state):
        print(state)
”’**********调用方法**********”’
beak_1=”喙的基部较高,长度和头部的长度几乎相等”
wing_1=”翅膀长而尖”
claw_1=”爪子是蹼状的”
wildGoose=Geese(beak_1,wing_1,claw_1)
wildGoose.fly(“我飞行的时候,一会儿排成个人字,一会排成个一字”)

 

实列二:

class Geese:
    ”’雁类”’
    neck=”脖子较长”
    wing=”振翅频率高”
    leg=”腿位于身体的中心支点,行走自如”
    number=0
    def __init__(self):
        Geese.number+=1
        print(“\n我是第”+str(Geese.number)+”只大雁,我属于雁类!我有以下特征:”)
        print(Geese.neck)
        print(Geese.wing)
        print(Geese.leg)
list1=[]
for i in range(4):
    list1.append(Geese())
print(“一共有”+str(Geese.number)+”只大雁”)

 

实例三:

class TVshow:
    list_film=[“战狼2″,”红海行动”,”西游记女儿国”,”熊出没•变形记”]
    def __init__(self,show):
        self._show=show
    @property
    def show(self):
        return self._show
    @show.setter
    def show(self,value):
        if value in TVshow.list_film:
            self._show=”您选择了《” +value+ “》,稍后将播放”
        else:
            self._show=”您点播的电影不存在”
tvshow=TVshow(“战狼2”)
print(“正在播放:《”,tvshow.show,”》”)
print(“您可以从”,tvshow.list_film,”中选择要点播放的电影”)
tvshow.show=”红海行动”
print(tvshow.show)

 

实例四:

class Fruit:
    color=”绿色”
    def harvest(self,color):
        print(“水果是:”+color+”的!”)
        print(“水果已经收获……”)
        print(“水果原来是:”+Fruit.color+”的!”)
class Apple(Fruit):
    color=”红色”
    def __init__(self):
        print(“我是苹果”)
class Orange(Fruit):
    color=”橙色”
    def __init__(self):
        print(“\n我是橘子”)
apple=Apple()
apple.harvest(apple.color)
orange=Orange()
orange.harvest(orange.color)

 

实例五:

class Fruit:
    def __init__(self,color=”绿色”):
        Fruit.color=color
    def harvest(self,color):
        print(“水果是:”+self.color+”的!”)
        print(“水果已经收获……”)
        print(“水果原来是:”+Fruit.color +”的!”)
class Apple(Fruit):
    color=”红色”
    def __init__(self):
        print(“我是苹果”)
        super().__init__()
class Sapodilla(Fruit):
    def __init__(self,color):
        print(“\n我是人参果”)
        super().__init__(color)
    def harvest(self,color):
        print(“人参果是:”+color+”的!”)
        print(“人参果已经收获……”)
        print(“人参果原来是:”+Fruit.color +”的!”)
apple=Apple()
apple.harvest(apple.color)
sapodilla=Sapodilla(“白色”)
sapodilla.harvest(“金黄色带紫色条纹”)

 

实战一:

class Phone:
    ”’手机类”’
    def __init__(self,language=’英文’):
        if language==’英文’:
            print(“智能手机的默认语言为”+language)
        else:
            print(“将智能手机的默认语言设置为”+language)
Phone()
Phone(‘中文’)

 

实战二:

class Card:
    ”’信用卡类”’
    def __init__(self,number,code=”123456″):
        if code ==”123456″:
            print(“信用卡”+str(number)+”的默认密码为”+str(code))
        else:
            print(“重置信用卡”+str(number)+”的密码为”+str(code))
Card(“4013735633800642”)
Card(“40137835633800642″,”168779”)

 

实战三:

class SaleHandler:
    ”’销售管理类”’
    def __init__(self):
        self.__sale_data={
            “2”:[(‘T0001′,’笔记本电脑’),
                 (‘T0002′,’荣耀6X’),
                 (‘T0003′,’iPad’),
                 (‘T0004′,’荣耀V9’),
                 (‘T0005′,’MACBook’)]}
    def querySaleList(self,query_month):
        ”’根据输入月份,查询商品明细”’
        if query_month in self.__sale_data:
            print(“%s月份商品销售明细如下:”%query_month)
            for item in self.__sale_data[query_month]:
                print(“商品编写:%s 商品名称:%s”%item)
        else:
            print(“该月份没有销售数据或输入月份有误!”)
print(“——销售明细——“)
sh=SaleHandler()
while True:
    month=input(“请输入要查询的月份(例如1、2、3等):”)
    if month==’quit’:
        break

    sh.querySaleList(month)

 

原文地址:http://www.cnblogs.com/zhanlisi0613/p/16810354.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性