#C:/Python32
class Person:
def __init__(self, name = "joe" , age= 20 , salary=0):
self.name = name
self.age = age
self.salary = salary
def __printData__(self):
return " My name is {0}, my age is {1} , and my salary is {2}.".format(self.name, self.age, self.salary)
print(Person)
class Employee(Person):
def __init__(self, name, age , salary ):
Person. __init__ (self,name = "Mohamed" , age = 20 , salary = 100000)
def __printData__(self):
return " My name is {0}, my age is {1} , and my salary is {2}.".format(sef.name, self.age, self.salary)
print(Employee)
答案 0 :(得分:0)
你需要在这里缩进第二行,来自:
def __printData__(self):
return " My name is {0}, my age is {1} , and my salary is {2}.".format(sef.name, self.age, self.salary)
为:
def __printData__(self):
return " My name is {0}, my age is {1} , and my salary is {2}.".format(sef.name, self.age, self.salary)
答案 1 :(得分:0)
您需要缩进倒数第二行,因为它位于函数定义之后。此外,您曾使用sef
代替self
。我已经纠正了以下两个方面:
class Person:
def __init__(self, name = "joe" , age= 20 , salary=0):
self.name = name
self.age = age
self.salary = salary
def __printData__(self):
return " My name is {0}, my age is {1} , and my salary is {2}.".format(self.name, self.age, self.salary)
print(Person)
class Employee(Person):
def __init__(self, name, age , salary ):
Person. __init__ (self,name = "Mohamed" , age = 20 , salary = 100000)
def __printData__(self): # The problem was the line after this one.
return " My name is {0}, my age is {1} , and my salary is {2}.".format(self.name, self.age, self.salary)
print(Employee)