1. 사용자 모듈

소스파일처럼 다른파일에서 선언된 함수를 불러와 사용

 

모듈파일

#circle.py

PI = 3.14

def ar_circle(rad):
    return rad * rad * PI

def ci_circle(rad):
    return rad * 2 * PI

 

실행파일1

#main1.py

import circle as c  # 모듈이름을 c로 선언


def main() :
    print('둘레 : ', c.ar_circle(3)) # circle의 ar_circle 호출
    print('넓이 : ', c.ci_circle(3)) # circle의 ci_circle 호출

main()

 

실행파일2

#main2.py

from circle import ar_circle # 모듈 cirle에서 ar_circle 함수사용선언
from circle import ci_circle # 모듈 cirle에서 ci_circle 함수사용선언


def main() :
    print('둘레 : ', ar_circle(3)) # 모듈이름빼고 사용가능
    print('넓이 : ', ci_circle(3)) # 모듈이름빼고 사용가능

main()

 

 

2. 빌트인 모듈

파이썬 설치시 기본적으로 제공되는 모듈

import math

math.pi
3.141592653589793

[ math 모듈 함수 ]

math.pi
math.e
math.sin(x)
math.cos(x)
math.tan(x)
math.asin(x)
math.acos(x)
math.atan(x)
math.log(x)
math.log10(x)
math.log2(x)
math.exp(x)
math.sqrt(x) : 루트
math.fabs(x) : 절대값
math.degrees(x) : radians to degrees
math.radians(x) : degrees to radians

'Python > 기초이론' 카테고리의 다른 글

Python - 클래스  (0) 2023.02.13
Python - 딕셔너리  (0) 2023.02.12
Python - 함수  (0) 2023.02.11
Python_참고 - tuple, list 함수  (0) 2022.12.25
Python - range  (0) 2022.12.25

+ Recent posts