Python cos () Funktion
Beschreibung
cos () Gibt den Kosinus von x Radiant.
Grammatik
Das Folgende ist die Syntax cos () Methode:
import math math.cos(x)
Hinweis: cos () nicht direkt zugänglich ist , müssen Sie Mathematikmodul zu importieren, und dann die Methode durch statische Objekte Mathematik nennen.
Parameter
- x - ein Wert.
Rückgabewert
Gibt den Kosinus von x Radiant zwischen -1 bis 1.
Beispiele
Nachfolgend ein Beispiel für die Verwendung von cos () Methode:
#!/usr/bin/python import math print "cos(3) : ", math.cos(3) print "cos(-3) : ", math.cos(-3) print "cos(0) : ", math.cos(0) print "cos(math.pi) : ", math.cos(math.pi) print "cos(2*math.pi) : ", math.cos(2*math.pi)
Nach dem obigen Beispiel Ausgang läuft:
cos(3) : -0.9899924966 cos(-3) : -0.9899924966 cos(0) : 1.0 cos(math.pi) : -1.0 cos(2*math.pi) : 1.0