如何用python表示三角函数

Python011

如何用python表示三角函数,第1张

Python编码下面的三角函数包括以下种类:acos(x)//返回x的反余弦弧度值。asin(x)//返回x的反正弦弧度值。atan(x)//返回x的反正切弧度值。atan2(y,x)//返回给定的X及Y坐标值的反正切值。cos(x)//返回x的弧度的余弦值。hypot(x,y

描述

sin()返回的x弧度的正弦值。

语法

以下是sin()方法的语法:

importmath

math.sin(x)

注意:sin()是不能直接访问的,需要导入math模块,然后通过math静态对象调用该方法。

参数

x--一个数值。

返回值

返回的x弧度的正弦值,数值在-1到1之间。

实例

以下展示了使用sin()方法的实例:

#!/usr/bin/python

import math

print "sin(3) : ", math.sin(3)

print "sin(-3) : ", math.sin(-3)

print "sin(0) : ", math.sin(0)

print "sin(math.pi) : ", math.sin(math.pi)

print "sin(math.pi/2) : ", math.sin(math.pi/2)

以上实例运行后输出结果为:

sin(3) : 0.14112000806

sin(-3) : -0.14112000806

sin(0) : 0.0

sin(math.pi) : 1.22460635382e-16

sin(math.pi/2) : 1

总结

以上就是本文关于Python入门之三角函数sin()函数实例详解的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:python正则表达式re之compile函数解析、Python中enumerate函数代码解析、简单了解Python中的几种函数等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!

具体代码如下:

>>>from math import pi

>>>r = float(input("请输入圆的半径:"))  #设置键盘输入

请输入圆的半径:2

>>>l = round(pi*r, 2)  #计算半圆弧长,保留两位小数

>>>print("L=%s"%str(l), end='')   # 无空行输出

L=6.28

>>>