curriculum/challenges/english/blocks/workshop-salary-tracker/68c28d659d345270d4a61084.md
The __repr__ method is a special method that is supposed to return a string representation of the object that can be used to instantiate it.
For example, the __repr__ method of Employee('Charlie', 'developer') should return the string Employee('Charlie', 'developer'), which is the same string used to create the object.
Give your Employee class a __repr__ method with a self parameter, and make it return a string that can be used to instantiate the object.
Your Employee class should have a __repr__ method with a self parameter.
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_function("__repr__").has_args("self")`)) })
Your __repr__ method should return the string used to instantiate the object.
({ test: () => runPython(`
empl = Employee("Frank", "dreamer")
assert repr(empl) == 'Employee("Frank", "dreamer")' or repr(empl) == "Employee('Frank', 'dreamer')"
`) })
class Employee:
def __init__(self, name, level):
self._name = name
self._level = level
--fcc-editable-region--
def __str__(self):
return f'{self.name}: {self.level}'
--fcc-editable-region--
@property
def name(self):
return self._name
@property
def level(self):
return self._level
charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)