[Python] divmod()
2021. 1. 14. 16:36ㆍProgramming Language/Python
divmod()
## 같은 의미 divmod(a, b) (a // b, a % b)
몫과 나머지를 tuple(튜플) 로 return한다.
# 둘 다 양수 print(divmod(10, 3), '\n') # 음수가 있을 경우 print(divmod(10, -3)) print(divmod(-10, 3)) print(divmod(-10, -3), '\n') # 둘중 하나 실수 print(divmod(10.6, 3)) """ <결과> (3, 1) (-4, -2) (-4, 2) (3, -1) (3.0, 1.5999999999999996) """
반응형
'Programming Language > Python' 카테고리의 다른 글
[Python] heapq 모듈 (0) | 2021.01.19 |
---|---|
[Python] Call by.. What? (0) | 2021.01.15 |
[Python] sys.maxsize - 최대 정수값 (0) | 2021.01.11 |
[Python] if not x (0) | 2021.01.08 |
[Python] 인덱싱, 슬라이싱 (0) | 2021.01.07 |