Product 클래스부터 정의해 봅시다.

    class Product:
        def __init__(self, n, p, s):
            self.name, self.price, self.stock = n, p, s
    
        def information(self):
            print('상품이름 :', self.name)
            print('상품가격 :', self.price)
            print('재고수량 :', self.stock)

    Product 클래스에 생성자 __init__() 메서드를 작성했습니다. __init__() 메서드는 객체를 만들 때 상품이름, 상품가격, 재고수량을 전달받아 각 객체의 인스턴스 속성(self.name, self.price, self.stock)에 저장합니다. 상품의 정보를 알려주는 메서드 information()도 추가했습니다. 이렇게 상품 클래스가 완성됐습니다.

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.