
10/2 4, 5세션
ex) pd.DataFrame()
<패키지, 모듈>.<클래스>()
# 1. 클래스 선언(코드 작성)
# 은행 계좌 : Account (식별자) : balance, deposit(), withdraw()
class Account:
balance = 0
def depostit(self, amount):
self.balance += amount
def withdraw():
self.balance -= amount
# 2. 객체 생성(메모리 사용)
acc1 = Account() #대문자로 시작하므로 클래스임을 암시
acc2 = Account()
# 3. 메서드 호출(코드 실행)
acc1.withdraw(2000)
acc2.deposit(5000)
acc1.balance, acc2.balance
TIP! dir()
객체에 들어있는 변수, 메서드 목록 확인
스페셜 메서드 : 특별한 기능을 하는 메서드
생성자 메서드 : __init()__
# 1. 클래스 선언
class Account2:
def __init__(self, balance):
self.balance = balance
def deposit(self, amount):
self.balance += amount
클래스가 맞다!