divmod() Quotient and remainder

Last updated: 2026-09-22

divmod() Quotient and remainder

divmod(a, b) returns (a // b, a % b); works for floats too.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

divmod(a, b)

⚙️ Parameters

a RequiredThe dividend (numeric).
b RequiredThe divisor (numeric, non-zero).

Returns:tuple. The pair (a // b, a % b).

💥 Raises

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

(3, 2)
(3.0, 2.5)
More case studies coming soon — check back later.

❓ FAQ

QWhat is divmod(a, b) equivalent to?
AIt is equivalent to (a // b, a % b) — one call gives you both quotient and remainder, and they are meant to be used together.
QWhy does divmod(17, 5) return (3, 2)?
ABecause 17 // 5 = 3 and 17 % 5 = 2, and they satisfy the identity 17 == 3 * 5 + 2.
QWhat happens when the divisor is 0?
AIt raises a ZeroDivisionError, the same as computing 17 // 0 directly.
QHow is the sign of the remainder determined with negative numbers?
AIt follows Python's % rule: the remainder takes the sign of the divisor, e.g. divmod(-17, 5) returns (-4, 3).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏