[python] 자주 사용하는 외부 모듈

Song A·2024년 6월 14일

수학관련 기본 함수

listVar = [1,25,3,6,7]
# 합
print(sum(listVar))

# 최댓값
print(max(listVar)) # 25

# 최소값
print(min(listVar)) # 1

# 거듭제곱
print(pow(13,2)) # 13^(2)

# 반올림
print(round(13.43538,2)) # 13.44

math 모듈

수학 관련 모듈

import math

# 절댓값
print(math.fabs(-10)) # 10

# 올림
print(math.ceil(5.21)) # 6
print(math.ceil(-5.21)) # -5

# 내림
print(math.floor(5.21)) # 5
print(math.floor(-5.21)) # -6

# 버림
print(math.trunc(5.21)) # 5
print(math.trunc(-5.21)) # 5

# 최대 공약수
print(math.gcd(14,21)) # 7

# 팩토리얼
print(math.factorial(10)) # 10!

# 제곱근
print(math.sqrt(4)) # 2

random 모듈

난수 관련 모듈

time 모듈

시간 관련 모듈

import time

lt = time.localtime()
# 현재 시간
print(lt)

print(lt.tm_year) # 년
print(lt.tm_mon) # 월
print(lt.tm_mday) # 일
print(lt.tm_hour) # 시
print(lt.tm_min) # 분
print(lt.tm_sec) # 초
print(lt.tm_wday) # 요일 (월 - 0)
profile
진행중

0개의 댓글