开始使用免费开始使用

使用 @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: {____.____}"
编辑并运行代码