[英]__init__() takes 3 positional arguments but 4 were given
class Patient(object):
'''
Attributes
name = Patient name
age = Patient age
conditions = Existing patient's conditions
'''
status='patient'#-----------class variable-------
def __init__(self,name,age):
self.name=name
self.age=age
self.conditions=[]
def get_details(self):
print(f'Patient record: {self.name}, {self.age} years.'\
f'Current information: {self.conditions}.')
def add_info(self,information):
self.conditions.append(information)
x=Patient('Yash',21)
y=Patient('Raj',19)
class Infant(Patient):
def __init__(self,name,age):
self.vaccinations=[]
super().__init__(self,name,age)
def add_vac(self,vaccine):
self.vaccinations.append(vaccine)
def get_details(self):
print(f'Patient record: {self.name}, {self.age} years.'\
f'Patient has had {self.vaccinations} vaccines.'\
f'Current information: {self.codition}.'\
f'\n{self.name} IS AN INFACT, HAS HE HAD ALL HIS CHEAKS?')
ash=Infant('Yash',21)
ash.add_vac('MMR')
print(ash.get_details())
class Patient(object):
'''
Attributes
name = Patient name
age = Patient age
conditions = Existing patient's conditions
'''
status='patient'#-----------class variable-------
def __init__(self,name,age):
self.name=name
self.age=age
self.conditions=[]
def get_details(self):
print(f'Patient record: {self.name}, {self.age} years.'\
f'Current information: {self.conditions}.')
def add_info(self,information):
self.conditions.append(information)
x=Patient('Yash',21)
y=Patient('Raj',19)
class Infant(Patient):
def __init__(self,name,age):
self.vaccinations=[]
super().__init__(name,age);
def add_vac(self,vaccine):
self.vaccinations.append(vaccine)
def get_details(self):
print(f'Patient record: {self.name}, {self.age} years.\
Patient has had {self.vaccinations} vaccines.\
Current information: {self.conditions}.\
{self.name} IS AN INFACT, HAS HE HAD ALL HIS CHEAKS?')
ash=Infant('Yash',21)
ash.add_vac('MMR')
print(ash.get_details())
這僅適用於 ash 實例 ok,x,y 是另一個實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.