Ubah metode kelas menjadi properti yang nilainya dihitung satu kali dan kemudian di-cache sebagai atribut normal selama masa pakai instance. Mirip dengan property(), dengan tambahan caching. Berguna untuk properti komputasi mahal dari instance yang tidak dapat diubah secara efektif.
@functools.cached_property(func)
class DataSet:
def __init__(self, sequence_of_numbers):
self._data = tuple(sequence_of_numbers)
@cached_property
def stdev(self):
return statistics.stdev(self._data)