mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): add brief explanation for decorators in getters and setters lesson (#65888)
Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
+3
-1
@@ -21,7 +21,9 @@ When you use a method, you always have to call it with parentheses. But with a p
|
||||
|
||||
For example, you might want to calculate a value or check that a new value is valid before saving it. Instead of calling a method for that, you can use an attribute-like way to do that.
|
||||
|
||||
To create a property, you define a method and place the `@property` decorator above it. This tells Python to treat the method as a property.
|
||||
In Python, a decorator is a function that modifies the functionalities of other functions, or classes, without changing their original code.
|
||||
|
||||
While it is possible to create custom decorators, this is beyond the scope of this lesson. Just know that to create a property, you define a method and place the `@property` decorator above it. This turns the method into a property, so it can be accessed like an attribute while internally calling the decorated method.
|
||||
|
||||
That takes us to getters. Here's how to create one with the `@property` decorator:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user