The standard module of Python

This article is used to record standard modules in Python and update at any time.

decimalModule (solving fractional circulation problem):

>>> import decimal

>>> a = decimal.Decimal(‘10.0’)

>>> b = decimal.Decimal(‘3’)

>>> a / b

Decimal(‘3.333333333333333333333333333’)


 

fractionsModule (solving fractional presentation problem):

>>> from fractions import Fraction

>>> Fraction(10, 3)

Fraction(10, 3)

>>> Fraction(10, 4)

Fraction(5, 2)

>>> Fraction(6, 2)

Fraction(3, 1)

 

Leave a Reply

Your email address will not be published. Required fields are marked *