언어 자료구조 알고리즘/프로그래밍 실습

[python] 상속 개요 - 책과 프로그래밍 책

언제나휴일 2020. 10. 30. 09:53
반응형

클래스 다이어그램

Book.py

#Book.py
class Book:
    def __init__(self,title, author, publisher, price):
        self.title = title
        self.author = author
        self.publisher = publisher
        self.price = price

ProgrammingBook.py

#ProgrammingBook.py
from Book import Book
class ProgrammingBook(Book):
    def __init__(self,title,author,publisher,price,language):
        Book.__init__(self,title,author,publisher,price)
        self.language = language

Main.py

from ProgrammingBook import ProgrammingBook

book =ProgrammingBook("디파","언휴","언제나휴일",5000,"파이썬")
print("제목:",book.title)
print("저자:",book.author)
print("출판사:",book.publisher)
print("가격:",book.price)
print("언어:",book.language)
반응형