math 패키지
2023. 2. 26. 15:27
math 패키지는 일련의 수학 함수 및 상수를 제공하는 Python의 기본 제공 패키지입니다.
삼각 함수, 지수 및 로그 함수, 반올림 및 천정 연산 등과 같은 일반적인 수학 연산을 위한 함수를 제공합니다.
수학 패키지는 "import math" 문을 사용하여 Python 스크립트로 가져올 수 있습니다.
수학 패키지에서 일반적으로 사용되는 일부 기능은 다음과 같습니다.
- math.pi: 이 상수는 원의 둘레와 지름의 비율인 파이(π) 값을 나타냅니다. 파이 값은 약 3.141592653589793입니다.
- math.sqrt(x): 숫자 x의 제곱근을 반환합니다.
- math.pow(x, y): x의 y승 값을 반환합니다.
- math.ceil(x): x보다 크거나 같은 가장 작은 정수를 반환합니다.
- math.floor(x): x보다 작거나 같은 가장 큰 정수를 반환합니다.
- math.sin(x): x 라디안의 사인
- math.cos(x): x 라디안의 코사인
- math.tan(x): x 라디안의 탄젠트
import math
# Calculate the area of a circle with radius 5
radius = 5
area = math.pi * math.pow(radius, 2)
print("Area of the circle:", area)
# Round a number up to the nearest integer
x = 3.14159
rounded_up = math.ceil(x)
print("Rounded up:", rounded_up)
# Calculate the sine of 45 degrees
degrees = 45
radians = math.radians(degrees)
sine = math.sin(radians)
print("Sine of 45 degrees:", sine)
'Python' 카테고리의 다른 글
class, class method 란? (0) | 2023.02.26 |
---|---|
random 패키지 (0) | 2023.02.26 |
for문 에서 2개의 인수를 받기 위한 enumerate 기능 (0) | 2023.02.26 |
날짜와 시간 (0) | 2023.02.08 |
format method (0) | 2023.02.08 |