728x90
반응형

init 5

[ Python ] __all__ 사용해서 패키지의 모듈을 import 하는 방법.

travel package 의 thailand module class ThailandPackage: def detail(self): print("[태국 패키지 3박 5일] 방콕, 파타야 여행 (야시장 투어) 50만원")travel package 의 vietnam module class VietnamPackage: def detail(self): print("[베트남 패키지 3박 5일] 다낭 효도 여행 60만원")package를 import 하는 파일 # __all__ # from random import * from travel import * # 패키지 안에 포함된 것들 중에서 import 되기 원하는 것들만 공개하고 원하지 않는 것은 비공개 할 수 있다.(__init__) trip_to = vietn..

Python 2021.03.08

[ Python ] super()

# super # 일반 유닛 class Unit: def __init__(self, name, hp, speed=0): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 {2}]".format(self.name, location, self.speed)) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage, speed=0): Unit.__init__(self, name, hp, speed) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = d..

Python 2021.03.07

[ Python ] 다중 상속.

# 다중 상속 : 부모 클래스를 여러개 상속 받는. # 일반 유닛 class Unit: def __init__(self, name, hp): self.name = name self.hp = hp # 상속받을 때 '클래스명(상속받을 클래스명)' # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage): Unit.__init__(self, name, hp) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = damage def attack(self, location): print("{0} : {1} 방향으로 적군을 공격 합니다. [공격력 : {2}]".format( self.name, location, self..

Python 2021.03.07

[ Python ] 상속

# 상속 # 일반 유닛 class Unit: def __init__(self, name, hp): self.name = name self.hp = hp # 상속받을 때 '클래스명(상속받을 클래스명)' # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage): Unit.__init__(self, name, hp) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = damage def attack(self, location): print("{0} : {1} 방향으로 적군을 공격 합니다. [공격력 : {2}]".format( self.name, location, self.damage )) def damaged(s..

Python 2021.03.07

[ Python ] 클래스 생성자 선언

# 클래스 만들기 # __init__ : Python에서 사용되는 생성자 # marine이나 tank 같은 객체가 만들어질 때 자동으로 호출되는 부분. # 객체 : 클래스에 의해 만들어진. # marine, tank는 Unit 클래스의 '인스턴스'라고 한다. # ------------ 클래스 생성 시작 -------------- class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage print("{0} 유닛이 생성 되었습니다.".format(self.name)) print("체력 {0}, 공격력 {1}".format(self.hp, self.damage)) # ---..

Python 2021.03.07
728x90
반응형
LIST