我是这个堆栈溢出的新手,这是我在这里的第一个问题。我正在学习 python,但我遇到了继承问题。我认为我的代码是正确的,但它没有从派生/子类继承父/基类。我尝试了两种继承方式。它正在打印 Normalphones 类的全名,但不是 Smartphones。我的代码在这里。帮我。
class Normalphones: # base class/ parent class
def __init__(self, brand, model_name, price):
self.brand = brand
self.model_name = model_name
self._price = max(price, 0)
def full_name(self):
return f"{self.brand} {self.model_name}"
def make_a_call(self, number):
return f"Calling {number} ...."
class Smartphones: # derived class / child class
def __init__(self, brand, model_name, price, ram, internal_memory, rear_camera):
Normalphones.__init__(self, brand, model_name, price) # uncommom way to inherit
# super().__init__(brand, model_name, price)
self.ram = ram
self.internal_memory = internal_memory
self.rear_camera = rear_camera
noramalphone1 = Normalphones('Nokia', '1150', 1200)
smartphone1 = Smartphones('I-phone', '11 max pro', 90000, '6 Gb', '128 Gb', '48 MP')
print(noramalphone1.full_name())
print(smartphone1.full_name())