본문으로 바로가기

모듈

category onYouTube/Python 2021. 3. 15. 12:08

- 모듈의 확장자 : .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)

 

 

-출처-

www.youtube.com/watch?v=kWiCuklohdY&t=20113s

'onYouTube > Python' 카테고리의 다른 글

내장함수  (0) 2021.03.15
패키지  (0) 2021.03.15
Finally  (0) 2021.03.14
에러 발생시키기  (0) 2021.03.14
예외 처리  (0) 2021.03.14