Mòduls estàndards: mòduls matemàtics¶
Mòdul math¶
El mòdul math ens proporciona varies funcions i operacions matemàtiques.
>>> import math
>>> math.factorial(5)
120
>>> math.pow(2,3)
8.0
>>> math.sqrt(7)
2.6457513110645907
>>> math.cos(1)
0.5403023058681398
>>> math.pi
3.141592653589793
>>> math.log(10)
2.302585092994046
Mòdul fraccions¶
El mòdul fractions ens permet treballar amb fraccions.
>>> from fractions import Fraction
>>> a=Fraction(2,3)
>>> b=Fraction(1.5)
>>> b
Fraction(3, 2)
>>> c=a+b
>>> c
Fraction(13, 6)
Mòdul statistics¶
El mòdul statistics ens proporciona funcions per fer operacions estadístiques.
Módulo random¶
El mòdul random ens permet generar dades pseudo-aleatoris.