首页 > 解决方案 > Python - 当我调用实例时,Int 对象不是可调用错误?

问题描述

当我尝试创建类的实例时,我得到一个 int object is not callable 错误。从类似的问题来看,可能是由于命名?我不确定。

    class Employee:
    """Class to represent employee"""
    def __init__(self, first_name, last_name, salary):
       """Initialize employee."""
       self.fn = first_name
       self.ln = last_name
       self.salary = salary

    def give_raise(salary, amount=5000):
       """Raise salary by default amount unless other amount is specified."""
       self.salary += amount


    Employee_1 = Employee('john', 'doe', 50_000)

    Employee_1.salary()

标签: python

解决方案


使用Employee_1.salary而不是Employee_1.salary().


推荐阅读