使用 @property 裝飾器
你已經練習過使用含有描述器的類別了,現在輪到你用 @property 裝飾器自行建立一個。加油!
本練習屬於課程
Python 物件導向程式設計進階
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
class BankAccount:
def __init__(self, email):
self.email = email
# Define and decorate a method to begin the process of
# creating a descriptor for the email attribute
@____
def ____(self):
return f"Email for this account is: {____.____}"