theater_module.py

# 일반 가격

def price(people):

    print("{0}명 가격은 {1}원 입니다.".format(people, people * 10000))

 

# 조조할인 가격

def price_morning(people):

    print("{0}명 조조 할인 가격은 {1}원 입니다.".format(people, people * 6000))

 

 # 군인 할인 가격

def price_soldier(people):

    print("{0}명 군인 가격은 {1}원 입니다.".format(people, people * 4000))

-------------------------------------------------------------------------------------------------------

 

module.py

import theater_module # 같은 패키지내에 있으면 해당 파일 명으로 모듈 호출

theater_module.price(3)  # 3명이서 영화 보러 갔을 때 가격

theater_module.price_morning(4)  # 4명이서 조조 할인 영화 보러 갔을 때

theater_module.price_soldier(5)  # 5명의 군인이 영화 보러 갔을 때

 

import theater_module as mv  # as 를 이용해 별명으로 간편하게 호출

mv.price(3)  # 3명이서 영화 보러 갔을 때 가격

mv.price_morning(4)  # 4명이서 조조 할인 영화 보러 갔을 때

mv.price_soldier(5)  # 5명의 군인이 영화 보러 갔을 때mv

 

from theater_module import * # * 호출시 함수명만으로 호출가능

price(3)

price_morning(4)

price_soldier(5)

 

from theater_module import price, price_morning # 일부모듈만 사용할 시

price(3)

price_morning(4)



from theater_module import price_soldier as price # 일부모듈만 사용할 시

price(3)

 

 

 

'Python' 카테고리의 다른 글

Python- pip install  (0) 2020.07.08
Python-패키지 사용법  (0) 2020.07.08
Python-init  (0) 2020.07.05
Python-class (스타크래프트 예시)  (0) 2020.07.05
Python-super  (0) 2020.07.05

+ Recent posts