python 中的意外参数

问题描述 投票:0回答:1
class Employee:
    def __int__(self, name, salary):
        self.name = name
        self.salary = salary

    def getsalary(self):
        print( self.salary)

rohan = Employee("Rohan","345500")
print(rohan.salary)
print(rohan.name)
#rohan.getsalary()

harry = Employee("Harry", "521000")
print(harry.salary)
print(harry.name)

能找到刚才说的那个意想不到的论点是什么问题。谁能解决这个问题或帮助我

输出:- 结果应该是 345500 罗汉 521000 哈利

python oop pycharm coder
1个回答
0
投票

这是

__init__
方法的拼写错误。

class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

    def getsalary(self):
        print( self.salary)

rohan = Employee("Rohan","345500")
print(rohan.salary)
print(rohan.name)
#rohan.getsalary()

harry = Employee("Harry", "521000")
print(harry.salary)
print(harry.name)
© www.soinside.com 2019 - 2024. All rights reserved.