# how to cnovert a decimal to fraction python

```>>> from fractions import Fraction
>>> Fraction(0.25)
Fraction(1, 4)```

Here is what the above code is Doing:
1. We’re importing the Fraction class from the fractions module.
2. We’re creating a Fraction object with a value of 0.25.
3. We’re printing the Fraction object.

The output of the code is:

Fraction(1, 4)

As you can see, the Fraction object has a value of 1/4.

You can also create a Fraction object by passing two arguments to the Fraction constructor. The first argument is the numerator and the second argument is the denominator. For example:

>>> from fractions import Fraction
>>> Fraction(3, 4)
Fraction(3, 4)

The output of the code is:

Fraction(3, 4)

As you can see, the Fraction object has a value of 3/4.

You can also specify a float value as the numerator and an int value as the denominator. For example:

>>> from fractions import Fraction
>>> Fraction(0.5, 4)
Fraction(1, 8)

The output of the code is:

Fraction(1, 8)

As you can see, the Fraction object has a value of 1/8.

You can also specify an int value as the numerator and a float value as the denominator. For example:

>>> from fractions import Fraction
>>> Fraction(4, 0.5)
Fraction(8, 1)

The output of the code is:

Fraction(8, 1)

As you can see, the Fraction object has a value of 8.

You can also specify a string value as the numerator and an int value as the denominator. For example:

>>> from fractions import Fraction
>>> Fraction(‘3/4’)
Fraction(3, 4)

The output of the code is:

Fraction(3, 4)

As you can see, the Fraction object has a value of 3/4.

You can also specify a string value as the numerator and a string value as the denominator. For example:

>>> from fractions import Fraction
>>> Fraction(‘3/4’)
Fraction(3, 4)

The output of the code is:

Fraction(3, 4)

As you can see, the Fraction object has a value of 3/4.