-1
#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)
4

2 回答 2

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)
于 2013-05-24T14:35:30.120 回答
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)
于 2013-05-24T14:36:48.553 回答