Tom Ritchford
Mar 14, 2023

--

Even easier, you can just call it as a method on any float you have:

f = 0.5
print(f.as_integer_ratio()) # (1, 2)

Note that this:

0.5.as_integer_ratio()

won't work (because integer literals in code aren't objects until they are assigned to a variable)

I had no idea this method existed, though, expect claps!

--

--

No responses yet