python - <__main__.Employee 对象位于 0x000001E32362C1F0>
问题描述
class Employee:
def __init__(self,first,last,salary):
self.first = first
self.last = last
self.salary = salary
emp_1 = Employee("Rohan","Parab",100000)
print(emp_1)
解决方案
您需要实现该__str__
方法,否则它将打印(您可能已经观察到)对象位置。
例如:
def __str__(self):
return f"First Name: {self.first}, Last Name {self.last}, Salary {self.salary}"
推荐阅读
- javascript - 重构此代码的最佳方法是什么?
- cesium - 获取用户选择的基础层
- structure - 没有目录结构的压缩文件夹
- angularjs - Typescript 中的控制器继承与缩小导致错误:$injector:unpr Unknown Provider
- javascript - Firefox:添加自定义键盘快捷方式,例如使用“显示密码”打开“保存的登录”
- python-3.x - 如何使用Selenium Python提取属性图片列表的值
- c# - 行为类似于 OpenFileDialog 的 OpenDatabaseForm
- git - 如何提交两个分支的“git diff”?
- python - 除了特定的文本块外,如何将行写入新文件?
- android - 在 EditText 中间显示选择