파이썬 모듈
# 파이썬 모듈
# Module : 함수, 변수, 클래스 등 파이썬 구성 요소 등을 모아놓은 파일
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
def powewr(x, y):
return x ** y
print('-' * 15)
print('called! inner')
print(add(5,5))
print(subtract(15,5))
print(multiply(5,5))
print(divide(10,2))
print(powewr(5,3))
print('-' * 15)
# __name__ 사용하는 이유 : 메인에서만 사용하고 다른 곳에서 실행 시 해당 결과가 실행이 안됨
#if __name__ == "__main__":
# print('-' * 15)
# print('called! __main__ ')
# print(add(5,5))
# print(subtract(15,5))
# print(multiply(5,5))
# print(divide(10,2))
# (powewr(5,3))
# print('-' * 15)
모듈 사용
# 모듈 사용 실습
import sys
print(sys)
print(sys.path)
print(type(sys.path))
# 모듈 경로 삽입
# sys.path.append('/Users/nhn/Desktop/math')
# print(sys.path)
# import test_module
# 모듈 사용
# print(test_module.power(10, 3))