Reputation: 90
(Python 3.8)
Is there a way how to store for example whole result of 1/3 into a variable?
foo = 1/3
and then foo will contain a periodic number (0.333333333333333333...)
Upvotes: 3
Views: 838
Reputation: 2914
Support for rational numbers is contained in the fractions
module.
>>> from fractions import Fraction
>>> Fraction(1, 3)
Unless there is a specific reason for this I would strongly advice you to stick with floating points as they are magnitudes faster than any software implementation.
Upvotes: 3