Mis a jour le 2025-04-14, 12:10

fonctions mathématiques (module math)

faire import math
Fonctions mathématiques :
  • math.floor(-7.6) partie entière, donne ici -8.0.
  • int(math.floor(4.5)) pour avoir l'entier 4.
  • math.ceil(-7.6) entier immédiatement supérieur, donne ici -7.
  • math.exp(2) : exponentielle.
  • math.log(2) : logarithme en base naturelle.
  • math.log10(2) : logarithme en base 10.
  • math.log(8, 2) : log de 8 en base 2.
  • math.sqrt : racine carrée.
  • math.pow(4, 5) : 4 puissance 5.
  • math.fmod(4.7, 1.5) : modulo, ici 0.2. Préférer cette fonction à % pour les flottants.
  • math.factorial(4) : factorielle 4, donc 24 (uniquement pour les entiers positifs).
  • math.fsum(l) : fait la somme des éléments d'une liste, à préférer à sum car moins d'erreurs d'arrondis (comparer math.fsum([0.01 for i in range(100)]) et sum([0.01 for i in range(100)]))
  • math.isinf(x) : teste si x est infini (inf) et renvoie True si c'est le cas.
  • math.isnan(x) : teste si x est nan (Not a Number) et renvoie True si c'est le cas.
  • math.gamma : la fonction gamma (pour n entier, gamma(n) = factorielle(n-1))
  • math.erf : la fonction d'erreur (intégrale d'une gaussienne).
  • math.comb(10, 3) : coefficient binomial.
Fonctions trigonométriques :
  • fonctions trigonométriques : math.sin, math.cos, math.tan, math.asin, math.acos, math.atan (l'argument est en radians).
  • fonctions hyperboliques : math.sinh, math.cosh, math.tanh, math.asinh, math.acosh, math.tanh
  • math.degrees(x) : convertit de radians en degrés (math.radians(x) pour l'inverse).
  • math.pi, math.e : les constantes.

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert