- 모듈의 확장자 : .py
- 같은 장소에 있는 모듈만 사용 가능
- import 사용할_모듈
#theater_module.py
def price(people):
print("{0}명 가격은 {1}원 입니다.".format(people, people * 10000)
def price_morning(people):
print("{0}명 조조 할인 가격은 {1}원 입니다.".format(people, people * 7000)
def price_soldier(people):
print("{0}명 군인 할인 가격은 {1}원 입니다.".format(people, people * 5000)
#case1
import theater_module
theater_module.price(3)
theater_module.price_morning(4)
theater_module.price_soldier(5)
#case2_별명으로 모듈 import
import theater_module as tm
tm.price(3)
tm.price_morning(4)
tm.price_soldier(5)
#case3_해당 모듈의 전체 함수 import
from theater_module import *
price(3)
price_morning(4)
#case4_해당 모듈의 일부 함수 import
from theater_module import price, price_morning
price(3)
price_morning(4)
#case5_해당 모듈의 특정 함수를 별명으로 import
from theater_module import price_soldier as price
price(5)
-출처-