我试图在这3个类之间做一些基本的继承,并使用一些简单的方法,我希望了解它们之间的正确结构以及可以改进的结构。
class Animal:
def __init__(self, kind, place):
self.kind = kind
self.place = place
#This class inherits kind and place arguments from Animal class (which can work for any animal)
#Initiates a Dog object with name, gender and
我不确定父类的对象是如何用Python创建的。考虑下面的场景。
class Animal():
def __init__(self):
print("Animal is created")
def eat(self):
print("I am eating")
class Dog(Animal):
def __init__(self, breed, name, spots):
self.breed = breed
self.name = name
sel
我有这段代码,我想弄清楚这是怎么回事
class Animal(object):
population = 0
def __init__(self, name):
self.name = name
def __str__(self):
return "I am an instance of {}. ".format(self.__class__, self.name)
def __repr__(self):
return self.__str__()
def make_sound(sel
class animal(object):
def __init__(self,name):
self.name = name
def eat(self,food):
print("{} is eating".format(self.name,food))
class dog():
def fetch(self,thing):
print("{} get the {}".format(self.name,thing))
s = dog('r')
错误:回溯(最近一
对不起,我不久前才开始学习python,我被这个程序代码卡住了,我就是不能让它像它应该的那样工作。
class Dog():
def __init__(self,name,breed,owner):
self.name = name
self.breed = breed
self.owner = owner
class Person():
def __init__(self,name):
self.name = name
mick = Person("Mick Jagger")
dog = D
下面我很难辨别这两个例子的优点和缺点。最理想的情况是,我想知道哪一个是最好的设计:
示例1(类型属性):
public abstract class Animal : /* all relevant interfaces*/
{
/*
All necessary implementations
*/
}
Public class Dog : Animal
{
Public string Name {get; set;}
Public Breed Type {get; set;}
/*
All necessary implementa
有人能帮我纠正这个错误吗?谢谢(我正在尝试访问daughter类的母类中的一个变量) class Animal:
def __init__(self, name):
self.name = name
class Mammal:
def Presentation(self):
print(self.name + "is a mammal")
dog = Animal("Dog")
dog.Mammal.Presentation(