[Python] divmod() 함수
divmod() 활용 예시 프로그래머스 Lv1~Lv2 (백준 기준 브론즈~실버) 코테에서 가독성 높이기용 보조 함수로 자주 등장“몫과 나머지를 동시에 써야 할 때”는 항상 divmod()가 더 깔끔 1. 시간 계산에 활용 (초를 분과 초로 변환)총 시간을 분과 남은 초로 나누어 계산할 때 유용합니다.# 초(total_seconds)를 분(minutes)과 초(seconds)로 변환하는 예제# divmod(x, y)는 (x // y, x % y) 형태의 튜플을 반환함examples = [45, 60, 125, 350, 601, 1234, 3599]for total_seconds in examples: minutes, seconds = divmod(total_seconds, 60) print(..
2025. 11. 12.