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

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

1299  
목차
  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 - math.log1p() 메서드 -
module Python - math.log2() 메서드 -
module Python - math.perm() 메서드 -
module Python - math.pow() 메서드 ★ - 승수값 (= 누승값 = pow메서드 = 포오 = 파워)
module Python - math.prod() 메서드 -
module Python - math.radians() 메서드 -
module Python - math.remainder() 메서드 ★ - 나머지 반환. (= remainder메서드 = …
module Python - math.sin() 메서드 -
module Python - math.sinh() 메서드 -
module Python - math.sqrt() 메서드 -
module Python - math.tan() 메서드 -
module Python - math.tanh() 메서드 -
module Python - math.trunc() 메서드 ★ - 정수 부분 반환. (= trunc메서드 = 트렁크)
module Python - math.e 상수 - 오일러 상수 (2.71...)
module Python - math.inf 상수 - float 자료형의 무한대 상수 (= inf) 반환.
module Python - math.nan 상수 - float 자료형의 NaN 상수 (= nan) 반환.
module Python - math.pi 상수 - 원주율 (= 3.14...) 반환. (= 파이 상수)
module Python - math.tau 상수 - 원주율 2배 (= 6.28...) 반환. (= 타우 상수)
module Python - cmath 모듈 메서드・상수 종류 (※ 복소수 모듈)
module Python - cmath.acos(x) 메서드 -
5/7
목록
찾아주셔서 감사합니다. Since 2012