多个 可以 from math import sin,cos,tan
或者
import math
然后使用是
math.sin math.cos math.tan
import math
a = math.sin(1)
b = math.cos(3.1415)
c = math.tan(0)
print(a)
print(b)
print(c)
题目的意思是这样?
def integral(func, a, b, n):
ns = range(1, n+1)
res = [(b-a)/n * func(a + (b-a)/n * (i-0.5)) for i in ns]
return sum(res)
导入math模块就行
从题主的意思,若想导入三角函数,直接采用import math即可,此时想要调用sin,cos,tant相应的做如下改变即可:
# 导入三角函数
import math
x=3*math.pi
f=math.sin(x) #若想f表示为cosx只需要将sin换成cos即可,这样就可以不用将所有的三角函数导入,只需要导入math即可
print(f)
math模块导入进行了,import math,里面sin,cos,tan,asin,acos,atan等等,齐全的,另外还有幂函数、双曲函数,数论函数等等,足够你用了