• 회원가입
  • 로그인
  • 구글아이디로 로그인

[module] Python - math.remainder() 메서드 ★ - 나머지 반환. (= remainder메서드 = 리메인더)

1298  
목차
  1. math.remainder() 예제
  2. math.remainder() 정의
  3. math.remainder() 구문
  4. math.remainder() 예제

 

math.remainder() 예제 - x/y의 나머지

 

import math

print (math.remainder(10, 9)) # 1.0

print (math.remainder(11, 9)) # 2.0

print (math.remainder(12, 9)) # 3.0

print (math.remainder(13, 9)) # 4.0

print (math.remainder(14, 9)) # -4.0  (주의: 5.0 아님.)

print (math.remainder(15, 9)) # -3.0  (주의: 6.0 아님.)

print (math.remainder(16, 9)) # -2.0  (주의: 7.0 아님.)

print (math.remainder(17, 9)) # -1.0  (주이: 8.0 아님.)

print (math.remainder(18, 9)) # 0.0

 


cf.

print (10%9) # 1

print (11%9) # 2

print (12%9) # 3

print (13%9) # 4

print (14%9) # 5

print (15%9) # 6

print (16%9) # 7

print (17%9) # 8

print (18%9) # 0

 

 

math.remainder() 정의

 

x/y의 나머지 값을 float 자료형으로 반환.

단, 나머지가 제수 y의 절반 이상일 경우, 피제수 x를 y로 딱 나눠지는 한 단계 높은 수로 변경해 나눈 후 피제수 x를 만드는 음수 나머지 값을 반환. (★ 즉, 절대적으로 나머지를 덜 남기는 쪽 이용.) 

위 예제 경우,

14부터는 나머지가 5 이상인데 이는 9의 절반을 넘은 수치임.

따라서, 이 경우엔 9로 딱 나눠지는 18에서 음수 나머지 반영.

 

※ Python 3.7

 


cf.

% 연산자 : int 자료형끼리 경우, int 자료형으로 나머지 반환.

 

 

math.remainder() 구문

 

math.remainder(x, y)

 


[매개변수]

 

x

필수. 분자. (= 나눠지는 수)

 

y

필수. 분모. (= 나누는 수)

 

 

math.remainder() 예제 

 

import math

print (math.remainder(5.4, 3)) # -0.5999999999999996

print (math.remainder(5, 4.3)) # 0.7000000000000002

print (math.remainder(5.4, 3.2)) # -1.0

print (math.remainder(4, 2)) # 0.0

 

 



분류 제목
module Python - cmath.acosh(x) 메서드 -
module Python - cmath.asin(x) 메서드 -
module Python - cmath.asinh(x) 메서드 -
module Python - cmath.atan(x) 메서드 -
module Python - cmath.atanh(x) 메서드 -
module Python - cmath.cos(x) 메서드 -
module Python - cmath.cosh(x) 메서드 -
module Python - cmath.exp(x) 메서드 -
module Python - cmath.isclose() 메서드 -
module Python - cmath.isfinite(x) 메서드 -
module Python - cmath.isinf(x) 메서드 -
module Python - cmath.isnan(x) 메서드 -
module Python - cmath.log() 메서드 -
module Python - cmath.log10() 메서드 -
module Python - cmath.phase() 메서드 -
module Python - cmath.polar() 메서드 -
module Python - cmath.rect() 메서드 -
module Python - cmath.sin(x) 메서드 -
module Python - cmath.sinh(x) 메서드 -
module Python - cmath.sqrt(x) 메서드 -
6/7
목록
찾아주셔서 감사합니다. Since 2012