未定义变量:def__init__(self)

Undefined Variable :def__init__(self)

我无法在 Python 3.8 中声明构造函数。我无法声明构造函数。系统显示错误信息:

"Undefined Variable" and "illegal target for annotations.
class Employee:
    def__init__(self,name,id):
        self.name = name
        self.id = id
    def dispaly(self):
        print("ID: %d\nName: %s"%(self.id,self.name))

emp1 = Employee("Robert",101)
emp1.dispaly()

您在 def__init__ 关键字之间缺少一个 space。
正确方法:

class Employee:

    def __init__(self, name, id):
        self.name = name
        self.id = id

    def display(self):
        print("Employee Name is {} and ID is {}.".format(self.name, self.id))

emp1 = Employee("Robert", "E001")
emp1.display()