Misc/Python 문법

[python] math 모듈

foreverWon 2025. 8. 9. 11:00
목차

    1. math.gcd(a, b)

    • 최대공약수(GCD)를 구함
    • 예: math.gcd(12, 15) -> 3
    • 최소공배수
      • (a*b) / gcd(a, b)

    2. math.factorial(n)

    • n! (팩토리얼) 계산
    • 예: math.factorial(5) -> 120

    3. math.sqrt(x)

    • 제곱근 반환
    • 예: math.sqrt(16) -> 4.0

    4. math.isqrt(n) (파이썬 3.8 이상)

    • 정수 제곱근 (소수점 버림)
    • 예: math.isqrt(10) -> 3

    5. math.ceil(x)

    • 올림 함수 (소수점 위로 올림)
    • 예: math.ceil(4.2) -> 5

    6. math.floor(x)

    • 내림 함수 (소수점 아래로 내림)
    • 예: math.floor(4.8) -> 4

    7. math.pow(x, y)

    • 거듭제곱 (x^y) 반환, float 반환
    • 예: math.pow(2, 3) -> 8.0
    • (내장 pow()와 다르게 float 결과)

    8. math.log(x, base)

    • 로그 함수
    • 예: math.log(8, 2) -> 3.0

    9. math.sin(x), math.cos(x), math.tan(x)

    • 삼각함수 (라디안 단위)
    728x90

    'Misc > Python 문법' 카테고리의 다른 글

    스폐셜 메서드(Dunder Method)  (1) 2025.08.29
    map()  (0) 2024.10.20
    python 기초 문법  (0) 2024.09.28