<aside> <img src="/icons/arrow-left-line_orange.svg" alt="/icons/arrow-left-line_orange.svg" width="40px" />
//modul
def add(a,b):
return a+b
//print
import mod1
print(mod1.add(1,2))
//modul
def add(a,b):
return a+b
def div(a,b):
return a/b
//print
from mod1 import add //modul에서 원하는 함수만 가져옴
print(add(1,2))
//modul
def add(a,b):
return a+b
def div(a,b):
return a/b
print(add(1,4))
//print
import mod1 //modul에서 출력 코드까지 가져옴
print => 5
--------------------------------
def add(a,b):
return a+b
def div(a,b):
return a/b
if __name__ == "__main__": //실행할려는 파일명이 main이고, main에서만 해당 print가 가능하도록 설정
print(add(1,4))
//print
import mod1 //modul에서 출력 코드까지 가져옴
print => X
//modul - 서로 다른 디렉터리에 존재하는 경우
def add(a,b):
return a+b
def div(a,b):
return a/b
if __name__ == "__main__":
print(add(1,4))
//print
import sys
sys.path.append("C:\\github-repo\\python\\python 기초\\자료형\\__pycache__\\subFolder")
import mod1
print(mod1.add(1,3))
</aside>