int.as_integer_ratio() As integer ratio
Last updated: 2026-09-22
int.as_integer_ratio() As integer ratio
int.as_integer_ratio() returns the pair (self, 1).
| Category | Number Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
int.as_integer_ratio()
Returns:tuple. The pair (self, 1), the ratio of the integer to 1.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
(5, 1)
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does as_integer_ratio() return?
AA (self, 1) tuple; for example (5).as_integer_ratio() returns (5, 1), representing 5/1.
QWhat is it useful for?
AUnifying the interface with float.as_integer_ratio(), making it convenient to write generic rational-number code that handles both integers and floats.
QWhat does calling it on 0 return?
A(0, 1), representing 0/1.