Last active
May 14, 2018 14:09
-
-
Save developer-sdk/c34f8d3151fbe6fa7eed1f78d9775fb4 to your computer and use it in GitHub Desktop.
파이썬 클래스 상속, 메소드 오버라이딩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| class Info(): | |
| def __init__(self, name): | |
| self.name = '상품명: ' + name | |
| def __str__(self): | |
| return self.name | |
| def package_price(self): | |
| return self.price * 5 | |
| class Pencil(Info): | |
| def __init__(self, name): | |
| Info.__init__(self, name) | |
| self.price = 100 | |
| def package_price(self): | |
| return self.price * 12 | |
| class Remover(Info): | |
| def __init__(self, name): | |
| Info.__init__(self, name) | |
| self.price = 200 | |
| def __str__(self): | |
| return Info.__str__(self) + " 가격 " + str(self.price) + "원" | |
| p = Pencil('연필') | |
| r = Remover('지우개') | |
| print(p) | |
| print(r) | |
| print(p.package_price()) | |
| print(r.package_price()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Child(Base): | |
| def __init__(self, value, something_else): | |
| super().__init__(value) | |
| self.something_else = something_else |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment