6. Fraction Module for Rational Numbers

The fractions module provides support for rational number arithmetic.

from fractions import Fraction

a = Fraction(1, 3)

b = Fraction(2, 3)

c = a + b

print(c)

#clcoding.com

1

5. Decimal Module for Precise Calculations

For financial and other applications requiring precise decimal representation, the decimal module is very useful.

from decimal import Decimal, getcontext

getcontext().prec = 6

a = Decimal('0.1')

b = Decimal('0.2')

c = a + b

print(c)

#clcoding.com

0.3

## 0 Comments:

## Post a Comment