python - 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()
解决方案
使用Employee_1.salary
而不是Employee_1.salary()
.
推荐阅读
- asp.net-mvc - 我在 ASP.NET MVC 5 中尝试了 Bootstrap DateTimePicker,但它不起作用
- android - 我在哪里可以找到android中定义的颜色
- c# - 如何在 .NET Core 中上传到 Google Cloud Storage 之前生成预签名 URL?
- python - 列表中的乳胶表达式
- java - Java Jackson 异常:嵌套异常是 java.lang.VerifyError
- xampp - Testlink 安装问题 $tlCfg->results['status_code'] = array (
- c - 执行 execlp 调用时显示的控制台行
- python - 使用 setup.py 文件从 Github 安装代码
- printing - 有没有办法查看日志并保存正在打印的内容(从打印机或我的电脑)
- node.js - 当元素在视图中时触发 vue-typed-js 动画