curriculum/challenges/english/blocks/workshop-salary-tracker/68c27fa1697ceb7c578b2c9f.md
The @property decorator is used in Python to turn a method into a property. It is typically used to define getter methods, which are methods used to retrieve the value of an attribute:
class Person:
def __init__(self, name):
self._name = name
@property
def name(self):
return self._name
p = Person('Alice')
print(p.name) # Alice
Create a method named name with a self parameter and decorate it with @property. Inside the method, return self._name.
Your Employee class should have a name method with a self parameter.
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_function("name").has_args("self")`)) })
Your name method should be decorated with @property.
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_function("name").has_decorators("property")`)) })
Your name method should return self._name.
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_function("name").has_return("self._name")`)) })
--fcc-editable-region--
class Employee:
def __init__(self, name, level):
self._name = name
self._level = level
def __str__(self):
return f'{self._name}: {self._level}'
charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)
--fcc-editable-region--