// education

객체지향 프로그래밍(OOP): 클래스, 인스턴스, 생성자(__init__) 및 캡슐화

데이터와 관련 기능을 하나로 묶어 프로그램의 재사용성과 유지보수성을 극대화하는 객체지향 프로그래밍(OOP) 기초를 학습합니다.


1. OOP 클래스 용어 사전 (Glossary)


2. 파이썬 클래스 선언 및 캡슐화 코드

class BankAccount:
    def __init__(self, owner: str, balance: float):
        self.owner = owner
        self.__balance = balance # 비공개 속성 (Encapsulation)

    def deposit(self, amount: float):
        if amount > 0:
            self.__balance += amount
            print(f"{amount:,}원 입금 완료 (잔액: {self.__balance:,}원)")

    def get_balance(self):
        return self.__balance

account = BankAccount("홍길동", 100000)
account.deposit(50000)
print(f"현재 잔액: {account.get_balance():,}원")
← 이전예외 처리(try-except-else-finally) 및 사용자 정의 예외 다음 →상속(Inheritance), 다형성 및 던더 매직 메소드(Dunder Methods)