본문 바로가기

Python

python 다중 상속

반응형


"""
다중 상속
"""

class Person(object):
def talk(self):
print('talk')

def run(self):
print('person run')

class Car(object):
def run(self):
print('car run')

# 다중 상속시 왼쪽부터 적용 된다, 메서드 오버라이드시 순서가 왼쪽부터 한번만 호출 된다.
# class Robot(Person, Car):
class Robot(Car, Person):
def fly(self):
print('fly')

robot = Robot()
robot.talk()
robot.run()
robot.fly()


반응형

'Python' 카테고리의 다른 글

타입 힌팅  (0) 2019.01.06
함수를 변수처럼 전달하기  (0) 2019.01.06
python class  (0) 2019.01.03
python command line args  (0) 2019.01.01
Python Basic  (0) 2019.01.01