首页 > 解决方案 > <__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)

标签: pythonpython-3.x

解决方案


您需要实现该__str__方法,否则它将打印(您可能已经观察到)对象位置。

例如:

def __str__(self):
    return f"First Name: {self.first}, Last Name {self.last}, Salary {self.salary}"

推荐阅读