Its not entirely clear if you are experimenting with repr and str, or whether your issue is with the object instantiation.
If it’s the latter L.A.P is right as you are creating and object with attributes but not calling them. Even though you’ve provided the attributes for that Employee, you’ve not mentioned them when printing. It’s like saying ‘create an Employee and then print them’. But Python needs ‘create an Employee and print their full name’.
I suspect you actually wanted to call the functions you’ve defined to manage these attributes. So again you need to tell Python to ‘print the Employee and the function that defines their full name’. (That’s not technically accurate but you get the idea).
class Employee():
raise_amt = 1.04
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + "." + last + "@company.com"
def fullname(self):
return f"{self.first} {self.last}"
def __repr__(self):
return f"{self.first} {self.last} {self.pay}"
def __str__(self):
return f"{self.fullname}"
emp_1 = Employee("Corey", "Schafer", 50000)
print(emp_1.fullname())
print(emp_1.__repr__())
Given what you are trying to do, you might want to consider a dict data structure with key, value pairs. I’ve appended it here but it would be best to deal with it in the init
I think people on the thread are close but it’s simply this:
return f"{self.fullname()}"
Rather than what you have which is:
return f"{self.fullname}"
See the difference? With the two tiny little () after fullname python doesn’t know that you want to call the fullname function. Python thinks you want to do something with the function and went and got it for you.