【问题标题】:Object-Oriented Programming / python3 Classes面向对象编程/python3 类
【发布时间】:2019-02-25 07:31:59
【问题描述】:

我需要创建我的类的实例并调用创建的方法,该怎么做?我搜索但没有找到我需要的确切答案。谢谢

class Chemise:
    def __init__(self,ID,Prix,Couleur,Description,Quantite):
        self.ID=ID
        self.Prix=Prix
        self.Couleur=Couleur
        self.Description=Description
        self.Quantite=Quantite

    def Ajout_chemise(self,valeur):
        self.Quantite+=valeur

    def Diminuer_chemise(self,valeur):
        self.Quantite-=valeur

    def Affiche_info(self):
        print('ID=',self.ID);print('Prix=',self.Prix);print('Couleur=',self.Couleur)
        print('Description=',self.Description);print('Quantite=',self.Quantite)

class Shirt(Chemise):
    ??????

【问题讨论】:

  • 在python中搜索继承,会得到很多结果
  • 如果您在 Google 上搜索“Python 类实例”这一短语,您会发现教程可以比我们在此处的答案中更好地解释它。

标签: python python-3.x oop


【解决方案1】:

如果你想创建一个实例,你可以这样做

c=Chemise()

然后调用任何你想要的方法

c.Affiche_info()

您目前正在做的是创建另一个继承自第一个类的类

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 2020-05-18
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2014-06-03
    • 1970-01-01
    相关资源
    最近更新 更多