Python public attributes are better getter-setter
Introduction
Goal
class OldResistor:
def __init__(self, ohms):
self._ohms = ohms
def get_ohms(self):
return self._ohms
def set_ohms(self, ohms):
return self._ohms = ohms
if __name__ == "__main__":
r0 = OldResistor(50e-3)
print(f"이전: {r0.get_ohms()}")
r0.set_ohms(10e3)
print(f"{r0.get_hms()}") Review
Summary
PreviousClosure: Lazy Evaluation And Eager EvaluationNextNo refactoring attribute, we can use property decorator
Last updated