Coding/Python

[python] 클래슀(pass, super)

κΉ€μœ λ‹ˆμ½˜ 2021. 11. 3. 13:04

#pass

#건물
class BuildingUnit(Unit):
def __init__(self, name, hp, location):
pass #일단 λ„˜μ–΄κ°„λ‹€.

#μ„œν”ŒλΌμ΄ 디폿 : 건물 1개 있으면 8 μœ λ‹› 생성
supply_depot = BuildingUnit("μ„œν”ŒλΌμ΄ 디폿", 500, "7μ‹œ")



#Another example
def game_start():
print("[μ•Œλ¦Ό] μƒˆλ‘œμš΄ κ²Œμž„μ„ μ‹œμž‘ν•©λ‹ˆλ‹€.")


def game_over():
pass

 

 

============

 

Super

 

class Flyable:
def __int__(self):
print("FlyableFF μƒμ„±μž")

class Unit:
def __init__(self):
print("Unit μƒμ„±μž")



class FlyableUnit(Unit, Flyable):
def __init__(self):
#super().__init__() #superλ₯Ό μ“Έ 땐, λ§ˆμ§€λ§‰ 상속 λ°›λŠ” 것에 λŒ€ν•œ init ν•¨μˆ˜κ°€ ν˜ΈμΆœλœλ‹€
Unit.__init__(self)
Flyable.__init__(self)

#λ“œλžμ‰½
dropship = FlyableUnit()

 

 

???μ™œ μ•ˆλ˜μ§€