시작하기무료로 시작하기

@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: {____.____}"
코드 편집 및 실행