We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 670c14c commit 1e1728dCopy full SHA for 1e1728d
1 file changed
tutorials/Lecture3.md
@@ -39,6 +39,21 @@ Setters and getters are special methods used in object-oriented programming to a
39
- A setter is a method that sets (updates) the value of a private attribute.
40
- It allows you to validate or restrict changes before updating the attribute.
41
42
+```python
43
+ @property
44
+ def led_light_state(self):
45
+ # method overloading polymorphism in this class
46
+ return self.value()
47
+
48
+ @led_light_state.setter
49
+ def led_light_state(self, value):
50
51
+ if value == 1:
52
+ self.off()
53
+ elif value == 0:
54
+ self.on()
55
+```
56
57
### Why Use Setters & Getters
58
- Encapsulation: Protects the internal state of the object.
59
- Validation: Allows you to add checks before changing values.
0 commit comments