xzy54
xzy54

Reputation: 90

Is there a way how to store periodic number into a variable

(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

Answers (1)

Sebastian Hoffmann
Sebastian Hoffmann

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

Related Questions