gpt4 book ai didi

python - 子类构造函数抛出 TypeError : __init__() takes 2 positional arguments but 5 were given

转载 作者:太空宇宙 更新时间:2023-11-04 08:30:56 24 4
gpt4 key购买 nike

<分区>

这是我第一天使用 Python 学习类和继承,所以请对我温柔点。我有两个类,即 Person 和 Employee,其中 Employee 是 Person 的子类。

class Person:
def __init__(self, name, place, age, sex):
self.name = name
self.place = place
self.age = age
self.sex = sex

class Employee(Person):
def __init__(self, emp_id):
self.emp_id = emp_id

现在,我正在尝试创建类 Employee 的实例,如下所示:

In [9]: A = Employee('Jack', 'Rome', 23, 'M')
TypeError: __init__() takes 2 positional arguments but 5 were given

我做错了什么?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com