-
파이썬 상속 (Inheritance)Engineering WIKI/Python 2022. 5. 23. 21:51
Inheritance.py
class Country: """Super Class""" name = '국가명' population = '인구' capital = '수도' def show(self): print('국가 클래스의 메소드입니다.') class Korea(Country): """Sub Class""" def __init__(self, name, population, capital): self.name = name self.population = population self.capital = capital def show_name(self): print('국가 이름은 : ', self.name) def show_population(self): print('국가 인구수는 :', self.population) def show_capital(self): print('국가의 수도는 :', self.capital)
inheritance_main.py
from inheritance import * a = Korea('대한민국', '50000', '서울') a.show() # 국가 클래스의 메소드입니다. a.show_name() # 국가 이름은 : 대한민국 a.show_population() # 국가 인구수는 : 50000 a.show_capital() # 국가의 수도는 : 서울
'Engineering WIKI > Python' 카테고리의 다른 글
파이썬 람다식 (0) 2022.05.25 파이썬 퀵 정렬 (0) 2022.05.25 Python3 vs Pypy3 (0) 2022.05.25 Python TDD (0) 2022.05.23 유사 딕셔너리 defaultdict() 활용법 (0) 2022.05.19 문자열 split() 과 split(" ") 차이 (0) 2022.05.19 함수 주석 (0) 2022.05.17 any, all 함수 (0) 2022.05.17