Python3 Fonction tan()

Python3 数字Nombres en Python3


Description

tan()La fonction estmathune fonction du module, utilisée pour calculer la tangente d'un angle.

Pour utiliser la fonction tan(), vous devez d'abord importer le module math, puis appelermath.tan()la fonction, en passant un angle (en radians) comme paramètre.

Syntaxe

Voici la syntaxe de la méthode tan() :

import math

math.tan(x)

Remarque :tan() n'est pas accessible directement ; vous devez importer le module math, puis appeler la méthode via l'objet statique math.


Parameters

  • x -- Une valeur numérique, un angle.

Valeur de retour

Renvoie la tangente de x radians, le résultat étant compris entre -math.pi/2 et math.pi/2.


Exemple

L'exemple suivant montre comment utiliser la méthode tan() :

Exemple (Python 3.0+)

#!/usr/bin/python3 import math print ("(tan(3) : ", math.tan(3)) print ("tan(-3) : ", math.tan(-3)) print ("tan(0) : ", math.tan(0)) print ("tan(math.pi) : ", math.tan(math.pi)) print ("tan(math.pi/2) : ", math.tan(math.pi/2)) print ("tan(math.pi/4) : ", math.tan(math.pi/4))

La sortie après avoir exécuté l'exemple ci-dessus est :

(tan(3) :  -0.1425465430742778
tan(-3) :  0.1425465430742778
tan(0) :  0.0
tan(math.pi) :  -1.2246467991473532e-16
tan(math.pi/2) :  1.633123935319537e+16
tan(math.pi/4) :  0.9999999999999999

Python3 数字Nombres en Python3

Autres extensions