프로그래밍 언어/Python

[Python] 수학 (math) 함수

ShovelingLife 2024. 1. 26. 11:08

파이썬 내(built-in)에 구현되어 있는 함수 표

 

함수 출력 결과

print(abs(-3)) #절대값 출력
 
print(abs(-3.5)) #절대값 출력
 
print(max(2, 3, 4, 6)) #최대값 출력
 
print(min(2, 3, 4)) #최소값 출력
 
print(pow(2,3)) # 2^3 (= 2**3)
 
print(round(3.51)) #반올림
 
print(round(3.1456, 3)) #소수점 3번째 아래를 반올림

수학 (math) 함수

- 파이썬은 수학(math) 모듈을 통해 많은 수학 함수(mathmatical funtions)들을 제공한다.

- 파이(pi)와 자연상수 e 도 math 모듈을 통해 이용할 수 있다. ex) math.pi, math.e

 

수학적 함수(mathmetical funtions) 표

import math
 
print("exp(1.0) = ",math.exp(1))
print("log(2.78) = ",math.log(math.e))
print("log10(10,10) = ",math.log(10,10))
print("sqrt = ",math.sqrt(4.0))
 
print("sin(PI/2) = ",math.sin(math.pi / 2))
print("cos(PI/2) = ",math.cos(math.pi / 2))
print("tan(PI/2) = ",math.tan(math.pi / 2))
print("degrees(1.57) = ",math.degrees(1.57))
print("radians(90) = ",math.radians(90))

 

https://andamiro25.tistory.com/12