• 필요한 것들끼리 부품처럼 만들어진 파일
  • 같은 파이썬 디렉토리에 있어야 사용할 수 있다.

# 일반 가격 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))

import theater_module theater_module.price(3) # 3명이 영화를 보는 가격 theater_module.price_morning(4) # 4명이 조조할인영화를 보는 가격 theater_module.price_soldier(5) # 5명이 군인할인영화를 보는 가격

출력값은 다음과 같다.

3명 가격은 30000원입니다. 4명 조조 할인 가격은 24000원입니다. 5명 군인 할인 가격은 20000원입니다.

  • theater_module을 mv라는 별명으로 호출
import theater_module as mv mv.price(3) mv.price_morning(4) mv.price_soldier(5)

출력값은 다음과 같다.

3명 가격은 30000원입니다. 4명 조조 할인 가격은 24000원입니다. 5명 군인 할인 가격은 20000원입니다.

from theater_module import * price(3) price_morning(4) price_soldier(5)

출력값은 다음과 같다.

3명 가격은 30000원입니다. 4명 조조 할인 가격은 24000원입니다. 5명 군인 할인 가격은 20000원입니다.

  • 군인할인가격 없이 일반과 조조할인 가격만 호출하겠다.
from theater_module import price, price_morning price(3) price_morning(4) price_soldier(6)

출력결과는 다음 결과처럼 price_soldier에 대해 오류가 발생한다.

price_soldier(6) NameError: name 'price_soldier' is not defined 3명 가격은 30000원입니다. 4명 조조 할인 가격은 24000원입니다.

  • price_soldier를 price라는 별명으로 호출하겠다.
from theater_module import price_soldier as price price(3)

출력값은 다음과 같다.

3명 군인 할인 가격은 12000원입니다.