gpt4 book ai didi

python - 重写父类方法时的问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:47 26 4
gpt4 key购买 nike

<分区>

我正在 Codedemy 上学习 Python 类(class)。我在他们教授类和面向对象编程的部分。我正在为继承而苦苦挣扎。尝试覆盖父方法时收到此错误消息:

<bound method PartTimeEmployee.full_time_wage of <__main__.PartTimeEmployee object>>

在这段代码中:

class Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name

def calculate_wage(self, hours):
self.hours = hours
return hours * 20.00


class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00

def full_time_wage(self):
super(PartTimeEmployee, self).calculate_wage(self, hours)

milton = PartTimeEmployee("Milton")

print milton.full_time_wage

那么问题是什么?

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