divmod( )
두 개의 숫자를 인자로 받아, 나눠지는 수를 나누는 수로 나눈 몫과 나머지를 튜플 형식으로 반환하는 함수
>> divmod(num1, num2)
( num1//num2, num1%num2 )
divmod( ) 와 %, // 차이는?
divmod( )보다 %, // 연산 수행 시 더 많은 Opcode(명령코드) 실행
=> 인자값의 크기가 그렇게 크지 않은 경우 %, // 연산이 더 빠르지만,
인자값의 크기가 매우 커지면 divmod( ) 연산이 더 빠르다.
내용 참고 :
https://stackoverflow.com/questions/30079879/is-divmod-faster-than-using-the-and-operators
Is divmod() faster than using the % and // operators?
I remember from assembly that integer division instructions yield both the quotient and remainder. So, in python will the built-in divmod() function be better performance-wise than using the % and //
stackoverflow.com
'프로그래밍 > Python' 카테고리의 다른 글
프로그래머스_python lv0. 중앙값 구하기 (0) | 2023.01.06 |
---|---|
프로그래머스_python lv0. 나머지 구하기 (0) | 2023.01.05 |
프로그래머스 lv0. 배열 두 배 만들기 (0) | 2023.01.04 |
프로그래머스 lv0. 두 수의 곱 (0) | 2023.01.03 |
프로그래머스 lv0. 몫 구하기 (0) | 2023.01.02 |